使用python语言开发的opcua客户端,可用于跨设备跨平台的工业数据采集
from opcua import Client
class SubHandler(object):
"""
Client to subscription. It will receive events from server
"""
def datachange_notification(self, node, val, data):
#print("Python: New data change event", node, val)
#print("changed. new value is : ", val)
print(val)
# def event_notification(self, event):
# print("Python: New event", event)
# def con():
if __name__ == '__main__':
client = Client("opc.tcp://DESKTOP-JDI248F:53530/OPCUA/SimulationServer/")
client.connect()
client.get_root_node()
aa = client.get_node('ns=3;i=1001')
bb = client.get_node('ns=3;i=1003')
handler = SubHandler()
sub = client.create_subscription(2000, handler)
sub.subscribe_data_change(aa)
sub.subscribe_data_change(bb)
# print(sub.subscribe_data_change(aa))
# print(sub.subscribe_data_change(bb))
# if __name__ == '__main__':
# con()