LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Make sure shared variable value is written

I am thinking about switching to from Datasocket to shared variables, but I just have one small question. When call to "write to shared variable" node ends, is it certain that the new value has been written (unless there is an error)? If I read the same shared variable right after writing to it, I just want to be sure that I always read the new value (without performing any additional checking such as comparing old value to the read value...).

 

0 Kudos
Message 1 of 7
(3,041 Views)

You can check this by writing tag (for ex. Current time) information along with the data and recheck the same by reading the data at Read Shared variable node. Later you can detach the tag from the data by using some pattern comparison.

 

Reagards

Visuman

0 Kudos
Message 2 of 7
(3,039 Views)
Thanks, but I I would prefer not to do that since it just adds more code and I want to keep it simple. I was hoping the write to shared variable function only returns when the value has been written.
0 Kudos
Message 3 of 7
(3,036 Views)

Yeah thats right, the shared variable always reads the updated one. I suggested the method to test the udation frequency

Reagrds

Visuman

0 Kudos
Message 4 of 7
(3,034 Views)
When you READ from the variable, you can right-click and select the 'Show Timestamp' option. While writing the value into the variable, store the timestamp somewhere and check whether this value is the same as the timestamp returned when reading from the variable.
Adnan Zafar
Certified LabVIEW Architect
Coleman Technologies
0 Kudos
Message 5 of 7
(3,013 Views)

Thanks veryone. I guess I'll use the timestamp method if it looks like the program is not reading the variable properly sometimes.

 

0 Kudos
Message 6 of 7
(2,954 Views)
The Variable is client/server based.  All writes must first propagate from the client to the server and then from the server back to the client.  This happens asynchronously so there's no guarantee that reading back a Variable after writing it will show the updated value.  Using the timestamp terminal to determine if the value has changed will certainly work.  If you're accessing the Variable through the static node (not the refnum based dynamic API), you can right click on the node and select "Show Timeout".  Using the timeout terminal will accomplish the same thing as using the timestamp except the code will be much easier to write.  This feature was added in LV 8.6 for certain types of variables and was supported more broadly in LV 2009.  If you're using one of these versions of LV, this might be an option.  Otherwise, the timestamp is probably your best bet.
0 Kudos
Message 7 of 7
(2,944 Views)