LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

using global variables

I am using subvi's in my program and passing datas between them using global variables.When i run my program , in one of the arrays , the values  are not real and keeps changing arbitrarily.
Sometimes the first 10 values of the array is incorrect and others are correct.
.I am not able to find out what would be my problem??Is that because of the global variable?If anyone could help me solve the issue???
0 Kudos
Message 1 of 12
(3,593 Views)
This would indicate a programming error and should not happen.
  1. Try to find all the instances where you write to this global. Is it in more than one location?
  2. Maybe you have many globals with similar names and have a mixup somewhere?
  3. Maybe you try to read from it before another location writes valid data to it (race condition)?

If you cannot figure it out, attach your program. 🙂

 
0 Kudos
Message 2 of 12
(3,590 Views)
Hi,

No the problem is not because of Global Variables.

I use these extensively  in machine control applications where the machine status I/O is read as an array  in the Main.vi and passed to the relevant sub VIs through Global variables and have not faced any issue as described by you till date. Possible areas to check would be :

1. Race conditions where you are trying to read / write  to the variable simultaneously. If your coding is such that, then you have to enforce discipline by creating some kind of data dependency so that  this conflict is avoided.

2. The source of the input to the  problematic array - maybe it  IS changing arbitrarily in real time.

3. If  the global variables are handled inside of Timed loops in the Main and sub.vis,  then priortize the  loops by assigning the highest  priority to the Main timed loop.

For all the bad reputation that these Globals have in the data-flow model of  LV,  I find that these are very effective and simple for passing data between main and sub VIs provided you handle them diligently. Yes they do have a purpose in life and I love them!

Raghunathan
Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 3 of 12
(3,594 Views)
hi alten bach ,
 
Thankyou for your suggestions and support regarding this issue.
 
0 Kudos
Message 4 of 12
(3,556 Views)

Hi raghunathan,

 

Thankyou for your suggestions and support regarding this issue.

I have found the race condition in the program and trying to eliminate it by using type2 global variable.

I think type2global varibale can be used in Labview 8.0 and further.But i am using Labview 7.1.So i amtrying to build a subvi as type2 global variable.

Is there any other way to solve the race condition?

 

0 Kudos
Message 5 of 12
(3,554 Views)
hi ,
 
I am trying to use type2 global variable to eliminate my problem as the attachment program .
In the attachment program the LV2 (subvi ) is the one i am using.The main program is different.
From the main program i will be getting the variables and giving it to the LV2 subvi.
while writing i am writing it as an array and while reading i have to read the first value of the array.(index  0 )
but i am not able to read the first data in the LV2 subvi.
 
COuld anyone help me out solving this issue?
thanks,
 
radhika
0 Kudos
Message 6 of 12
(3,553 Views)
Smiley SurprisedSmiley SurprisedSmiley SurprisedSmiley SurprisedSmiley Surprised
 
Globals?????? Did someone say "globals"????
 
Never use 'em. Too much chance of problems just like this. I'll use functional globals, thank you very much.
 
Life is much simpler when you know exactly where your data is going and when.
 
Globals ....
 
(shudder!)
 
Smiley Happy
PaulG.

LabVIEW versions 5.0 - 2023

“All programmers are optimists”
― Frederick P. Brooks Jr.
0 Kudos
Message 7 of 12
(3,536 Views)

Moving to the LV2 style global is a good step. Please excuse my previous post .... some of us are just a little too passionate about certain things. I'll get back to this.

Smiley Happy

PaulG.

LabVIEW versions 5.0 - 2023

“All programmers are optimists”
― Frederick P. Brooks Jr.
0 Kudos
Message 8 of 12
(3,537 Views)
I don't like your example of the LV2 global. Actually, I wouldn't even call it a LV2 global Smiley Very Happy but something else??? The data being written and read from a global must be the same, or it's not really a 'global'. Look up "functional global variables" in the LabVIEW help files. It will explain better than I can.
PaulG.

LabVIEW versions 5.0 - 2023

“All programmers are optimists”
― Frederick P. Brooks Jr.
0 Kudos
Message 9 of 12
(3,521 Views)
Paul is correct; the best way to avoid these race conditions would be using a functional global variable. I have included a link to a knowledgebase containing a discussion of functional globals. Essentially this is the preferred method to avoid race conditions with global variables because you can better enforce the flow of the program. Good luck with your application, and have a great day!

Mike D.
Applications Engineer
National Instruments

Using LabVIEW to Create Multithreaded Applications for Maximum Performance and Reliability:
http://zone.ni.com/devzone/conceptd.nsf/webmain/d2e196c7416f373a862568690074c759
0 Kudos
Message 10 of 12
(3,504 Views)