2 sys.path.insert(0,
"..")
7 from IPython
import embed
14 shell = code.InteractiveConsole(vars)
18 from opcua
import Client
25 Subscription Handler. To receive events from server for a subscription 26 data_change and event methods are called directly from receiving thread. 27 Do not do expensive, slow or network operation there. Create another 28 thread if you need to do such a thing 32 print(
"Python: New data change event", node, val)
35 print(
"Python: New event", event)
38 if __name__ ==
"__main__":
39 logging.basicConfig(level=logging.WARN)
43 client = Client(
"opc.tcp://localhost:4840/freeopcua/server/")
49 root = client.get_root_node()
50 print(
"Root node is: ", root)
51 objects = client.get_objects_node()
52 print(
"Objects node is: ", objects)
55 print(
"Children of root are: ", root.get_children())
67 myvar = root.get_child([
"0:Objects",
"2:MyObject",
"2:MyVariable"])
68 obj = root.get_child([
"0:Objects",
"2:MyObject"])
69 print(
"myvar is: ", myvar)
73 sub = client.create_subscription(500, handler)
74 handle = sub.subscribe_data_change(myvar)
78 sub.subscribe_events()
83 res = obj.call_method(
"2:multiply", 3,
"klk")
84 print(
"method result is: ", res)
def event_notification(self, event)
def datachange_notification(self, node, val, data)