NI Home > Community > NI Discussion Forums

LabVIEW

Showing results for 
Search instead for 
Do you mean 
Reply
Active Participant
Timmar
Posts: 337

Programatic Access to network published shared variable - Knowlege Nugget

Wanted to Share a coding problem I have just resolved:

 

Proframatic Shared.png

 

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.

 

iTm - Senior Systems Engineer
uses: LABVIEW 2012 SP1 x86 on Windows 7 x64. cFP, cRIO, PXI-RT
Trusted Enthusiast
P@Anand
Posts: 2,318
0 Kudos

Re: Programatic Access to network published shared variable - Knowlege Nugget

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

-----

The best solution is the one you find it by yourself
Proven Zealot
crossrulz
Posts: 8,588
0 Kudos

Re: Programatic Access to network published shared variable - Knowlege Nugget

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.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Knight of NI
Knight of NI
Ben
Posts: 16,143
0 Kudos

Re: Programatic Access to network published shared variable - Knowlege Nugget

Since I don't use shared varibales I have to ask...

 

Is there a timestamp returned that reveals the state of the variable?

 

Ben

Ben Rayner
Who is NOT John Galt... yet... just building Rayner's Ridge
Scheduled to close on the new ridge next week!
Active Participant
Timmar
Posts: 337
0 Kudos

Re: Programatic Access to network published shared variable - Knowlege Nugget

Ben

 

I didn't look at the timestamp but it throws an error.

iTm - Senior Systems Engineer
uses: LABVIEW 2012 SP1 x86 on Windows 7 x64. cFP, cRIO, PXI-RT
Active Participant
Timmar
Posts: 337
0 Kudos

Re: Programatic Access to network published shared variable - Knowlege Nugget

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?

 

iTm - Senior Systems Engineer
uses: LABVIEW 2012 SP1 x86 on Windows 7 x64. cFP, cRIO, PXI-RT
Active Participant
Timmar
Posts: 337
0 Kudos

Re: Programatic Access to network published shared variable - Knowlege Nugget

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!

iTm - Senior Systems Engineer
uses: LABVIEW 2012 SP1 x86 on Windows 7 x64. cFP, cRIO, PXI-RT
Proven Zealot
crossrulz
Posts: 8,588
0 Kudos

Re: Programatic Access to network published shared variable - Knowlege Nugget


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.

 



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Active Participant
Timmar
Posts: 337
0 Kudos

Re: Programatic Access to network published shared variable - Knowlege Nugget

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.

iTm - Senior Systems Engineer
uses: LABVIEW 2012 SP1 x86 on Windows 7 x64. cFP, cRIO, PXI-RT
Trusted Enthusiast
Wayne.C
Posts: 2,016

Re: Programatic Access to network published shared variable - Knowlege Nugget

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.