LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Queued State Machine for Starting and Stopping a Continuous DAQmx Task

Solved!
Go to solution

Hi all, I have been away from using LabVIEW for a few years and now getting my head back into it... I am a little stuck on this problem and could use some help...

 

Currently, I am updating the design of some old vis of mine that perform continuous AI measurements using the DAQ Assistant and an "enable" front panel button to start/stop data acquisition as needed ... I would like to change these to a state machine using DAQmx controls and an event structure to monitor for changes in the "Start/Stop Acquisition" front panel button...

 

Essentially, I just want to be able to manually start and stop DAQ task as needed with a front panel button without stopping the entire vi...

 

I have examined all the NI examples, Google, and YouTube tutorials without success... I have attached what I have done so far (LV 2014SP1)...

 

Any help would be greatly appreciated...

 

Thanks,

Jack

0 Kudos
Message 1 of 8
(733 Views)

Hi Jack,

 

you need to fiddle with the conditions of your statemachine to make it work!

 

Right now there is a problem when you switch from "Acquiring" to "System Idle": you basically DON'T stop the DAQmx task! You try to go to "Stop DAQmx" state, but due to the outer case structure you go to "System Idle" state instead…

 

Recommendation: use only one case structure and implement a "DAQmx idle" state!

(Another recommendation: draw your statemachine states on a sheet of paper and sketch the conditions. This helped me a lot…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 8
(687 Views)

Daq.png

I don't have DAQ mx, so you have to connect the Daq mx blocks yourself.
The main idea behind this is to use a event structure for collecting your stop, exit and start clicks and additionaly to
set the timeout of the event structure to 0 in case you want to do consecutive daq reads until you click stop or exit.

Quiztus2_0-1713260407011.png

Quiztus2_2-1713260585198.png

 

 

 

Actor Framework
0 Kudos
Message 3 of 8
(670 Views)
Solution
Accepted by topic author jcannon

Thank you, GerdW and Quiztus2!

 

I have used your feedback to create a queued state machine... This vi will be further developed into a larger, more complex application and this QSM skeleton will work great...

 

Thanks again...

0 Kudos
Message 4 of 8
(644 Views)

it appears strange to me that you start everytime before you read. I don't expect that to be necessary.

I would tidy your program before going bigger.

What is the purpose of the 2 parallel error wires?

Do you really want to polute your queue with start commands?

 

Actor Framework
Message 5 of 8
(634 Views)

Hi Quiztus2,

 

If you start the DAQmx task but don't read, the samples are still acquired by the DAQ device, which holds them in the device buffer until they are read... This leads to a buffer error once the buffer is maxed out, causing an error, and the application stops running... So the DAQmx task must "start, read, stop" on each operation to run correcting... Only the initialised DAQmx task can remain in memory via the shifter register and not be performed on each operation...

 

What do you mean by parallel wires? Do you mean parallel while loops? By using two loops, the event structure with the front panel controls can always be accessed and send commands to change the DAQmx state... I think with your example images, when the DAQmx "read data" state is running, there is no way for a change in the "record data" button to be actioned as the event structure is located in the "system idle" state...  Please correct me if I have missed something... 

 

Thanks.

 

   

0 Kudos
Message 6 of 8
(599 Views)

regarding error wires: I mean this error wire spaghetti here:

Quiztus2_1-1713335899328.png

regarding start,read,stop: Sure, Init, Start, Read,Stop is perfect, but did you consider also: Init, Start, Read, Read, Read,Read, Stop?

 

In the code I created for you the following should happen ( I didn't test it) : Click Start -> Start Case (Start) -> Read Case (Read) -> Idle State (React to clicks, otherwise timeout) -> Timeout -> Read Case (Read) and so on.

 

Regarding parallel loops:

I didn't test your QMH, but it looks like your event loop polutes the queue with start commands when timeout is set to 0.

 

Actor Framework
0 Kudos
Message 7 of 8
(587 Views)

@jcannon wrote:

If you start the DAQmx task but don't read, the samples are still acquired by the DAQ device, which holds them in the device buffer until they are read... This leads to a buffer error once the buffer is maxed out, causing an error, and the application stops running... So the DAQmx task must "start, read, stop" on each operation to run correcting... Only the initialised DAQmx task can remain in memory via the shifter register and not be performed on each operation...


 If you want to 'back sample' i'd put the sampling in a separate loop that keeps a record (array) of fixed/limited length and pull from that when needed. It can e.g. keep the last 10 seconds worth of data and and rotate/overwrite as needed. 

This can be implemented in several ways, an array which you prune is the 1st thought, but it could also be a lossy queue.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 8 of 8
(577 Views)