LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Alternative to global variable?

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

  1. First, vi1 is called
  2. A loop is implemented in vi1. Once vi1 has started or finished the first loop, run vi2 in parallel with vi1
  3. Once vi2 is finished, shut down looping in vi1 and exit vi1 as well

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

0 Kudos
Message 1 of 4
(4,202 Views)

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.Smiley Happy

 

 

Gaurav k
CLD Certified !!!!!
Do not forget to Mark solution and to give Kudo if problem is solved.
0 Kudos
Message 2 of 4
(4,182 Views)

you can make use of function globals or queue for achieving the same

Regards
Guru (CLA)
0 Kudos
Message 3 of 4
(4,171 Views)

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

 

Consumer_Producer.png

Kind regards,

- Bjorn -

Have fun using LabVIEW... and if you like my answer, please pay me back in Kudo's 😉
LabVIEW 5.1 - LabVIEW 2012
Message 4 of 4
(4,162 Views)