LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

first value read by datasocket read vi is wrong

Hi,

I am using datasocket to communicate with OPCservers to a PLC (a micrologix over DF1). I find that the first value read from the server using the read vi is always zero regardless of what the current value is. Subsequent calls to the read vi work fine. Furthermore, the read vi doesn't report any error or timeout, although it does report '0' for the quality. Does any one know why this might be? Is this a setting in the OPCserver? A bug in the read vi? Some other issue?

(some details: I've used the open vi with the URL, and passed the connection to the read vi. All optional inputs on the read vi are left default. Labview 8.1, Windows XP)
0 Kudos
Message 1 of 4
(3,597 Views)

Hi Steve,

It sounds like you are seeing the behavior discussed here.  The first DataSocket Read returns the default value of 0.  As you have seen, actual values from the OPC server are read after that.  To avoid this, ignore the first value that is returned. 

Jennifer R.
National Instruments
Applications Engineer
0 Kudos
Message 2 of 4
(3,562 Views)
Thanks for the link. Thats exactly the behaviour I see. I had toyed with the idea of just putting a delay in to allow the value to update (once the server has updated its read values, the first datasocket read does give the correct updated value), but I guess putting a read with 'wait for updated value' and discarding this is probably a more robust way of ensuring the correct value is read - either that or monitoring the 'quality' flag as well as 'timeout' and 'error'.....

As an aside, does this behaviour mean that the datasocket read will always return the default (incorrect) value if wired with a URL (not a datasocket connection) and 'wait for updated value' false??? I have an idea I have seen this when testing some concepts earlier. Now I know why.

S

0 Kudos
Message 3 of 4
(3,556 Views)

Hi Steve, 

I tested two and three sequential DataSocket Reads with a URL pointing to NI OPC Server.  The first read always returned a default 0.  The remaining reads were dependent on "wait for updated value" and the timeout.  In general, setting "wait for updated value" to false returned 0 with a quality of 0, although once or twice the value was actually correct.  The same is true if the timeout period does not allow enough time for the value to update. 

To ensure you are reading valid data, it is best to use one of the methods you mentioned. 

Jennifer R.
National Instruments
Applications Engineer
0 Kudos
Message 4 of 4
(3,534 Views)