def create_subscription(self, period, handler): """ Create a subscription. returns a Subscription object which allow to subscribe to events or data on server handler argument is a class with data_change and/or event methods. period argument is either a publishing interval in milliseconds or a CreateSubscriptionParameters instance. The second option should be used, if the opcua-server has problems with the default options. These methods will be called when notfication from server are received. See example-client.py. Do not do expensive/slow or network operation from these methods since they are called directly from receiving thread. This is a design choice, start another thread if you need to do such a thing. """ if isinstance(period, ua.CreateSubscriptionParameters): return Subscription(self.uaclient, period, handler) params = ua.CreateSubscriptionParameters() params.RequestedPublishingInterval = period params.RequestedLifetimeCount = 10000 params.RequestedMaxKeepAliveCount = 3000 params.MaxNotificationsPerPublish = 10000 params.PublishingEnabled = True params.Priority = 0 return Subscription(self.uaclient, params, handler)
def create_subscription(self): try: #if not self._datachange_sub: params = ua.CreateSubscriptionParameters() params.RequestedPublishingInterval = self.pub_interval params.RequestedLifetimeCount = self.lifetime_count params.RequestedMaxKeepAliveCount = self.max_keep_alive_count params.MaxNotificationsPerPublish = self.max_notifications_per_publish params.PublishingEnabled = True params.Priority = self.priority sub = Subscription(self.window.client.uaclient, params, self._subhandler) self._datachange_sub[sub.subscription_id] = sub self.model.setHorizontalHeaderLabels( ["Subscription Id", "Publishing Interval"]) row = [ QStandardItem(str(sub.subscription_id)), QStandardItem(str(sub.parameters.RequestedPublishingInterval)) ] row[0].setData(sub) self.model.appendRow(row) except Exception as ex: self.window.log_window.ui.logTextEdit.append(str(ex)) raise
def subscribe(self, monitored_nodes, sub_infos): #Create the handlers handler = [] for i in range(len(sub_infos)): handler.append(SubHandler(self.AggrObject, self.handle_dict)) #Creating a subscription for ech 'sub_infos' element in the config file (different types of subscriptions -> different parameters) sub = [] sub_index_list = [] for i in range(len(monitored_nodes)): sub_index_list.append(monitored_nodes[i]["subIndex"]) for i in range(len(sub_infos)): if(i in sub_index_list): #Set sub parameters params = ua.CreateSubscriptionParameters() params.RequestedPublishingInterval = sub_infos[i]['requested_publish_interval'] params.RequestedLifetimeCount = sub_infos[i]['requested_lifetime_count'] params.RequestedMaxKeepAliveCount = sub_infos[i]['requested_max_keepalive_timer'] params.MaxNotificationsPerPublish = sub_infos[i]['max_notif_per_publish'] params.PublishingEnabled = sub_infos[i]['publishing_enabled'] params.Priority = sub_infos[i]['priority'] #Create the subscription sub.append(self.client.create_subscription(params, handler[i])) #handle will contains mon_item_ids handle = [] Aggr_key = [] for key in self.handle_dict: Aggr_key.append(key) for i in range(len(monitored_nodes)): filter = self.set_datachange_filter(monitored_nodes[i]['deadbandval'], monitored_nodes[i]['deadbandtype']) #Set filter from config parameters setted in the config file handle.append(self.create_monitored_item(sub[monitored_nodes[i]['subIndex']], self.client.get_node(monitored_nodes[i]['nodeTomonitor']), monitored_nodes[i]['sampling_interval'] ,self.handle_dict[Aggr_key[i]], filter, monitored_nodes[i]['queue_size'], monitored_nodes[i]['discard_oldest'])) #handle = list of monitored items ids #handler.datachange_notification is called when a value of the monitored nodes has changed return sub, handle
def _create_subscription(self, handler): params = ua.CreateSubscriptionParameters() params.RequestedPublishingInterval = 10 params.RequestedLifetimeCount = 3000 params.RequestedMaxKeepAliveCount = 10000 params.MaxNotificationsPerPublish = 0 params.PublishingEnabled = True params.Priority = 0 return Subscription(self.iserver.isession, params, handler)
def create_subscription(self, handler): # Set subscription parameters params = ua.CreateSubscriptionParameters() params.PublishingEnabled = self.publishingEnabled params.RequestedPublishingInterval = self.requestedPublishingInterval params.RequestedMaxKeepAliveCount = self.requestedMaxKeepAliveCount params.RequestedLifetimeCount = self.requestedLifetimeCount params.MaxNotificationsPerPublish = self.maxNotificationsPerPublish params.Priority = self.priority datachange_sub = self.client.create_subscription(params, handler) self._datachange_subs.append((datachange_sub, {})) self.publishingIntervals.append(self.requestedPublishingInterval)
def create_subscription(self, period, handler): """ Create a subscription. returns a Subscription object which allow to subscribe to events or data on server """ params = ua.CreateSubscriptionParameters() params.RequestedPublishingInterval = period params.RequestedLifetimeCount = 3000 params.RequestedMaxKeepAliveCount = 10000 params.MaxNotificationsPerPublish = 0 params.PublishingEnabled = True params.Priority = 0 return Subscription(self.iserver.isession, params, handler)
def create_subscription(self, period, handler): """ Create a subscription. returns a Subscription object which allow to subscribe to events or data on server period is in milliseconds handler is a python object with following methods: def datachange_notification(self, node, val, data): def event_notification(self, event): def status_change_notification(self, status): """ params = ua.CreateSubscriptionParameters() params.RequestedPublishingInterval = period params.RequestedLifetimeCount = 3000 params.RequestedMaxKeepAliveCount = 10000 params.MaxNotificationsPerPublish = 0 params.PublishingEnabled = True params.Priority = 0 return Subscription(self.iserver.isession, params, handler)