DAQFactory also supports some LabJack M functions, all start with device.LabJackM. unless you use the using("device.labjack") function call described earlier. All will throw an error if an error occurs, which you can then catch using try/catch blocks.
LJM_eReadName(ID [string], Name [string]): reads a particular input specified by the Name. ID is the ID of the device (which would include the IP for Ethernet connections). DAQFactory will automatically open the device with the given ID if it is not open already. You do not need to call any sort of open function to open the device. Name follows the standard LJM nomenclature for the LJM_eReadName() function (see the LabJack M documentation from LabJack)
LJM_eWriteName(ID [string], Name [string], Value [number]): this is almost identical to LJM_eReadName, except writes the given value to the specified named addressed. This correlates with LJM_eWriteName(), though like LJM_eReadName, DAQFactory takes care of opening the device and managing handles.
LJM_eStreamStart(ID [string], Name(s) [string or array of strings], scanRate [number], scansPerRead [number], 1) : starts a stream on the given device. Name(s) is either a string with the desired value to stream, or an array of strings containing the names of the values to stream. Note the last parameter must be 1. This is to allow for a future version of this streaming that automatically reads the data like the LabJackUD.
LJM_eStreamRead(ID [string]): returns data from a stream that is running on the specified device. The stream must be started using LJM_eStreamStart. This function returns an object. That object contains arrays of data for each name specified in LJM_eStreamStart, plus member variables for ljmScanBacklog and deviceScanBackLog. So, for example, if you were streaming AIN0:
private dataIn = device.LabJackM.LJM_eStreamRead("ANY")
dataIn.AIN0 would have an array of data (based on what the LabJack returns)
dataIn.ljmScanBacklog would have the scan backlog
dataIn.deviceScanBacklog would have the device scan backlog
LJM_eStopStream(ID [string]): stops a stream running on the specified device.
Here's some sample script for setting up and running a stream:
private scanRate = 10000
private scansPerRead = 500
device.labjackM.LJM_eStreamStart("ANY", {"AIN0", "AIN1"}, scanRate, scansPerRead, 1)
private dataIn
global backlog
while(1)
dataIn = device.labjackM.LJM_eStreamRead("ANY")
channelA.AddValue(dataIn.data.AIN0)
channelB.addValue(dataIn.data.AIN1)
backlog = dataIn.ljmscanBacklog
endwhile
There is a bit here, but only a little of it needs to be changed to stream other inputs. But first, you'll need to create channels to receive the data. In this case, they are named ChannelA and ChannelB. We recommend setting them up as standard input channels for the LabJackM (in this case, D# "ANY", I/O Type "AIN#(0:254)", Chn #'s 0 and 1. Make sure the Timing on the channels are 0 though since you can't poll and stream a channel at the same time.
Here's a line by line breakdown:
private scanRate = 10000
Sets the scanRate. We store this in a variable because we need it in several locations to calculate times.
private scansPerRead = 500
Sets the scans to acquire with each read. Please see the LJM documentation for the best choice of value for this parameter based on scan rate.
device.labjackM.LJM_eStreamStart("ANY", {"AIN0", "AIN1"}, scanRate, scansPerRead, 1)
Starts the stream on the first found device "ANY", for names "AIN0" and "AIN1".
private dataIn
global backlog
Set up some variables to receive data. "backlog" is global so you can view the backlog from a page.
while(1)
This sequence will stay running while the device is streaming to collect data and put it into the channels. While(1) means loop forever.
dataIn = device.labjackM.LJM_eStreamRead("ANY")
Read a block of data and store it in our private variable.
channelA.AddValue(dataIn.data.AIN0)
Take the result of the stream read and stuff it into channelA. Repeat for ChannelB.
backlog = dataIn.ljmscanBacklog
Save the backlog in a global variable so it can be accessed elsewhere.
endwhile
Loop around and repeat.
The sequence will remain running while streaming is running. To stop streaming, stop the sequence and call LJM_eStreamStop:
sequence.startStream.stop
device.labjackM.LJM_eStreamStop("ANY")