04-28-2017 04:55 PM
04-28-2017 06:16 PM
This is definitely much more complicated than it needs to be. I'm pretty sure you don't need the queue stuff, and I very much doubt that you want two separate loops.
I'm not quite sure this is going to do what you want, but I think the form is correct and this is a good starting point to build from.
Let me know if we're getting close.
04-28-2017 06:39 PM
04-29-2017 06:15 AM
Here is a more standard way:
The error case is empty. When the queue is released the Dequeue Element vi throws an error and the consumer loop is stopped. You don't need a stop local variable and you can set the stop button mechanical action to Latch When Released. This way the stop button is automatically reset when read.
Ben64
04-29-2017 10:36 AM
Ben,
Good fix, for the way the program currently stands.
In your opinion, is this a good time to be using a queue? In twenty years, I've almost never used one, and would encourage others to avoid them as much as possible. They are, of course, appropriate some times, but I'm not seeing anything here that makes me think this would be a good time to use one.
04-29-2017 04:25 PM
Let me summarize what I think you are trying to do. My understanding might be wrong, but you can fix that up.
You are doing continuous sampling at 2KHz, and are taking 100 samples at a time (and doing something useful with them). Periodically, you want to push a "Log Me" button and save the current sample set (I'm going to assume you want the current set of 100 samples) saved in a file that auto-increments each time you push the "Log Me" button. In addition, you want this to run with minimal "interference" from the on-going logging. And you don't want to use those nasty queues (I don't quite understand your aversion, but so be it).
So what is the time-critical element here? Pushing the Log Me button. At that time, you want to (a) define your file name, (b) have the data "in hand", and (c) write the file. Let's solve (b) first (without using Queues).
Do you know about VIGs (Virtual Instrument Globals, also called FGV, or Functional Global Variable)? This is a "Memory Element". I'm not going to insult your intelligence by telling you about them -- in 20 years of LabVIEW, you've surely encountered them. As your sample comes in, store it in a VIG. This takes almost no time, and now you can access the "latest data" whenever you need it.
So create an Event Loop. Make the Log Me button a Latch When Released control, and create a Value Changed? Event for it. What do you do when the button is pressed? Why, you get the data from the VIG and write it to your Waveform to Spreadsheet Express VI (ugh -- I hate Express VIs). But you use a trick -- since you are running LabVIEW 2016, you pass the File Name through the Create File with Incrementing Suffix VI before wiring the Path into the Express VI. Now, this actually creates a File first, so you just Close the File and use the (now unique) File Name.
Alternatively, if you want to "roll your own", you can put the intended File Name in a Shift Register of the While Loop surrounding the Event Structure. Use the File Name, do some simple String Manipulation to change it as you desire (i.e. "Log Me A.log" becomes "Log Me B.log"), load the new name into the out-going Shift Register, and you are ready for the next round.
The important thing is that the File Name definition needs to be in proximity to the File usage. Using both in an Event Loop keeps it also in (temporal) proximity with the Button Press.
Bob Schor
05-01-2017 12:43 PM - edited 05-01-2017 12:44 PM
Thank you for your answers. I believe a little clarification is in order concerning my usage of queues.
The reason for using queues here is that the VI I posted here is part of a larger VI for gathering data from different sensors, with different rates, but saving all of them in the same file, with a common time. Queues have been recommended to me in that case (Themocouple (2000Hz), Load cells (2000Hz), three axis accelerometer (2048 Hz), Optical RPM sensor (frequency counter), RS485 TX and RX (50ms) and CAN TX and RX (10ms)).
I only posted a subset of this larger VI here to understand the problem with the data logging, and that "lag" in the reading of the file path.
05-01-2017 01:46 PM
That seems like a reasonable scenario in which to use a queue.