SWTB_Banner_Left_LogoOnly

Subscribing

clearpixel

Home Product Details Free Demo Purchasing Support News

SWTB_7Button_BlueLine

Subscribing to an OPC DA Server

Subscription is initiated by calling either SubscribeItem or SubscribeMultipleItems method. For any change in the subscribed item’s value, your application will receive the ItemChanged event notification, described further below. Obviously, you first need to hook up an event handler for that event. In order to prevent event loss, you should do it before subscribing.

Values of some items may be changing quite frequently, and receiving all changes that are generated is not desirable for performance reasons; there are also physical limitations to the event throughput in the system. Your application needs to specify the requested update rate, which effectively tells the OPC server that you do not need to receive event notifications any faster than that. For OPC items that support it, you can optionally specify a percent deadband; only changes that exceed the deadband will generate an event notification. The requested update rate, percent deadband, and data type are all contained in a DAGroupParameters object.

If you want to subscribe to a specific OPC item, call the SubscribeItem method. You can pass in individual arguments for machine name, server class, ItemID, data type, requested update rate, and an optional percent deadband. You can also pass in a State argument. When the item’s value changes the State argument is then passed to the ItemChanged event handler in the EasyDAItemChangedEventArgs object.

NOTE: OPCData.NET users can also pass in ServerDescriptor, DAItemDescriptor and DAGroupParameters objects. For most overloads of the SubscribeItem method, you will be required to pass in the State argument as type Object.

The State argument is typically used to provide some sort of correlation between objects in your application, and the event notifications. For example, if you are programming a Windows Forms application and you want the event handler to update the control that displays the item’s value, you may want to set the State argument to the control object itself. When the event notification arrives, you simply update the control indicated by the State property of EasyDAItemChangedEventArgs, without having to look it up by ItemId.

To subscribe to multiple items simultaneously in an efficient manner, call the SubscribeMultipleItems methods (instead of multiple SubscribeItem calls in a loop).
OPCData-COM users will pass in an array or arrays of arguments (each element containing information for a single subscription to be made), and receive back an array of HandleResult objects (containing the subscription handles).OPCData.NET users will pass in an array of DAItemGroupArguments objects (each containing information for a single subscription to be made), and receive back an array of HandleResult objects (containing the subscription handles).

NOTE: It is NOT an error to subscribe to the same item twice (or more times), even with precisely same parameters. You will receive separate subscription handles, and with regard to your application, this situation will look no different from subscribing to different items. Internally, however, the subscription made to the OPC server will be optimized (merged together) if possible.

Subscribing to an OPC A&E Server

Subscription is initiated by calling the SubscribeEvents method. The component will call handlers for Notification event for each event that satisfies the filter criteria of the created subscription. Obviously, you first need to hook up event handler for that event, and in order to prevent event loss, you should do it before subscribing.

Events may be generated quite rapidly. Your application needs to specify the notification rate, which effectively tells the OPC Alarms and Events server that you do not need to receive event notifications any faster than that.

If you want to subscribe to particular set of OPC Events, call the SubscribeEvents method. You can pass in individual arguments for machine name, server class, and notification rate. Alternatively, you can pass in a ServerDescriptor in place of machine name and server class arguments. Optionally, you can specify a subscription filter; it is a separate object of AESubscriptionFilterType that you create using CreateSubscriptionFilter method. Other optional parameters are attributes that should be returned in event notifications (separate set of attributes for each event category is needed), and the “active” and “refresh when active” flags. These parameters can alternatively be all replaced by passing in an AESubscriptionParameters object. You can also pass in a State argument of any type. When any event notification is generated, the State argument is then passed to the Notification event handler in the EasyAENotificationEventArgs object.

The State argument is typically used to provide some sort of correlation between objects in your application, and the event notifications. For example, if you are programming an HMI application and you want the event handler to update the control that displays the event messages, you may want to set the State argument to the control object itself. When the event notification arrives, you simply update the control indicated by the State property of EasyAENotificationEventArgs, without having to look it up.

The “refresh when active” flag enables a functionality that is useful if you want to keep a “copy” of condition states (that primarily exist in the OPC server) in your application. When this flag is set, the component will automatically perform a subscription Refresh (see further below) after the connection is first time established, and also each time it is reestablished (after a connection loss). This way, the component assures that your code will get notifications that allow you to “reconstruct” the state of event conditions at any given moment.

Note: It is NOT an error to subscribe to the same set of events twice (or more times), even with precisely the same parameters. You will receive separate subscription handles, and with regard to your application, this situation will look no different from subscribing to different set of events.


View code samples here

DkTanLine_600x2  

 

[Home] [Product Details] [Free Demo] [Purchasing] [Support] [News]
 

P: 1-888-665-3678 (US-Sales) or 704-849-2773 (Support & International), F: 704-849-6388
148A East Charles Street, Matthews, North Carolina, USA 28105
Copyright Software Toolbox, Inc., 1996-2011, All Rights Reserved Worldwide.