« Close

Datasheets and User Guides

App Notes

Software & Driver

 

4.9 - AIStreamRead

Waits for a specified number of scans to be available and reads them. AIStreamStart should be called before this function and AIStreamClear should be called when finished with the stream. Note that while streaming the LabJack U12 is too busy to do anything else. If any function besides AIStreamRead is called while a stream is in progress, the stream will be stopped.

Note that you must pass the actual local ID to this function, not the idnum parameter used for most functions. Usually you simply pass the value returned by the idnum parameter in AIStreamStart.

Declaration:

long AIStreamRead (    long localID,
                       long numScans,
                       long timeout,
                       float (*voltages)[4],
                       long *stateIOout,
                       long *reserved,
                       long *ljScanBacklog,
                       long *overVoltage )

Parameter Description:
Returns: LabJack errorcodes or 0 for no error.
Inputs:

  • localID – Send the local ID from AIStreamStart.
  • numScans – Function will wait until this number of scans is available. Minimum is 1. Maximum numSamples is 4096, where numSamples is numScans * numChannels. Internally this function gets data from the LabJack in blocks of 64 samples, so it is recommended that numSamples be at least 64.
  • timeout – Function timeout value in seconds. 1 is usually a good value.
  • *voltages – Pointer to a 4096 by 4 array where voltage readings are returned. Send filled with zeros.
  • *stateIOout – Pointer to a 4096 element array where IO states are returned. Send filled with zeros.

Outputs:

  • *voltages – Pointer to a 4096 by 4 array where voltage readings are returned. Unused locations are filled with 9999.0.
  • *stateIOout – Pointer to a 4096 element array where IO states are returned. Unused locations are filled with 9999.0.
  • *reserved – Reserved for future use. Send a pointer to a 0.
  • *ljScanBacklog – Returns the scan backlog of the LabJack RAM buffer. This is the number of scans remaining in the U12 buffer after this read. If this value is growing from read to read, data is not being read fast enough and the buffer will eventually overflow. In normal operation this will return 0 almost all the time. The size of the buffer in terms of scans is 4096/numChannels.
  • *overVoltage – If >0, an overvoltage has been detected on at least one sample of one of the selected analog inputs.

ActiveX Function Differences:
The “voltages” and “stateIOout” arrays are represented as strings. Floating point data is returned as 13 characters per number (XXXX.XXXXXXXX) and integers are returned as 10 characters per number (XXXXXXXXXX). Zeros are used for padding where necessary. . The total number of bytes in the “voltages” string is 13*numSamples. The total number of bytes in the “stateIOout” string is 10*numScans. Note that to avoid a memory leak, these strings should be emptied (set to “”) after each call to AIStreamReadX.

Declaration (ActiveX):

long AIStreamReadX (    long localID,
                        long numScans,
                        long timeout,
                        BSTR FAR* voltages,
                        BSTR FAR* stateIOout,
                        long FAR* ljScanBacklog,
                        long FAR* overVoltage)

6 comments

Can you send a example for AIStream for U12?

There are some stream examples on the U12 Windows Examples page.

Why i get error (number 8) when i call AIStreamRead function after first calling?

The list of error codes can be found here:

http://labjack.com/support/u12/users-guide/4.40

Error code 8 indicates "Invalid array size or value". Before calling AIStreamRead make sure your voltages and stateIOout arrays are the correct size and all values are set to zero.

I suspect that you are calling AIStreamRead in a loop and not initializing the array values to zero in the loop before the call. Note that after calling AIStreamRead the voltages and stateIOout arrays will contain non-zero values, so if you are reusing the arrays in a loop you need to reinitialize the array values to all zeroes for your next AIStreamRead call. 

Why am I sometimes getting values of 199980 returned after calling streamread? These values are definitely incorrect.

Are you setting readCount=TRUE in AIStreamStart?  Otherwise, can't think of a reason to get back a large integer.  Do you see the same thing running LJstream.exe?  What language are you using ... does an unmodified example do this?