Sequence to write data from one channel to another under certain conditions

Recommended Posts


I am more or less new to DAQFactory (have done some simple data acquisition, but nothing complex yet).
After reading through many threads in this forum as well as spending some time with the user's guide, I still couldn't figure out how to do the following:
I want to read two channels from a Labjack UE9 with a frequency of 1000 Hz, so I think I should use the stream mode. So far, so good - acquiring the data at 1000 Hz works fine.
Now I would like to copy the values from one of these channels to one of two new channels (for this, I have created two V channels called "T_Pre" and "T_Post"), but only if the signal from the other UE9 channel is between two specific values (variables set by scrollbars). This must work during the ongoing stream acquisition. Only the values from the V channels have to be stored; the stream data can be discarded afterwards.
Here's what I came up with (and what does not work):

using ("device.labjack")
include ("C:\Program Files (x86)\LabJack\Drivers\LabJackUD.h")
//setup stream, set scan rate
AddRequest(0, LJ_ioPUT_CONFIG, LJ_chSTREAM_SCAN_FREQUENCY, Var.scanrt, 0, 0)
//clear channel history
//setup channels to stream
AddRequest(0, LJ_ioCLEAR_STREAM_CHANNELS, 0, 0, 0, 0)
AddRequest(0, LJ_ioADD_STREAM_CHANNEL, 12, 0, 0, 0)
AddRequest(0, LJ_ioADD_STREAM_CHANNEL, 11, 0, 0, 0)

//start the stream
//set variable "scanrate" to actual scanrate
global scanrate = 0
eGet (0, LJ_ioSTART_STREAM, 0, @scanrate, 0)
 //write data to VChannels, if input UE9_11 is between certain values
if (UE9_11[0]>var.kw1min)
    if (UE9_11[0]<var.kw1max)
if (UE9_11[0]>var.kw2min)
    if (UE9_11[0]<var.kw2max)
ePut(0, LJ_ioSTOP_STREAM, 0, 0, 0)

The sequence is started by a button. Another Button changes "var.stop" to 1 if pressed, which stops the sequence as intended. The problem is probably somewhere in the "while" loop.

I'm quite sure that I made a simple beginner's mistake, so it would be very kind if anyone could point me in the right direction.

Thanks in advance!

Share this post

Link to post
Share on other sites

What you have won't work because of the way stream works.  Stream sends data in blocks, and so it is hard to process every data point as it comes in.  Also, your while() loop lacks a delay(), which will cause the CPU power to spike.  You should pretty much always have a delay() inside a while() loop.  There are exceptions, but this is a good general rule.

Now to your question, it is probably easier to just use the filter() function on the whole incoming data.  You can make a V channel that is a calculated v channel (meaning there is an Expression associated with it).  That expression would be something like:

filter(UE9_11, UE9_11 > var.kw1min)

Then whenever you reference that V channel it will perform the filter, which will remove all values that don't match the criteria.  Filter() is an internal function so is pretty darn fast.


Share this post

Link to post
Share on other sites

Thanks a lot for the quick reply!

Your tip helped; the filter works just as intended, even with combined criteria (UE9_11>var.kw1min && UE9_11<var.kw1max).

Share this post

Link to post
Share on other sites

Yup, you can do a lot with Filter() and since it is internal, it is fast and DAQFactory can do it in real time.   I like Search() too.  Its a quick way to find certain things in your data.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now