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):

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.