03-15-2011 07:52 PM - edited 03-15-2011 07:56 PM
Hi:
I am wondering if there is a design alternative to using global variable in my situation right now. In my application, two subVI(vi1 and vi2) are used by a master VI.
The flow of application requires three steps
The way I am handling this problem is that I create a boolean global variable "vi1 running" whose value is repeatedly checked by the master VI. At the end of step1, this variable is set "TRUE" which then triggers the start of vi2. Similarly, another global variable called "kill vi1?" is also created to stop running vi1 at step 3, whose value is repeatedly checked by vi1. In summary, the status of vi1 is communicated via global variables.
I understand global variables are usually not prefered as it causes debugging problems and makes program hard to read. So I was wondering if you have run into similar situation and can think of any alternative design?
Thanks,
KC
03-16-2011 12:13 AM
Hi kchenphy,
In vi 1 when when step 1 is over you can open reference of vi 2 using "open vi reference" from application palette. Then you can use Invoke node to use RUN method. This will run Vi 2. Now using same vi reference you can monitor execution status of vi 2 in vi1. You can use property "Execution state"
When it will be other than "Running" you can stop vi 1 till that time you can keep vi 1 in loop.
I hope I made my point clear.
03-16-2011 02:06 AM
you can make use of function globals or queue for achieving the same
03-16-2011 02:44 AM - edited 03-16-2011 02:45 AM
Hi,
In this case it's communication (sending events) between two loops and I would definitly suggest Queue's.
If you don't know how to use those, search for producer/consumer loops, allthough this is a structure to use in 1 VI, you can put each loop in a different VI and it will still work.
I've posted a very simple and dirty example as attachement