Streaming from U3 channel error | LabJack
 

Streaming from U3 channel error

2 posts / 0 new
Last post
concacid
concacid's picture
Streaming from U3 channel error

Hi,

I wrote this subfunction to stream from my U3 when called. I want to stream for a certain number. e.g looptime=3 means I'll stream and store the data from 3 different cycle. If my numscan is 2000, I want to store the value in a array capable of taking them. My code here is supposed to do that but I keep getting an error.

CODE

function [time,allvalue]=LJ_Stream_func(loopAmount,delay,numScans,takedata,scanRate,dblCommBacklog, dummyDoubleArray, AqTime)

ljasm = NET.addAssembly('LJUDDotNet'); %Make the UD .NET assembly visible in MATLAB

ljudObj = LabJack.LabJackUD.LJUD;

[ljerror, ljhandle] = ljudObj.OpenLabJack(LabJack.LabJackUD.DEVICE.U3, LabJack.LabJackUD.CONNECTION.USB, '0', true, 0);    

%Start the stream.

    [ljerror, dblValue] = ljudObj.eGet(ljhandle, LabJack.LabJackUD.IO.START_STREAM, 0, 0, 0);

     %Init array to store all data in acquisition loop

        allvalue_final= [];

        time_final=[];

        

    %Read data

    for i=1:loopAmount

        %Loop will run the number of times specified by loopAmount variable

        %then read however much data is available.

        %Thus this delay will control how fast the program loops and how

        %much data is read each loop. 

        pause(delay);

        %Init array to store data

        adblData = NET.createArray('System.Double', AqTime*1*numScans);  %Max buffer size (#channels*numScansRequested)

       

        %Read the data.  Array we pass must be sized to hold enough SAMPLES, and

        %the Value we pass specifies the number of SCANS to read.

        numScansRequested = numScans;

        [ljerror, numScansRequested] = ljudObj.eGetPtr(ljhandle, LabJack.LabJackUD.IO.GET_STREAM_DATA, LabJack.LabJackUD.CHANNEL.ALL_CHANNELS, numScansRequested, adblData);

        

        

        %Each data as sort in this order (Chan1,Chan2,Chan3,Chan4,Chan1,Chan2....)

        %Sort the data in columns

           for ii=1 : (numScans)

 

                  takedata = takedata +1 ; 

                  allvalue_initial(ii)=adblData(ii);

                  allvalue_final= [allvalue_final,allvalue_initial(ii)];

                  time_initial(ii)=(takedata/scanRate);

                  time_final=[time_final, time_initial];

 

           end

        

        [ljerror, dblCommBacklog] = ljudObj.eGet(ljhandle, LabJack.LabJackUD.IO.GET_CONFIG, LabJack.LabJackUD.CHANNEL.STREAM_BACKLOG_COMM, dblCommBacklog, dummyDoubleArray);

                       

                                 

    end

    

    %Stop the stream

    ljudObj.eGet(ljhandle, LabJack.LabJackUD.IO.STOP_STREAM, 0, 0, 0);

    

    %Pass the value of the function to matlab for treatment

        

         assignin('base','allvalue',allvalue_final);  

         assignin('base','time',time_final);

      

    disp('Streaming has stopped. Data collected succesfully. ')

    

endCODE:

ERROR:

xceptionObject: [1x1 LabJack.LabJackUD.LabJackUDException]

         identifier: 'MATLAB:NET:CLRException:MethodInvoke'

            message: 'Message: Error in the application.…'

              cause: {}

              stack: [5x1 struct]

This error freezes my computer sometimes. What could be the problem? Please help.

Thank you.

LabJack Support
labjack support's picture
Unless there is some missing

Unless there is some missing code, you are not configuring stream mode before starting it so the error is expected. It looks like you are using MATLAB, so please refer to the stream example in the MATLAB examples:

https://labjack.com/support/software/examples/ud/matlab

The examples show how to catch and display exceptions from our .NET interface using showErrorMessage.m. That will give a better indication on what the error is.

General streaming using the UD driver documentation can be found here:

https://labjack.com/support/datasheets/u3/high-level-driver/example-pseu...

Note that constants such as LJ_ioCLEAR_STREAM_CHANNELS and LJ_chSTREAM_SCAN_FREQUENCY in UD driver/documentation are LabJack.LabJackUD.IO.CLEAR_STREAM_CHANNELS and LabJack.LabJackUD.CHANNEL. STREAM_SCAN_FREQUENCY when using .NET and MATLAB.

Let us know if that doesn't help. I wouldn't expect the UD driver to cause a computer to freeze, so that may be a MATLAB issue or possibly a MATLAB when using the UD driver issue under certain circumstances.