pythonopc-uaopc

Write array with opcua


everyone!

I need to write a variable as an array (list) to the OPC server. I am using Python and Python OPC-UA. In the picture you can see the name and structure of the variable where I am trying to write the data.

opc-image

I try to use this code and get an error

    q = [0]*50
    data = client.get_node(f'ns=3;s="OSC_Profile"."THIS"')
    dv = ua.Variant(q, ua.VariantType.ExtensionObject)
    data.set_value(dv)
KeyError                                  Traceback (most recent call last)
Input In [18], in <cell line: 9>()
     20     dv = ua.Variant(q, ua.VariantType.ExtensionObject)
---> 21     data.set_value(dv)

KeyError: 'int'

I would be glad if someone could suggest the right way


Solution

  • Ok you have a custom datatype so you have to create the corresponding class:

    q = [ua.OSC(...), ua.OSC(...), ...]
    data.set_value(ua.Variant(q, ua.VariantType.ExtensionObject))