I am trying to implement a recording time for data acquisition on a LabVIEW instrument I am using. Currently there is a record button that will log data on the first press and stop logging after the second, but I want to be able to put in exactly 2 or 3 (variable) seconds exactly to have it record. I have built a subVI that functions this way on its own, but when I put it in the while loop that contains the write to measurement file function, the whole instrument crashes. Any ideas why?
Here is a picture of what I've got for the subVI:
Solved! Go to Solution.
Greetings, it would be better if you inserted a snippet instead of a screenshot, since we can't convert the later to labview code by dragging, and don't know for example what's in the false case. Also, from the looks of it, your code cannot be used as a SubVI since it has a conditioned while loop, and will only deliver data when it finishes execution. You could accomplish what you want by using the tick count function, comparing difference between start and current, and wiring that to a case structure OR use an event structure in a separate loop with a timeout that matches the desired time interval.
I think this is a snippet. This is what I switched to as per your suggestion, but I'm having the same issue. I can't even run the VI without using the true hold, it just freezes and I have to force stop it. I very well may be using the event structure incorrectly. I just looked at the documentation and guessed how it works, but I've never used one before.
Yeah, when using events, you need to put them inside a while structure, and include a timeout and an exit condition, otherwise they stay forever waiting for an event to occur. I think this might be something like what you need
It basically incorporates a trigger that indicates data collection to start for a period defined by seconds, the timeout structure detects when that amount of time has passed with no other events happening, and shuts off data collection signal. Stop button just exits the loop. The reason to have 2 while loops is that, if no event occurs, the event structure "freezes" the while loop until either there is a timeout, or a handled event occurs.
Thanks so much, that makes way more sense.
The only issue I see is the fact that the data acquisition part of my VI is already inside of a while loop. I have dragged the sunVI outside of the while loop and ran the output through into the data write, but it still freezes after a half a second.
(the wires are broken where they enter the main while loop)
I'm sure you didn't need to see my whole VI either, so the second one is a bit crude.
Yeah, you need some brushing up in your LabView basics, a While loop and to that extent, any structure in LabView will deliver data in its outputs if and only if it has finished execution and it has data for each output, meaning that wires that come from inside a while loop will only deliver data when said loop finishes, and whatever code is waiting on that input can't execute until the while finishes. I'd strongly suggest to take the beginners' courses, it would help a lot with your program. Meanwhile, just put the data collection code inside the loop that says "main code here" and communicate via local variables, not wires, since parallel while loops cannot communicate via wires, one would block the execution of the other.