From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Continuous data acquisition in actor helper loop

Hi,

 

So, I'm trying to run a simple DAQ device (simulated) using a helper loop in the actor framework.  Normally, the data read method is executed in a loop, so the only way I could think to avoid a loop inside of a loop was to place this function in the timeout event of the helper loop for this actor.  This works but it causes other problems.  For instance, if I add a stop event to pause the device and close all references, there is a lengthy delay between when I initiate the stop event and when the device actually receives the stop command.  The delay is strongly dependent on the number of samples being read by the DAQmx Read.vi.  Any ideas?

 

speclabAI_0-1584047945689.png

 

0 Kudos
Message 1 of 9
(3,256 Views)

A common error with this kind of thing is to have two timing sources, the hardware device and a software loop (which you have).  Both timers are set to the same period, but one is slightly longer and falls behind the other, leading to a delay.  I suspect you have a problem like this.  

Message 2 of 9
(3,239 Views)

Any thoughts on how to solve this issue?  Thanks 

0 Kudos
Message 3 of 9
(3,208 Views)

If the "Read" message is reading the values and takes a specific time, could you have it enqueue itself?

That is, in "Read.vi", call "Send Read Msg.vi" or similar.

 

You'd need to also provide a method of handling the start/stop, but it seems you've already handled that in a way that doesn't involve the timing of the send.


GCentral
0 Kudos
Message 4 of 9
(3,189 Views)

Usually with daq one uses the hardware to define the timing.   I use the daqmx events in an event structure to trigger when I read the data.

0 Kudos
Message 5 of 9
(3,179 Views)

Thank you.  I have not tried using DAQmx events before.  If you would be willing to share any code or direct me to any specific examples that would be greatly appreciated.  The link you sent is a good starting point, but seems rather limited.

0 Kudos
Message 6 of 9
(3,169 Views)

You mentioned that your DAQ read loop takes a long time to respond- can you post that code for us to review?

 

You also mentioned it's strongly dependent on the number of samples being read.

 

Just a guess without looking at code: your DAQmx Read function will block until the number of samples to be read is available to be read. Say you want to read 5000 samples at 1 kHz; this means your Read function blocks for 5 seconds every time it's read. If you get a Stop request during this time, you have to wait the full 5 seconds no matter what, as the Stop won't process until after the Read function returns.

 

I would solve this with DAQmx events; you can register an event for "N samples available in the buffer" with N set to 5000. Then when the event fires, you can call Read, and it'll immediately return with all 5000 samples. You can also have the same event structure registered for a "Stop" user event, so if a Stop event comes in before the 5000 samples are acquired it will process the Stop immediately.

 

You can also have the function read the remaining samples when a Stop happens (even with a non-full buffer) by setting the Timeout to 0 on DAQmx Read. If you request 5000 samples with 0 timeout, and only 1000 samples are in the buffer, it'll return the 1000 samples immediately. I think you can also set the Number of Samples to Read to -1 to return the full buffer, but I can't quite remember (it's in the Help for that function, and either method will work). Note that if the function times out it'll return an error, so be sure to clear the error or your system will think the function failed.

Message 7 of 9
(3,166 Views)

Thank you.  This is very helpful.  I'm still not sure how to actually implement these events since I'm new to DAQmx, but I would like to understand how to do this more generally, using, for instance third party hardware that uses triggers for initiating some event (e.g. moving a stage, acquiring an image from a camera, etc.).  I'm attaching the section of AF code relevant for this problem.   

Download All
0 Kudos
Message 8 of 9
(3,151 Views)

Good morning sir;
                               can you share your AI  DAQ project in actor framework . 

0 Kudos
Message 9 of 9
(400 Views)