Please enable JavaScript to view this site.

DAQFactory User's Guide

Navigation: 17 Devices > 17.7 LabJack UE9 / U6 / U3 > 17.7.5 Analog and Digital I/O > 17.7.5.2 High Speed Acquisition - streaming

17.7.5.2.2 Basic Streaming

Scroll Prev Top Next More

When you want to read inputs at rates faster than 100hz, or at very precise intervals, it is usually best to use the LabJack's stream mode instead of having DAQFactory and the PC set the read rates.  Anything above 100hz is difficult for a PC to perform since it has so many other tasks to do as well.  To setup streaming in DAQFactory you will need to use a combination of Channels and sequence script.  Streaming in DAQFactory is different from how the LabJack User Manual describes, as DAQFactory handles all the callback and data collection, putting the data into the appropriate channels.  In this sample we'll stream 2 channels.

1) Start DAQFactory up with a new document.

2) Click on CHANNELS: in the Workspace to go to the channel table.

3) Add two new channels, ChannelA and ChannelB, both Device Type = LabJack, D# = 0, I/O Type = A to D, and Channel numbers 2 and 3.  Set the Timing for both channels to 0, and the History: set to 36000.

3) Click on Apply to save your changes.

4) Right click on SEQUENCES: in the Workspace and select Add Sequence.  Call the new sequence StartStream

5) In the sequence editor window that appears, enter the following script:

 

// standard initialization:
using("device.labjack")
include("c:\program files\LabJack\Drivers\labjackud.h")
 
// setup stream:
// set scan rate:
AddRequest(0, LJ_ioPUT_CONFIG, LJ_chSTREAM_SCAN_FREQUENCY, 1000, 0, 0)
// setup channels to stream:
AddRequest(0, LJ_ioCLEAR_STREAM_CHANNELS, 0, 0, 0, 0)
AddRequest(0, LJ_ioADD_STREAM_CHANNEL, 2, 0, 0, 0)
AddRequest(0, LJ_ioADD_STREAM_CHANNEL, 3, 0, 0, 0)
GoOne(0)
 
// start the stream:
global scanrate = 0
eGet(0,LJ_ioSTART_STREAM, 0, @scanrate, 0)
// scanrate now has the actual scanrate, which you can display on the screen if you want.

6) Click on Apply to save your script.

7) Right click on SEQUENCES: in the Workspace and select Add Sequence.  Call the new sequence StopStream and enter the following script:

 

ePut(0,LJ_ioSTOP_STREAM, 0, 0, 0)

8) Click on Apply to save your script.

9) Click on Page_0 under PAGES: in the Workspace to display a blank page.

10) On that page, right click and select Graphs- 2D Graph.

11) While holding down the Ctrl key, click and drag the graph to move it to the top left corner of the page, then click and drag the bottom right corner of the graph to expand it to take up about 3/4 of the screen.

12) Right click on the graph and select Properties....  For the Y Expression put ChannelA.  Click on New Trace and for the Y Expression put ChannelB.  Click OK to close the properties window.

13) Right click somewhere on the empty part of the page and select Buttons - Button.  Right click on the new button and select Properties....

14) For LabelText, put Start, then select the OnLButtonUp (Left Click) in the list on the left.  In the right area put this script:

 

sequence.startStream.begin()

15) Repeat steps 13 and 14, but put Stop for the LabelText and sequence.StopStream.begin() for the OnLButtonUp event.

That is it.  You should be able to click on the Start button and have streaming on channels 2 and 3 start up and be graphed.  It is possible that the values will be off the scale of the graph, so you may want to click on the graph, then right click on the graph and select AutoScale - AutoScale Y.

One important point if you start tweaking this sample: the Channels that you created must have the same D# and channel number as the one you specified in the LJ_ioADD_STREAM_CHANNEL request.  The I/O Type must be "A to D" as well, even if you are streaming digital inputs, timers or counters.  If not then DAQFactory won't know where to put the data that is streaming in.  

Note: make sure you configure your inputs before starting the stream.  For the U3, this means you have to set the pins to analog input as shown in the example file.

Note: you should not change the LJ_chSTREAM_WAIT_MODE, as all waiting is handled internally.  If you change this, you will most likely cause streaming to stop functioning.