1

OPC UA Client Subscription Handler

I have created an OPC UA Server and a Subscription handler on the client side. I am trying to get the node data to be stored into a .csv or .txt file for processing. I am wondering if there us a way to do that?

1 Answers1

0

You can change the Subscription Handler to your likes. A simple text handler would be something like this:

class TextSubscriptionHandler:
    def __init__(self, file):
        self.f = open(file, 'w')

    def datachange_notification(self, node: Node, val, data):
        self.f.write(f'{node}:{val}\n')

handler = TextSubscriptionHandler()
sub = client.create_subscription(500, handler)
Schroeder
  • 749
  • 4
  • 10
  • So I added this class to my code after import but it is still does not generate a file with real time values. – Kashif syed Oct 18 '22 at 17:06
  • Edited the code for more complete example. Also maybe there is a miss understanding how subscriptions work. A datachange notification is only send if a value has changed. If nothing changes no value is send from the server. – Schroeder Oct 19 '22 at 08:35