SyncRead method
Description | Reads the value, quality and timestamp information for one or more items in a group. |
Syntax | SyncRead (Source As Integer, NumItems As Long, ServerHandles() As Long, ByRef Values() As Variant, ByRef Errors() As Long, Optional ByRef Qualities As Variant, Optional ByRef TimeStamps As Variant)Source — The 'data source'; OPC_DS_CACHE or OPC_DS_DEVICE.NumItems — Number of items to be read.ServerHandles — Array containing server handles for the items to be read.Values — Variant containing a variant array of values returned to the client for the specified server handles.Errors — Variant containing an Integer array of errors returned to the client indicating the success/failure of reading the individual item. NOTE a FAILED error code indicates that the corresponding Value, Quality and Time stamp are UNDEFINED.Qualities (optional) — Variant containing an Integer Array of Qualities.TimeStamps (optional) — Variant containing a Date Array of UTC TimeStamps. If the device cannot provide a timestamp, the server will provide one. |
Remarks | The SyncRead operation is a blocking operation, which means the function runs to completion before returning. The data can be read from CACHE in which case the server will return its last read value or the data can be read from the DEVICE in which case an actual read of the physical device is completed before returning a value to the client. When reading from CACHE, the data is only valid if both the group and the item are active. If either the group or the item is inactive, then the Quality will indicate out of service (OPC_QUALITY_OUT_OF_SERVICE). |
Example | Dim lNumitems As Long Dim arHandles() As Long Dim arValues() As Variant Dim arErrors() As Long Dim arQualities() As Variant Dim arTimeStamps() As Variant Dim i As Long '/* Create array of OPCItem Server handles lNumitems = MyOPCGroup.OPCItems.Count ReDim arHandles(1 To lNumitems) For i = 1 To lNumitems arHandles(i) = MyOPCGroup.OPCItems(i).ServerHandle Next 'i '/* Read Group data from Cache MyOPCGroup.SyncRead OPC_DS_CACHE, lNumitems, arHandles, arValues, arErrors, arQualities, arTimeStamps '/* Display the data returned For i = LBound(arValues) To UBound(arValues) If arErrors(i) = 0 Then '/* Update display txtData(MyOPCGroup.OPCItems(i).ClientHandle) = arValues(i) txtQuality(MyOPCGroup.OPCItems(i).ClientHandle) = "Good" End If Next 'i |
Provide Feedback