LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with Event Structures...

I am trying to write a program that has a main event structure that handles all the front panel activity but also has a while loop running in parallel with the event structure that can poll the current values of a device.  It seems that there is a problem with running a while loop in parallel with an event structure, but I'm not quite sure why.  Attached is a simple program that shows the structure I am trying to use.  Any advice is appreciated.

Kasey

0 Kudos
Message 1 of 8
(3,423 Views)
I can't do two attachments in one message...here is the global variable.

0 Kudos
Message 2 of 8
(3,421 Views)

There is no problem. You simply need to have the event structure inside a while loop of its own. The outer loop can only iterate when all the code inside it has finished running, and that includes the smaller while loop. BTW, if this is in the same way, you don't need a global variable. You can even do it without a local, if you only have 2 loops. Simply stop the event loop with a T constant and the other loop with the stop control.

To learn more about LabVIEW, I suggest you try searching this site and google for LabVIEW tutorials. Here and here are a couple you can start with. You can also contact your local NI office and join one of their courses.
In addition, I suggest you read the LabVIEW style guide and the LabVIEW user manual (Help>>Search the LabVIEW Bookshelf).


___________________
Try to take over the world!
0 Kudos
Message 3 of 8
(3,415 Views)
Thank you.  The extra while loop seems to take care of the problem.  I realize that I don't need a global in my simplified example, but in the real program, the while loop calls a subvi and the stop is issued from that subvi, so I think I need a global in that case.  I left it in my example in case that had something to do with the problem.  I'm glad to see it doesn't.

Thanks again.
Kasey

0 Kudos
Message 4 of 8
(3,404 Views)

Your two loops cannot be stacked, they need to be independent. You can sense the stop button in multiple independent event structures, so run two loops, each containing an event strucure. See attached quick modification (LabVIEW 7.1). All clear?

(BTW: There is no conceivable reason for your global variable and stacked sequence structure!)

Message Edited by altenbach on 09-01-2005 10:01 AM

0 Kudos
Message 5 of 8
(3,403 Views)

Actually, as I explained above, I do need a global variable because in the real program I am calling a subvi and closing the loops from that subvi.  Is there a way to do that without a global?  Also, I would love to get rid of the sequence, but if I use a global I need a way to reset it after the end of the program.  Is there some other way to do that?

Thanks.
Kasey

0 Kudos
Message 6 of 8
(3,396 Views)

Yes, think dataflow!

If you wire it as in the attached figure below, the global variable will be written once the loop stops. Dataflow dictates that a node will execute once all inputs contain data and outputs only contain data once the node has finished. In this case, data is only available AFTER the while loop has stopped.

There is no need to complicate the code with stacked sequence structures.

Message Edited by altenbach on 09-01-2005 10:26 AM

0 Kudos
Message 7 of 8
(3,393 Views)
Thank you.  That looks much neater.

Kasey

0 Kudos
Message 8 of 8
(3,382 Views)