06-10-2010 03:15 PM - edited 06-10-2010 03:16 PM
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
06-10-2010 03:33 PM
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'
06-10-2010 03:39 PM
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.
06-10-2010 03:41 PM
06-10-2010 03:44 PM
06-10-2010 03:51 PM
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.
06-10-2010 03:53 PM - edited 06-10-2010 03:54 PM
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
06-10-2010 04:15 PM
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.