This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Access flash images when using Lightcrafter 4500 EVM in Matlab

Other Parts Discussed in Thread: DLPC350

Hello,

i am trying to control the Lightcrafter 4500 with Matlab by using mex-files compiled based on the released API. I have started using the gitHub code (https://github.com/Stage-VSS/matlab-lcr

  • Michael,

    Are you encountering any issues with this code? If so, you may need to contact the developer for further assistance. Let me know how I can be of assistance.

    Best Regards,
    Philippe Dollo
  • Hi Philippe,

    thank you for your answer. I think my thread was cut off somehow.

    What i want to do is project 16 patterns (8bit) via pattern sequence mode loaded from flash memory. Everything should be controlled in Matlab with mex-files build from the API of the GUI.

    With help of the mentioned github code above i am able to perform basic tasks with the device (connect, set LED Currents, exposure times, display modes, etc.). This works well in Matlab.

    My problem now is that with 16 different 8bit patterns, i need to call the other flash indexes in order to project the patterns. For example, i use the function "addToLutPat" to set up a pattern LUT and with buffer swap i can project the 6 patterns of the first two flash images which i assume are already loaded in the buffer. If i want to project pattern 7 to 16 i need to set up an image LUT with the desired flash images.

    Referring to the official programmers guide i can accomplish this with calling the mailbox functions or from the API the function sendImageLut (or sendSplashLut). I can compile those functions to mex-files but as soon as i execute it is not possible to open the mailbox for example. Other functions like CloseMailbox, setMailboxAddr, sendMsg, prepWrite cannot be called either. Could the reason be that those functions are private? They do not appear in the released API.h file. 

    To call the sendImageLut function my code is like:

    unsigned char lutEntries[64];  //array for max number of flash images

    (for ind=0, ind<6,ind++)      //16 patterns are contained in 6 flash images

    {lutEntries[ind]=ind;}

    sendImageLut(&lutEntries[0], 6)

    Since all other functions can be executed as mex-files without problems, i cannot understand why this is not working. Any help on this is much appreciated.

    Best regards,

    Michael

  • Hey Michael, I ran into the same problem. I added a mex file to support switching between 2 images (in principle you can add more).  I saved the file below as lcrSendImageLut_2images.cpp and then made a mex file using make.m in the main directory of the git files. First add all your patterns to the lut with lcrAddToPatLut.  Then, add the image lut with with lcrSendImageLut_2images(imageIndices(1),imageIndices(2),numberImages). You should have as many image indices for the number of "true" buffer swaps in the addtopatlut commands.

    Liz 

    #include "lcr.h"
    #include "mex.h"
    void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
    {
    if (nrhs < 3 || nrhs > 3)
    {
    mexErrMsgIdAndTxt("lcr:usage", "Usage: lcrSendImageLut(lutEntry0,lutEntry1,numEntries)");
    return;
    }
    unsigned char lutEntry0 = mxGetScalar(prhs[0]);
    printf("lutentry0 %u\n",lutEntry0);
    unsigned char lutEntry1 = mxGetScalar(prhs[1]);
    printf("lutentry1 %u\n",lutEntry1);

    unsigned int numEntries = mxGetScalar(prhs[2]);
    unsigned char tmpArray[] = {lutEntry0,lutEntry1};

    int result = DLPC350_SendImageLut(tmpArray, numEntries);
    if (result < 0)
    {
    mexErrMsgIdAndTxt("lcr:failedToSendimagelut", "Failed to send image lut");
    return;
    }
    }

  • Hi Liz,

    thank you for your help. I included your code and built a mex-file lcrSendImageLut_2images as you suggested. Unfortunately i still get the same error when calling this function in Matlab like lcrSendImageLut_2images(0,1,2).

    In the command window in Matlab i get:

    lutentries 0 0

    lutentries 1 1

    Error - Failed to send images

    I have a feeling that the problem is not the code itself but maybe the mex-file because no matter what i input in sendImageLut, it always fails to send. You mentioned that you are using the make.m file to build the mex function. I did it manually like "mex lcrSendImageLut_2images.cpp lcr.lib DLPC350_api.cpp DLPC350_usb.cpp" and the mex-file was built successfully. But maybe that is the problem. When i run make.m i always get reference errors to the according api functions DLPC350...xyz. Have you had similar issues? Since you got it to work there must be something i am missing here. Thank you for your support Liz.

    Here is the code i am using in Matlab:


                % Set up pattern parameters
                bitDepth=8;
                numPatterns=6;
                numEntries=numPatterns/(24/bitDepth);
                exposurePeriod=133333;

                % Connect to device
                lcrOpen();
               
                % Set display mode
                lcrSetMode(true); %pattern mode           

                % Stop the current pattern sequence
                lcrPatternDisplay(0);

                % Clear locally stored pattern LUT.
                lcrClearPatLut();
                 
                % Set up pattern LUT
                lcrAddToPatLut(0, 0, 8, 7, false, false, true, false);
                lcrAddToPatLut(0, 1, 8, 7, false, false, false, false);
                lcrAddToPatLut(0, 2, 8, 7, false, false, false, false);

                lcrAddToPatLut(0, 0, 8, 7, false, false, true, false);
                lcrAddToPatLut(0, 1, 8, 7, false, false, false, false);
                lcrAddToPatLut(0, 2, 8, 7, false, false, false, false);  
              
                % Set pattern display data source
                lcrSetPatternDisplayMode(false); %flash memory

                % Set the sequence parameters.
                lcrSetPatternConfig(numPatterns, false, numPatterns, numEntries);

                % Set exposure time
                lcrSetExposureFramePeriod(exposurePeriod, exposurePeriod);

                % Set the pattern sequence to trigger.
                lcrSetPatternTriggerMode(true);   

                % Send pattern LUT to device.
                lcrSendPatLut();
               
                % Send image LUT to device
                lcrSendImageLut_2images(0,1,numEntries);   %Flash image 0,1

                % Validate the pattern LUT.
                status = lcrValidatePatLutData();
                if status == 1 || status == 3
                    error('Error validating pattern sequence');
                end

                % Start the pattern sequence.
                lcrPatternDisplay(2);

  • Hey Liz,

    have you modified the make.m file of github in any way? Like with additional links LDFLAG or similar? Because i still get reference errors.

    Is it possible that you send me your lcrSendImageLut_2Images mex file so i can test if its an compiling issue or not? This would be very helpful.

    Best regards,

    Michael

  • Problem solved. Just use Visual Studio 2012 as compiler instead fo MinGW and everything works fine
  • Michael,

    Thanks for your input. I will tentatively close this thread as such.

    Best Regards,
    Philippe Dollo