Do trivial client read/writes exist? #746
-
Very new to opc and python-opc. Have some lab equipment that is working great, but would like to script some behaviors with python. For my application, simplicity for users is the most important thing. But to get this, I had to write an (albeit small) helper class. I was just wondering if I had missed something, and there was an easier way to do this with Of course, if I have made some other unwise assumptions in my code below, please advise :) We have only a single PLC-like thing hosting a single OPC server with only a few hundred tags, if that context is relevant. from asyncua.sync import Client
class MyClient(Client):
@staticmethod
def _qualified_name(tag):
return [f'0:{n}' for n in tag.split('/')]
def read_tag(self, tag):
qname = self._qualified_name(tag)
return opc.nodes.objects.get_child(qname).read_value()
def write_tag(self, tag, value):
qname = self._qualified_name(tag)
opc.nodes.objects.get_child(qname).write_value(value)
### USER CODE STARTS HERE ###
### is there a way to not need the above code at all?
with MyClient('opc.tcp://192.168.1.2:12345/') as opc:
opc.write_tag('magnets/magnet_10/current_setpoint_in_amps', 1.28)
print(opc.read_tag('magnets/magnet_10/current_setpoint_in_amps')) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
First you should make your user understand this is us. Not the old OPC. Tags do not exists. They are nodes |
Beta Was this translation helpful? Give feedback.
-
And yes ua uses namespaces If you remove them you will probably get an issue at some point |
Beta Was this translation helpful? Give feedback.
-
But you are using the API correctly. |
Beta Was this translation helpful? Give feedback.
But you are using the API correctly.
I would tell the users to write something like
Client.nodes.objects.get_child(["2:xxx", 3:CCC",3:xxx"].read_value(). It is not that bad and is correct