LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

why my local variable seems to be lag behind?

I 'm using LABVIEW 7.1. I have trouble witn local variables.
I used local variable to transit data in the program( to save messy connecting lines). But It seems that local variables value was not updated when I run the program. it updates the value the next time I run the program. It's kind of weird! Why????
0 Kudos
Message 1 of 9
(3,597 Views)
Hi Fenny,

Can you post your vi? It will be easier for us to help you.

Paulo
0 Kudos
Message 2 of 9
(3,587 Views)
Fenny:

Local variables (and globals) can lead to all sorts of problems in terms of race conditions, proper initializations, etc. If you are using them to avoid 'messy' wiring, perhaps you should take pause and look at another approach in designing your program. Just my advice.
~~~~~~~~~~~~~~~~~~~~~~~~~~
"It’s the questions that drive us.”
~~~~~~~~~~~~~~~~~~~~~~~~~~
0 Kudos
Message 3 of 9
(3,576 Views)
My whole program is 4MB, it's hard to post it in the forum. So local variables do cause problems and when use, we should take caution. I should drop the idea of using them . Could you recoomend some online resources about using local variables?
thanks!
0 Kudos
Message 4 of 9
(3,564 Views)
Hi fenny

Labview vis/function execute as soon as all inputs are available ( NOT left to right, NOT top to bottom). Since read local has no inputs, it executes prior to write local that requires an input. It looks to me that this is the cause of a 1 cicle delay in your updates. Make sure the local is written before read.

Hope it helps
Alipio
---------------------------------------------------------
"Qod natura non dat, Salmantica non praestat"
---------------------------------------------------------
Message 5 of 9
(3,557 Views)
oh, really!
Then this must be the reason that some data seems to be lag behind. But how should we avoid such lag-behind occurring if local variables are necessary?

thanks!
0 Kudos
Message 6 of 9
(3,549 Views)
Hi,

If you can't really avoid them, or don't want to, you can allway place them inside a sequence and wire something to the structure to make sure it will only work after that input "arrives".

Paulo
0 Kudos
Message 7 of 9
(3,547 Views)
Hm, smart idea!

thanks, Paulo!
0 Kudos
Message 8 of 9
(3,545 Views)
Would it be possible to post a screen shot of your vi or a small vi which shows the problem that you're having without including the larger code? I think that the problem is with the order in which everything is updated, but there may be a better way to solve the problem. As alipio has suggested, since LV is a dataflow language the best way to assure orderly operation is to design your program for control via data flow. I expect that there may be ways which are immediately apparent upon looking at your coding structure.

Also, on a project as large as yours there is significant room for problems with local variables. Many LabVIEW programmers avoid both local and global variables like the plague, prefering to use functional globals (also called LV2 style globals) instead. While using functional globals will likely not solve your current problem (which appears to be dataflow related), they overcome problems brought about by race conditions when you're reading and writing to a variable from multiple points in the code.
0 Kudos
Message 9 of 9
(3,527 Views)