|
Obtaining Information from an OPC DA server
In OPC Data Access, reading data from OPC items is one of the most common tasks. The OPC server generally provides current data for any OPC item in form of a Value, Timestamp and Quality combination (VTQ).
If you want to read the current VTQ from a specific OPC item, call the ReadItem method. You can pass individual arguments for machine name, server class, ItemID, and an optional data type. You will receive back a DAVtq object holding the current value, timestamp, and quality of the OPC item. The ReadItem method returns the current VTQ, regardless of the quality. You may receive an Uncertain or even Bad quality (and no usable data value), and your code needs to deal with such situations accordingly.
NOTE: OPCData.NET users you can also pass in the ServerDescriptor and DAItemDescriptor objects to the ReadItem call.
For reading VTQs of multiple items simultaneously in an efficient manner, call the ReadMultipleItems method (instead of multiple ReadItem calls in a loop).
OPCData-Com users can pass in an array of values in place of each ReadItem argument, or (if the value is the same for the whole operation, e.g. the machine name), a single value as with the ReadItem call. You will receive back an array of DAVtqResult objects.
OPCData.NET users you can pass in a ServerDescriptor object and an array of DAItemDescriptor objects, or an array of DAItemArguments objects. You will receive back an array of DAVtqResult objects.
Some applications need the actual data value for further processing (e.g. for computations that need be performed on the values), even if it involves waiting a little for the quality to become Good. For such usage, call the ReadItemValue method, passing it the same arguments as to the ReadItem method. The method will wait until the OPC item’s quality becomes Good (or until a timeout expires), and you will receive back an Object holding the actual data value.
For reading just the data values of multiple data values (while waiting for Good quality) in an efficient manner, call the ReadMultipleItemValues method (instead of multiple ReadItemValue calls in a loop).
OPCData-COM users can pass in an array of values, or (if the value is the same for the whole operation, e.g. the machine name), a single value as with the ReadItemValue call. You will receive back an array of ValueResult objects.
OPCData.NET users you can pass in a ServerDescriptor object and an array of DAItemDescriptor objects, or an array of DAItemArguments objects. You will receive back an array of ValueResult objects.
NOTE: You can set the DesiredValueAge in the ClientMode property to control how “old” may be the values you receive by reading from OPC items. Be aware that it is physically impossible for any system to always obtain fully up-to-date values.
Obtaining Information from an OPC A&E server
In OPC Alarms and Events, information is usually provided in form of event notifications, especially for transient (simple and tracking) events. For condition-related events, however, it is also possible to get (upon request) information about the current state of a specified condition.
If you want to obtain the current state information for the condition instance in an OPC Alarms and Events sever, call the GetConditionState method. You pass in individual arguments for machine name, server class, fully qualified source name, condition name, and optionally an array of event attributes to be returned. Alternatively, you can pass in a ServerDescriptor in place of machine name and server class arguments. You will receive back an AEConditionState object holding the current state information about an OPC condition instance.
View code samples here
|