03-22-2015 10:40 PM
Hi everyone, I am trying to get more information on how to communicate between two parallel loops. I am running two while loops in parallel in my VI. While Loop 1 has an event structure in it that will stop the loop when Boolean control ComError in While Loop 2 changes value. While Loop 2 just sets the ComError boolean to True and is connected to the Stop control of the loop. When I run the VI, I expect when While Loop 2 sets ComError Boolean = True that then While Loop 1 event structure ComError changed value event would trigger and stop While Loop 1 but it does not.
I have attached my VI. What am I doing wrong?
Thanks so much for everyone's help.
03-22-2015 11:04 PM
That VI isn't going to work like you think it is.
The Value change event fires whenever the user changes the value of the control, or when a value is sent to the Value(Signalling) property node of that control.
Wiring a value to a local variable will NOT fire a value change event.
03-22-2015 11:19 PM
03-22-2015 11:25 PM
Try it.
I don't know if it would be the most efficient method because what you have is a simplified VI to test out a concept. What is best is going to be determined by the rest of your application.
03-23-2015 12:23 AM
03-23-2015 10:32 AM
Thanks everyone for their input. My While Loop2 is reading a com port using VISA read function. My While Loop 1 has an event structure in it that has different event cases dependent on user input on the front panel. The STOP control of While Loop 1 is controlled by boolean output from each of the events. All of these events will keep While Loop 1 running except for one event which is when the User hits the done button. I want While Loop 1 to shutdown if there is a VISA read function error.
Taking the advice of RavensFan, I created a boolean variable called "ComError." In the While Loop 1 event structure, I created an Event Case called "ComError" (value change) which shuts down While Loop 1 whenever this variables signal changes. Then I passed the While Loop 2 error cluster "status" to "ComError" property node value (signaling). This seems to work and it effectively shuts down While Loop 1 when While Loop 2 has a ComError.
This seems to be the best method for my application but maybe there are more efficient methods of doing this? Thanks so much!
03-23-2015 11:56 AM
In your described design, the user interface handling stops along with While Loop 1 when a VISA read function error occurs. I assume that would probably also mean that your application is entirely finished. This is often not what you want - instead, consider a VISA read function error being reported to the user in some way and allow the user a way to stop or recover.
Also, you did not create a Boolean variable called "ComError", you created a Boolean control or indicator. Controls and indicators are user interface elements and should not be used for purely programmatic operations. A better solution would be a User Event. A User Event allows you to define your own event, register it for your Event Structure, and then raise it in your While Loop 2 when the error occurs.