LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing a stop boolean to a while loop within a subvi

Hello! Sorry to be bugging you guys on my first post, but i've been scratching my head with this one. 

 

 

I've written a Serial Read/Write program that reads and writes asynchronously, and am trying to package it in a nice little subvi. The problem I've run in to is that due to the nature of my program I have while loops (one for reading and writing) that keep going when operating normally, making it difficult to pass in a stop boolean from outside the sub-vi to stop the while loops.

 

I know I can use a global variable to do this, but I'm trying to find a better way so I can neatly implement this little serial port handler without the need to create a separate vi for my global vars.  

 

I have my reading/writing data being communicated through to the subvi niceley via queues, and I wish i could just have a boolean i can wire into this subvi that will get read with every iteration of the nested while loop.

 

Thank you for any help! 

 

-Paul

 Super_Serial.JPG

Message Edited by f18viper on 06-10-2010 03:16 PM
0 Kudos
Message 1 of 8
(4,777 Views)

The first thing I would say is that if you want that to be a subVI, get rid of the loops altogether. The loop would be in your main VI.

 

If you keep the loops, then your main could pass a reference of a stop button to the subVI. In the subVI, OR the read of the local with the value property of the reference. 

 

This question has come up numerous times so check the LabVIEW examples and the board for 'control references'

Message 2 of 8
(4,771 Views)

I can't get rid of the loops within the subVi because then i would be opening and closing the port constantly, which isn't too pretty.

 

I'm still a LabView newb so thanks about the references, i didn't really know about that. I'll give it a shot. 

0 Kudos
Message 3 of 8
(4,765 Views)
Having the opening and the closing of the ports in the main VI is the obvious solution to your objection. It is the common way of doing things.
0 Kudos
Message 4 of 8
(4,762 Views)
That would be, but I want one subvi for my serial device.
0 Kudos
Message 5 of 8
(4,758 Views)

Action Engine Nugget

 

Take the loop out of your subVI.  Turn it into an action engine with 3 actions.  Init, Run, Close.

 

Before the loop in your mainVI run the subVI passing it the Init enum.  In the loop, use the subVI with the Run action.  After the loop, use the subVI with the close method.

 

Now you have one subVI, and your main VI controls the opening, closing, and execution of the while loop.

0 Kudos
Message 6 of 8
(4,752 Views)

f18viper wrote:
That would be, but I want one subvi for my serial device.

 

What is the reasoning for this? It doesn't make sense not to put it in main. If there is a reason you want it to be in a subVI, explain, and someone can probably give you direction on why not to do that and how to organize your program correctly.

 

Edit: or listen to ravens

Message Edited by for(imstuck) on 06-10-2010 03:54 PM
0 Kudos
Message 7 of 8
(4,745 Views)

This is what they are talking about.  The following should be part of your main.  The loop is in main so stopping the loop is easy.  The loop repeatedly calls you subvi until stopped.  Your subvi would only contain serial read and write code.  You could even eliminate the queue and send the read data directly to the write by using a wire.

 

This way is much simpler than your original vi.

 

Serial.png

- tbob

Inventor of the WORM Global
0 Kudos
Message 8 of 8
(4,733 Views)