LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using Local Variables, but Avoiding the Front Panel

Hi,
 
I have a synchronization issue using while loops in parallel.
 
Anyway,I have two while loops:
 
1) this loop reads a TTL pulse via a DIO card, and alternates the properties of a slider bar (label, min, max values, and resets the value to 0) between two states (#1 and #2).
 
2) reads from a VISA serial port, and saves info to a file everytime it reads a new data point. The info consists of the VISA data, and the slider value, and the state of the slider (#1 and #2).
 
Ok, when looking at my output file. I see inconsistencies: impossible values of the slider bar for either state. This means that while writing to file, the program thought it was still in state #1, but the slider had already been reset to zero and gone to state #2.
 
My theory:
The way i implemented it is that the state (#1 or #2) is indicated by a boolean indicator on the front panel. It switches whenever it sees a TTL pulse. But the second loop might see a change in the slider value (resetting to zero) but hasn't recorded the Boolean change (both values read via local variables). Hence the inconsistency.
I believe this is due to the slow nature of the front panel on my computer... there seems to be a lag whenever i press a button or open a dialog window.
 
My Question:
Is there a way to use local variables without displaying their value on the front panel. That is, i want a boolean variable which loop 1 writes to and loop 2 reads from, but have them update instantly... while keeping the loops independent, so that they both acquire data as fast as possible. Hardwiring would be the best, but I can't seem to have two while loops running in parallel while hard wired (they then insist on becoming sequential)
 
 
Alternatively:
Is there a Shift-Register-Like function which allows to while loops to be connected directly, but still run independently? In other words, what the best way to implement this scenario:
Loop 2 uses a value generated by loop 1, which is spat out constantly. Both loops would run independently,  so loop 2 would use the last updated value by loop 1 for each new iteration... .and wouldn't worry about reusing values (if loop 1 is slower) or missing any values given to him by loop 1 (if loop 1 is faster).
0 Kudos
Message 1 of 2
(2,610 Views)
I think I followed yur explanation, but I might be somewhat confused.

What you described sounds like a classic race condition. Global and local variables can be quite susceptible to these.

You are right about parallel loops: They cannot have any data dependency (a wire connecting the output of one to the input of the other). This is the fundamental paradigm of LabVIEW: Dataflow.

The producer/consumer architecture is ideal for your situation. You may want two producers and one consumer.

I prefer to transfer data among loops via queues. I would probably have at least three loops: the DIO reader, the serial port reader, and the user interface (UI) and save to file loop. If a large amount of data needed to be saved, I might separate that to another loop, but it is probably not needed in your case.

Your question: Local variables are tied to a control or indicator. You may hide the indicator, but it must be on the panel. You can have a variable (a wire on the diagram) whihc is not hooked to an indicator. With a case structure, a while loop, and a shift register you can put an indicator inside a case which executes infrequently, allowing the loop to run much faster than the UI updates.

Note: Put a wait function in each of the parallel loops. The value can be small, even zero. This allows LV's internal scheduler to switch between the loops much more quickly than without.

Lynn
Message 2 of 2
(2,597 Views)