Showing results for 
Search instead for 
Did you mean: 

How to read shared variables inside event structure ?



I have a problem that my shared variables do not update inside event structure. The program(s) I am trying to get working is seen in the attached screenshot. It works as follows:


0. I start the vi that is unsquared.

1. I write a string to a shared variable using vi in red square. I make sure that its updated using write-wait-read.

2. I run the other vi (blue square), this changes the boolean shared variable.


The unsquared vi has been running the whole time, it has event structure bind to boolean shared variable change (the one in blue vi). After I have runned the blue vi, the unsquared vi should change the indicator values to match the ones in red vi. However I have to start the blue vi multiple times to get it to change, sometimes even 6 times.


Also, when I change the value in red vi to a third value and start blue vi multiple times, the unsquared vi shows all the variables. I.e. I put "cat" to red then start red, put "mouse" to red then start red,... and then start clicking blue... Unsqured shows cat, mouse,..., dog (dog is the default).




How can I force the shared variable to update inside event sructure. I want the current value of the variable, not some historical values.





0 Kudos
Message 1 of 6

Do you have any sort of buffering turned on with that shared variable?

Message 2 of 6


How do I check the buffering?


I have tried to wait long time (~ 10 sec) after changing the string... So if I there is a time buffer, it should have been changed. In the red vi, variable changes in less than 100 ms.


I there is a buffer that stores old values, how do I clear that or disable it?


IMHO shared variable buffers shoud not exist. There should be only one value and you should be able to get that value regardles of which program is asking that value (if the buffer is in the event loop, then it is another story... but again... how to disable it?).




0 Kudos
Message 3 of 6


Found the buffering... disabling it solved the problem... thanks.


FYI, there is another solution that I just found out... attached. Adding timeout to the event structure and the variable read outside the event structure... This makes the shared variable strings (one that is read outside and the otherone that is read inside) different.


Could someone explain why the variables are in different state even if they are used in the same place and looped with 10ms intervals?



0 Kudos
Message 4 of 6

The outside one is read right away.  The inside one isn't read until the event occurs, by that time the value in the shared variable has changed.


I don't know what your ultimate goal here is, but you are basically playing around with variables in a way that is leading to race conditions.  It is a race between when values are written to the shared variable and when values are read from them.

0 Kudos
Message 5 of 6


Well, this is a part of network ui, so the race is between human (write) and computer (read). I would guess that the human cannot produce data fast enough for machine to handle (mouse click interval < 10 ms is very difficult) + the state locks after first input.


And actually, its other way around... The outside variable is changed before than the variable inside the event loop. I would guess that all the variable changes in the buffer has to be done and the event structure does it when trigged and the while loop (outside variable) does it every 10 ms (= event structure timeout).


Anyway, I will have problems if I poll the variable too fast.


0 Kudos
Message 6 of 6