I want to subscribe to an Object node in Python.
I want to output the values of variable nodes of the object node in datachange_notification. Is it possible?
If there is a way, please let me know.
I tried as below, but the handler does not work properly.
<code>from opcua import Client
client = Client("opc.tcp://1111.1111.1111.1111:1000")
client.connect()
class SubHandler(object):
def datachange_notification(self, node, val, data):
# print client.get_node("ns=2;ABC.T1") # variable node
# print client.get_node("ns=2;ABC.T2") # variable node
# print client.get_node("ns=2;ABC.T3") # variable node
node = client.get_node("ns=2;ABC") # object node
nodes = []
nodes.append(node)
handler = SubHandler()
subscription = client.create_subscription(500, handler)
handle = subscription.subscribe_data_change(nodes)
</code>
<code>from opcua import Client
client = Client("opc.tcp://1111.1111.1111.1111:1000")
client.connect()
class SubHandler(object):
def datachange_notification(self, node, val, data):
# print client.get_node("ns=2;ABC.T1") # variable node
# print client.get_node("ns=2;ABC.T2") # variable node
# print client.get_node("ns=2;ABC.T3") # variable node
node = client.get_node("ns=2;ABC") # object node
nodes = []
nodes.append(node)
handler = SubHandler()
subscription = client.create_subscription(500, handler)
handle = subscription.subscribe_data_change(nodes)
</code>
from opcua import Client
client = Client("opc.tcp://1111.1111.1111.1111:1000")
client.connect()
class SubHandler(object):
def datachange_notification(self, node, val, data):
# print client.get_node("ns=2;ABC.T1") # variable node
# print client.get_node("ns=2;ABC.T2") # variable node
# print client.get_node("ns=2;ABC.T3") # variable node
node = client.get_node("ns=2;ABC") # object node
nodes = []
nodes.append(node)
handler = SubHandler()
subscription = client.create_subscription(500, handler)
handle = subscription.subscribe_data_change(nodes)
New contributor
ms1234 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.