client_to_prosys_events.py
Go to the documentation of this file.
1 import sys
2 sys.path.insert(0, "..")
3 import logging
4 
5 from opcua import Client
6 from opcua import ua
7 from IPython import embed
8 
9 
10 class SubHandler(object):
11 
12  """
13  Subscription Handler. To receive events from server for a subscription
14  """
15 
16  def datachange_notification(self, node, val, data):
17  print("Python: New data change event", node, val)
18 
19  def event_notification(self, event):
20  print("Python: New event", event.EventType)
21 
22 
23 
24 
25 if __name__ == "__main__":
26  #from IPython import embed
27  logging.basicConfig(level=logging.WARN)
28  client = Client("opc.tcp://localhost:53530/OPCUA/SimulationServer/")
29  #client = Client("opc.tcp://olivier:olivierpass@localhost:53530/OPCUA/SimulationServer/")
30  try:
31  client.connect()
32  root = client.get_root_node()
33  print("Root is", root)
34 
35  handler = SubHandler()
36  sub = client.create_subscription(500, handler)
37  handle = sub.subscribe_events(evtype=2788)
38  # refresh server condition to force generation of events
39  cond = root.get_child(["0:Types", "0:EventTypes", "0:BaseEventType", "0:ConditionType"])
40  cond.call_method("0:ConditionRefresh", ua.Variant(sub.subscription_id, ua.VariantType.UInt32))
41 
42  embed()
43  finally:
44  client.disconnect()
def datachange_notification(self, node, val, data)


ros_opcua_impl_python_opcua
Author(s): Denis Štogl , Daniel Draper
autogenerated on Tue Jan 19 2021 03:12:43