How to get a value changing on an opc client subscription in a boolean variable

16 Views Asked by At

i am new in python and usually programing Siemens plc. For a new project i have to read values from an opc server on a plc via subscription, store them in a sql data base and make a protocol after finishing the job. The problem for me is the subscription.

In the example which i found i get the value print out on screen after changing, that works so far. See here:

   
class SubHandler(object):
    def datachange_notification(self, node, value, data):
        print("Received Value is: ", value)
        print(value)
       
        

if __name__ == "__main__":
    
    num_node = client.get_node('ns=3;s="OPC_Daten"."Var_Real" ')

        
    handler = SubHandler()
    sub = client.create_subscription(500, handler)
    handle = sub.subscribe_data_change(num_node)
    

But i´d like to store the value in an e.g. global variable or list and also set a boolean variable to True when the value changes. What i could read so far is this probably not a good python style, but for me it is important that it works. How could this be done? Thanks in advance.

0

There are 0 best solutions below