04-23-2024 09:57 PM - edited 04-23-2024 10:50 PM
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.
Solved! Go to Solution.
04-23-2024 10:42 PM
Replaced with the TDMS logging loop I always use.
04-23-2024 11:08 PM
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?
04-24-2024 02:52 AM
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.
04-24-2024 07:15 AM
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