Wanted to Share a coding problem I have just resolved:
I have been trying to debug the code above.
It worked for one device and not the other (Identical devices: DevA,DevB)
It has been throwing an error, unable to access variable.
I resolved the problem by changing by changing the timeout to something > zero
Hope this helps future travellers
This seems onlt yo be a problem during the first connection to the variable,
Subsequent reads don't seem to need it.
It is almost as though it needs time to troll through the project shared variable database to finde the reference the first time through.
Appreciate that you came forward to share your solution. It will be really helpfull if we get to know the reason behind this. I believe these things can be collected to a seperate board as I suggested earlier here
I noticed this a few years ago when I was doing some real-time work. My solution then was to perform a read of all of the shared variables as part of the initialization. I think I only had this probelm with Network Shared Variables.
I didn't look at the timestamp but it throws an error.
I would also like to start a discussion about how I think programatic NPSV works.
When I access a variable on another device, I construct a string using the device name (in the Project) followed by the variable name.
The "MAX" Name is not relevent.
So... It follows, that any code I compile must have a lookup table for the shared variable libraries in all project devices, referencing their IP Addresses.
If I compile an .rtexe, does this information reside in the .exe or is there an extra file (perhaps the aliases file) where this information is stored?
Answering my own question:
Contents of an aliases file:
This is how it does the lookup!
Since I don't use shared varibales I have to ask...
Is there a timestamp returned that reveals the state of the variable?
The timestamp is only available on the reads. It returns the timestamp of when the variable was written to.
One more thing to watch out for (we recently got bit by this). The NPSV is actually written to a buffer (8kB?). The variable is published either when the buffer is filled or 10ms has passed. There is a command to flush the buffer to avoid this 10ms delay.
Thanks for the 10 msec Nugget,
I was already aware of this but great to include it in this nugget, I can afford 10 mSec Latency for my application.
I've been using action engines (AE) to handle programatic access to NPSV's. I use the Open and Verify Connection when the program first starts to get things rolling and then store the refnum. This allows me to get all the overhead done first. After that I use normal read/write. Sometimes I have an AE per variable, sometimes I use the same AE to access many NPSV's and store an array of refnums.