LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem Using Queue to Control Loop State?

Solved!
Go to solution

Hi all,

Below is an example of the producer/consumer design pattern I am trying to implement... Essentially, I want to display continuous data in a chart, and when a button is pressed, start/stop saving that data to file...

 

I have the DAQ in one loop ("DAQ Loops") and the data to be saved in another loop ("Save Loop") using a queue to pass the data between loops...

 

I am trying to be as efficient as possible with my programming... I don't want data that won't be saved sent to the queue... I also don't want to be continuously polling a save button in the "Save Loop"... Because the "Save Loop" stops whenever the queue is empty, I was hoping I could use the queue status (empty or not?) to control the transition between states in the "Save" loop... I also don't want the "Save Loop" to be spinning doing nothing while the queue is empty by setting the queue timeout to 0 ms. .. However, this is proving difficult...

 

**EDIT: I have updated the attached vi... It seems to work now BUT when the queue runs in the "Save Loop", the initialise, write, close states transition multiple times before staying in the write state.. When the queue stops, the states transition correctly... It seems that the data in the save queue actually starts, stops, and starts again each time the save is button pressed.

 

Also, note that the save button is located in an event structure in a separate loop in my actual vi... So I don't want another event structure in the "Save Loop" if possible...

 

Any suggestions? Thank you.      

0 Kudos
Message 1 of 5
(179 Views)
Solution
Accepted by topic author jcannon

Replaced with the TDMS logging loop I always use.

-------------------------------------------------------
Control Lead | Intelline Inc
0 Kudos
Message 2 of 5
(158 Views)

Thank you, thank you, thank you!!

 

This was doing my head in...

 

Just in terms of my understanding, your tdms logger uses the refnum status in the first iteration to determine the initial state of the logging state machine? 

0 Kudos
Message 3 of 5
(142 Views)

I haven't looked at the supplied solution, but i'd set the write loop to a 1 sec timeout on the Dequeue, and if Timeout, close the file.

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 5
(115 Views)

Basically I used the timeout from Dequeue Element to determine if there is any incoming data.

if timeout == true     # no incoming data, cleanup
    if not_a_refnumm == false
         tdms.close
    print("Not logging...")
else                   # incoming data
    if not_a_refnum == true
         tdms.open
         print("Data logged...")
    tdms.write
    
-------------------------------------------------------
Control Lead | Intelline Inc
0 Kudos
Message 5 of 5
(90 Views)