2 sys.path.insert(0,
"..")
6 from opcua
import Client
13 Client to subscription. It will receive events from server 17 print(
"Python: New data change event", node, val)
20 print(
"Python: New event", event)
23 if __name__ ==
"__main__":
25 logging.basicConfig(level=logging.DEBUG)
26 client = Client(
"opc.tcp://localhost:53530/OPCUA/SimulationServer/")
31 root = client.get_root_node()
32 print(
"Root is", root)
33 print(
"childs of root are: ", root.get_children())
34 print(
"name of root is", root.get_browse_name())
35 objects = client.get_objects_node()
36 print(
"childs og objects are: ", objects.get_children())
37 myfloat = client.get_node(
"ns=4;s=Float")
38 mydouble = client.get_node(
"ns=4;s=Double")
39 myint64 = client.get_node(
"ns=4;s=Int64")
40 myuint64 = client.get_node(
"ns=4;s=UInt64")
41 myint32 = client.get_node(
"ns=4;s=Int32")
42 myuint32 = client.get_node(
"ns=4;s=UInt32")
44 var = client.get_node(ua.NodeId(
"Random1", 5))
45 print(
"var is: ", var)
46 print(
"value of var is: ", var.get_value())
47 var.set_value(ua.Variant([23], ua.VariantType.Double))
48 print(
"setting float value")
49 myfloat.set_value(ua.Variant(1.234, ua.VariantType.Float))
50 print(
"reading float value: ", myfloat.get_value())
53 sub = client.create_subscription(500, handler)
54 handle = sub.subscribe_data_change(var)
56 device = objects.get_child([
"2:MyObjects",
"2:MyDevice"])
57 method = device.get_child(
"2:MyMethod")
58 result = device.call_method(method, ua.Variant(
"sin"), ua.Variant(180, ua.VariantType.Double))
59 print(
"Mehtod result is: ", result)
63 sub.unsubscribe(handle)
def event_notification(self, event)
def datachange_notification(self, node, val, data)