LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Pit falls of using an event structure inside of a SubVI

Hi!

I've developed some code for a state machine SubVI to drive some digital IO.  The SubVI has to be configured to a large extent from its own Front Panel while the calling "main" VI controls the "polling" of the SubVI's code and the driving of the actual hardware based on the SubVIs output.

I have written a lot of event based code inside an Event Structure to drive the user interface of the state machine.  (The user can cause the front panel to "pop-up" with a boolean control line).  Now, the event structure has a "timeout" of 1ms so that the main program loop within the SubVI can execute while being polled.

This works just fine execept that there is an added 1ms delay.  However, the polling frequency of the SubVI will be on the order of 100-500ms so I think that 1ms in the timeout of the event structure should be insignificant. 

Attached isn't the code in question, but an example of what I am trying to acomplish.  The SubVI simply increments the numeric output at each itteration.  There is a reset button inside the SubVI to reset the numeric indicator to 0.  The reset button is driven by the event structure.  The MainVI simply polls the SubVI and shows the output.  This code works....

I need input from the hive mind as to what might be some potential un-seen pitfalls of implimenting event structure code inside a SubVI.  Also, is there anyway to eliminate the 1ms delay?

Thanks
-Nic
Download All
0 Kudos
Message 1 of 23
(5,302 Views)
It looks like I can wire a "0" to the timeout.  Everytime i hit "reset" it seems to work w/o any problems.  Can there be an instance where I press a control button and it not fire its event because....???
0 Kudos
Message 2 of 23
(5,290 Views)
Nickerbocker,
 
My Main VI.vi looks blank to me. 
 
Regards,  -SS


Message 3 of 23
(5,282 Views)

First of all, your MainVI is empty..  It is not calling anything.. There is no code.

You also have to consider that a sub-vi can be a fully functional VI that is being called by another VI.  So using event structures in a sub-vi can be quite acceptable.

However, I just don't understand why people are so attracted to Local Variables.  (have a look at this thread)

There are better methods to accomplish what you are trying to do.

Let me modify your code and I will explain.

Back soon...

RayR



Message Edited by JoeLabView on 06-17-2008 01:07 PM
Message 4 of 23
(5,276 Views)
I was running your main VI in execution highlighting mode, but could not find any errors. 😄
 
I have no idea why you even have an event structure and loop, since all you do is polling. Why don't you just poll the boolean? In fact since none of your loops spin anyway, all you need is a naked feedback node (globally initialized) in your subVI.
 
No loops! This is all the code you need in the sub:
 


Message Edited by altenbach on 06-17-2008 10:10 AM
Message 5 of 23
(5,272 Views)
Oooops...i forgot to save the "My Main.vi" before attaching it.  I've re-attached the two file.  I guess when I have a lot of buttons that all do something the Event structure helps to keep things organized in the code for me....  but it can just as easily be coded w/o the event structure I suppose....
Download All
0 Kudos
Message 6 of 23
(5,262 Views)
Just got back... no time to look at your VI's..
 
HAve a look at the attached examples for passing values to lower loop without Locals.
 
 
Message 7 of 23
(5,256 Views)
I'm sorry, but I do not understand what the point in that is.  It sure does look like you have to draw a lot of extra lines to make the code work w/o locals.  The opperation of the VI is not as apparant w/o the locals and with the extra visual "noise" of the enqueue VI's.
0 Kudos
Message 8 of 23
(5,248 Views)
Well, here's what I had in mind. Works just fine.:)
Message 9 of 23
(5,243 Views)


Nickerbocker wrote:
I'm sorry, but I do not understand what the point in that is.  It sure does look like you have to draw a lot of extra lines to make the code work w/o locals.  The opperation of the VI is not as apparant w/o the locals and with the extra visual "noise" of the enqueue VI's.


It is using a queue..  It's not noise...  It's proper coding practice. 
 

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).

 

Message 10 of 23
(5,218 Views)