LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DataSocket Read -- from OPC cache or from PLC?

Solved!
Go to solution

Hi all,

 

I would be grateful for some further understanding of exactly how the "DataSocket Read" function works.

 

I am using a PLC from Automation Direct (KEPDirect).  I've attached the VI I use to open communication with the PLC, and the VI I use to read some of the parameters from the PLC (I have them grouped according to datatype -- the one I've posted is the one I use to read numeric values).  I find that, for the most part, all of the communications work very nicely.

 

Occasionally, however, I find that successive executions of my Read subVI return identical numbers -- down to 9 decimal places.  This is completely unreasonable given that the PLC data is obtained from 2 different devices -- I KNOW that the two meters on the calibration bench do NOT have identical K factors.

 

There are two places from which the PLC data can be obtained:  the OPC server cache and the PLC itself.  The OPCDataAccess Automation Standard I have states the following for OPCItemRead:

 

    Read

Description
Read makes a blocking call to read this item from the server.
Read can be called with only a source (either OPCCache or OPCDevice) to refresh the item’s value, quality and timestamp properties. If the value, quality and timestamp must be in sync, this method’s optional parameters return values that were acquired together.
Syntax
 Read (Source As Integer, Optional ByRef Value As Variant, Optional ByRef Quality As Variant, Optional ByRef TimeStamp As Variant)
 
Part
Description
Source
The ‘data source’; OPC_DS_CACHE or OPC_DS_DEVICE
Value
Returns the latest value read from the server
Quality
Returns the latest value read from the server
TimeStamp
Returns the latest timestamp read from the server.

 

I wish to ensure that I am reading directly from the device and not from the cache, as I postulate that the reason for the occasional return of identical K values is that the cache isn't being updated before my code reads the next K value.  The DataSocket Read function provided by LabVIEW does not seem to allow me to set this parameter.  So, what goes on inside DataSocket Read?  The LabVIEW help for that function states:

 

"Dequeues the next available data value from the client-side buffer associated with the connection you specify in connection in and returns the data."

 

This would perhaps imply that LabVIEW reads from the OPC cache and not the PLC?

 

Would someone please assist my understanding here?  If the DataSocket Read function does indeed read from the OPC cache and not the PLC, is there any way to force a read directly from the PLC?

 

Thank you!

Diane

 

Download All
0 Kudos
Message 1 of 6
(4,367 Views)

Hello Diane,

 

it is my understanding that when you use OPC servers, you are binding a shared variable to a tag that reads a value directly from the PLC. You may take a look to the links below they may help you..

 

Connect LabVIEW to Any PLC Using OPC

 

Connecting LabVIEW to an OPC Server through a DataSocket Connection

 

 

Regards

 

Mart G

0 Kudos
Message 2 of 6
(4,324 Views)

Thanks for the reply, but I'm afraid that neither link expanded my knowledge or answered my question.  Did you look at the code I posted?  It's pretty much the same as that shown in the opc example referenced in the second link.  I'm not asking how to set up and read from the tags.  I am asking what, exactly, is the format of the read command sent by "DataSocket Read".  One cannot open that function and view its block diagram, so I have no idea how it's formatting the read command.  What syntax is it using? 

 

I'm not using the DSC Module, so the first link isn't much help either.

 

If possible, can someone tell me precisely what "DataSocket Read" is doing under the hood?  How does it format the read command?  Does it specify a source (i.e. cache or PLC), as shown in the standard I posted?  If not, then it's probably using whatever the default source is, in which case I'll probably have to write a driver myself. 

 

The results I'm receiving would indicate that it reads from the cache, not the device directly, as I am occasionally receiving identical read values for two different tags ("Kfactor" and "Kfactor2"), which are read in succession.  The data sources for those two tags are different:  "Kfactor" is calculated from the pulse data coming from meter 1, and "Kfactor 2" is calculated from the pulse data coming from meter 2.  Each meter's pulse data comes into the PLC on its own channel.  It's difficult to imagine a scenario where, occasionally, the PLC would just up and decide to use the meter1 data source to calculate the meter2 Kfactor.  The thing about code is that it doesn't suddenly and randomly decide to change the way it executes.  It executes the same way every time.

 

It is much more likely that the PLC uses the meter1 data to calculate Kfactor and writes it to the OPC cache, then uses the meter2 pulse data to calculate Kfactor2 and writes that to the cache.  If DataSocket Read is grabbing data from the OPC cache, one can envision a situation where the second call to DataSocket Read executes before the cache value has been updated, thus grabbing a stale value.

 

I do appreciate your response, but I'm not a beginner and I need something a bit more in-depth.

 

Thank you!

0 Kudos
Message 3 of 6
(4,315 Views)
Solution
Accepted by topic author DianeS

Hello Diane,

 

After doing a deeper reasearch I can tell you that the Data Socket Read VI can read only from the OPC server there is no way to read the PLC directly using Data Socket, the OPC server has to be used as a mid point between both clients ( LabVIEW and the PLC).

 

Regards

 

Mart G

Message 4 of 6
(4,281 Views)

Hi Mart,

 

Thank you very much for your answer...that is precisely what I needed to know.  I really appreciate your digging deeper to find that out for me.  I hope it will help others as well!

 

Diane

0 Kudos
Message 5 of 6
(4,276 Views)

Hello Diane,

 

You are very welcome, Smiley Wink

 

Regards,

 

Mart G

0 Kudos
Message 6 of 6
(4,274 Views)