Search code examples
pythonhandlersubscriptionopc-ua

OPC UA Client Subscription Handler


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?


Solution

  • 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)