LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Queue state machine event structure and latched switches

I modified the timer variable, still nothig change
the output from the random generator, only changes once.

I turn on the highlight execution, and see the execution wait in default state.

waiting for user action

the timer has no real effect

0 Kudos
Message 11 of 16
(886 Views)
According to the way you wrote your code, a user has to press a button to cause the event structure to exeucte.  Until the event structure executes, the current loop iteration does not finish.  You need to understand that Labview execution is dependant on data flow.  The loop will not advance to the next iteration until all code inside the loop has passed its data.  I don't quite understand exactly what you want your code to do.  If you want the loop to continue going without user intervention, put a timeout case in the event structure.  Wire a numeric value to the timeout icon.  Then you can delete the delay function.  The way the timeout event works is that if no event happens for a certian period of time (the timeout value wired to the timeout icon) then the timeout event fires.  You can put the random number code inside this timeout case.  Then when you run the vi, the timeout case will fire after the timeout value and the event structure will have completed its data flow.  Now the loop can increment and start over again.  After the timeout value, the timeout case again fire and a new random number will be generated.  And so on...  If a user presses a button before the timeout value, its event will fire and the event structure will be done, and the next loop will start.  Try adding the timeout case as I described.
- tbob

Inventor of the WORM Global
Message 12 of 16
(871 Views)
Thanks tbob,
I wired a value (25) to the timeout terminal and add an event case (application-timeout) to the event structure.
I place the random number vi in the timeout event case.
It works good now.

In real application, in the timeout event case, I read/scan 14 analog channels (hardware) and update the gauges respectively.

Next, I need to turn the "compressor" switch off when the random number is greater than 0.97.
everything else stays the same,  that is keep reading the analog channels, all switches status the same, except "compressor" = off.

0 Kudos
Message 13 of 16
(856 Views)
Easy, use a compare function like greater than or less than and wire to a case structure.  Put in code inside the case structure to do whatever you want.  This is very basic Labview (or any programming language) knowledge.  You really should either take a LV course, by a book, or study the online tutorials.
- tbob

Inventor of the WORM Global
0 Kudos
Message 14 of 16
(849 Views)
thanks
I got it working now.  I am ok so far.
you did a very good job, bring me up to speed about event structure with the timeout case.
sometimes, I learn better by getting involve into things.

I started with the two loops (my first few attachments) and I ended up with your one loop.
Too me, your one loop is easier to understand.
Just curious, can you elaborate when to use one loop and one to use two loops (Producer -consumer)?

Again thanks for teaching and your patience
0 Kudos
Message 15 of 16
(843 Views)
One clear case for using two loops is that one of them (a data acquisition loop for example) must run much faster than the other (User interface). User interface loops run slowly because people are slow (compared to CPU processing speed) and because the OS does things like screen updates at rates which are not under the programmer's control.

If the process activated by an event in an event structure cannot be completed before the next event is generated, then that process should be in a parallel loop. How fast can the user click two different places on the front panel or type something in and hit "Enter?"

Lynn
0 Kudos
Message 16 of 16
(838 Views)