LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

main/subVI control confusion

hello one and all,

 

i am a little confused on the best way to approach this.  i have a main and sub VI.  the main VI is the main VI and the sub VI has a complex settling routine and after all the little parameters have settled out, it quits its while loop and returns control back to the main which collects, averages, and manipulates the settled data.

 

ok, so i want the stop button on the main VI to stop the sub VI while loop in mid stream if need be; to gracefully exit the program.  so i experimented with Notifiers, which worked well with the latter.  but then i need to pass input parameters changes from the main into the sub and then when the sub is finished settling, pass output parameter changes from the sub back into the main.  i tried Notifiers on that and it looks ok with the input parameters but gets pretty damn messy with the output parameters.

 

so what is the best way to approach and achieve input and output parameter changes while gracefully aborting nicely?  thank you in advance and have a great day.  lucas  p.s. i am using labview 2010 x64 bit under win7.

0 Kudos
Message 1 of 6
(2,357 Views)

Take a look at the 'message handler' design pattern.

 

I'd use queues instead of notifiers, as passing a bunch of parameters would override each other when using notifiers.

Then use a 'message'-type-def-cluster. First part is the message such as SetParamA (use an enum or string), the second part is any data you want to send along such as parameter values (use string or variant + FlattenToString/UnflattenFromString or the variant functions). I did demonstrate this using events here.

 

You will need to code your message handler ('SubVi') to check from time-to-time if a new message is available. This is best modelled as a state-machine, where you either have an 'idle' state in which you wait for the next message or you check for new messages in each iteration and perform 'normal' states when the Dequeue gives you a timeout, otherwise first handle the message.

 

Felix

 

 

0 Kudos
Message 2 of 6
(2,342 Views)

do you have the source labview vi code available for your nugget that you linked under "here"?  i would like to run and trace that through my code so that i can understand it hands on.  the running example will really help me.  thank you in advance and have a great week.  lucas

0 Kudos
Message 3 of 6
(2,303 Views)

Code is posted there in post 4. At that time the forum was limited to 3 pictures, so I had to split the posting into several.

But all you really need is the message cluster.

 

Felix

0 Kudos
Message 4 of 6
(2,293 Views)

ok, so i still have the question, please direct me.  i have a cluster of data wrapped into a UserEvent.  if that data changes in the mainVI, how can see how to get the subVI to respond to the change, but how do i unwrap the cluster from the UserEvent to get at the data?  same with the output from the subVI to notify and unwrap the data in the mainVI.  i guess i need that cluster of data more global or public to both VIs.  how would i do that?  or, would i need to unwrap it from the UserEvent?  thank you in advance.  lucas

0 Kudos
Message 5 of 6
(2,280 Views)

Hi Lucas,

 

Have you tried using global variables to communicate between your main and sub VIs?  I often find that this is the easiest way to reliably pass data from one vi to another.

Scott A
SSP Product Manager
National Instruments
0 Kudos
Message 6 of 6
(2,248 Views)