# -*- coding: utf-8 -*- """ Created on Fri Oct 30 09:32:33 2020 @author: black """ from opcua import Client, ua import datetime url = "opc.tcp://192.168.2.113:4048" #url = "opc.tcp://192.168.20.20:4840" client = Client(url) client.session_timeout = 20000 client.connect() print(f"Connected: {url}") node = client.get_node('ns=2;i=2') print("before: ", node.get_value()) value = node.get_value() new_value = value + 10 node.set_value(ua.DataValue(ua.Variant(new_value, ua.VariantType.Int16))) print("after: ", node.get_value()) node = client.get_node('ns=2;i=3') print("before: ", node.get_value()) value = node.get_value() new_value = value + 10 node.set_value(ua.DataValue(ua.Variant(new_value, ua.VariantType.Int16))) print("after: ", node.get_value())
import sys sys.path.insert(0, "..") import logging from IPython import embed from opcua import Client if __name__ == "__main__": logging.basicConfig(level=logging.DEBUG) client = Client("opc.tcp://localhost:53530/OPCUA/SimulationServer/") client.set_security_string( "Basic256Sha256,Sign,certificate-example.der,private-key-example.pem") try: client.application_uri = "urn:example.org:FreeOpcUa:python-opcua" client.secure_channel_timeout = 10000 client.session_timeout = 10000 client.connect() root = client.get_root_node() objects = client.get_objects_node() print("childs og objects are: ", objects.get_children()) embed() finally: client.disconnect()