LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

local variables

I have used local variables in my programs mainly to update runtime variables that do not change very often. I came across a situation where I would write the value of a control in a case statement using a local variable. On the next iteration of the loop, the control had the old value and would never get updated. I was able to get it to update by adding a 20ms delay (5 ms would not work). Or replace the local with a value property node (no delay was needed). Then it would update properly. My questions are:

 

1. What can cause a control to never update when I write a local to it? If I write it once, is it guaranteed to update the memory eventually?

2. When you write a local, does it update the control when the part of the code it is in (case sequence etc) is finished?

3. If I use a value property node, does that guarantee the control is updated when it finishes executing the property node?

 

I had assumed that if I wrote a local once, that ‘eventually’ it would update the control. It did not happen in this situation. What I would like to here, hopefully from NI, is that if I write to a local, the control value will be:

 

A. Guaranteed to update to the value of the last write. What you saw was a bug.

B. Is not guaranteed to update the control If (condition i.e. it is read before the update is completed, etc)

 

Same for the property node:

 

A. Guaranteed to update to the value of the last write.

B. Is not guaranteed to update the control If (condition i.e. it is read before the update is completed, etc)

 

 

Hopefully someone from NI can shine some light on it.

0 Kudos
Message 1 of 6
(3,147 Views)

There is nothing that would cause a write to a local variable to never update and the update will happen immediately. If you did not see the update, then either that section of code did not execute or you had another write to the local (or indicator) that happened immediately after. That latter is what is called a race condition and my guess is that is what you because adding the delay made your other write happen first. The same thing will happen with a value property node except it will take longer because of the switch to the UI thread.

 

Post your VI if you want help in finding the race.

0 Kudos
Message 2 of 6
(3,137 Views)

In my case it did not. It is not being written any place else. Hopefully someone from NI can answer this.

0 Kudos
Message 3 of 6
(3,129 Views)

 


@ErnieH wrote:

I have used local variables in my programs mainly to update runtime variables that do not change very often.


 

What is a runtime variable?

 

What is your LabVIEW version?

In any case, we need to see some code that demonstrated the problem. I suspect a race condition.

 

 

  • Where is the terminal of the associated control?
  • How many other instances of the same local variables are there?
  • How many are read vs write?
  • How do you determine that the control has the old value?
  • What controls the case structure?
  • Could it be that the value wired to the case selector terminal is delayed because of race conditions and the local thus only updates one iteration later?

 

 

Front panel controls are by default asynchronous, so they only get visibly updated at a reasonable interval. When you update a local variable, it updates the data copy in the associated transfer buffer as soon as you write to it, and when you read from the terminal later, it also reads from the transfer buffer. There is no way that things are not perfectly synchronized between different iterations, so there must be some other logical explanation. As I said, I suspect a race condition due to sloppy coding.

 

Property nodes are synchronous.

0 Kudos
Message 4 of 6
(3,119 Views)

Rather than spreading the conversation around, it really should be kept in the original thread where you first brought your problem up.  You already had a lot of conversation on it with other forum members.

0 Kudos
Message 5 of 6
(3,101 Views)

Actually I was asking more generic, specific questions about locals in general that I had hoped would be answered by someone at NI that had knowledge of how the code is compiled. The previous post seems to be a bug that can happen when you use the mouse down event to update a front panel control. Is there another board to post this question to just for NI engineers, or should I send it to my local rep?

0 Kudos
Message 6 of 6
(3,079 Views)