09-24-2012 08:23 PM
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.
09-24-2012 08:40 PM
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
09-25-2012 07:11 AM
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.
09-25-2012 07:17 AM
Since I don't use shared varibales I have to ask...
Is there a timestamp returned that reveals the state of the variable?
Ben
09-25-2012 07:17 PM
Ben
I didn't look at the timestamp but it throws an error.
09-25-2012 08:17 PM
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?
09-25-2012 09:13 PM
Answering my own question:
Contents of an aliases file:
----------
[GWB]
GWB="192.168.1.36"
[GWB-Munted]
GWB-Munted="192.168.1.41"
[GWB2]
GWB2="192.168.1.38"
[MasterController]
MasterController="localhost"
[MESy-BC1-192-168-1-39]
MESy-BC1-192-168-1-39="192.168.1.39"
[My Computer]
My Computer="192.168.1.99"
[Remote Controller]
Remote Controller="10.30.203.37"
[Simulator]
Simulator="192.168.1.48"
[TWB]
TWB="192.168.1.35"
[TWB-Munted]
TWB-Munted="192.168.1.36"
[TWB2]
TWB2="192.168.1.37"
-------
This is how it does the lookup!
09-26-2012 07:15 AM
@Ben wrote:
Since I don't use shared varibales I have to ask...
Is there a timestamp returned that reveals the state of the variable?
Ben
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.
09-26-2012 07:19 PM
Ben,
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.
09-27-2012 07:23 AM
Timmar,
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.