0

I am creating an application that writes data to opcserver using python. I have a client side and a server side. The server side starts the server in the background and creates the necessary object, as well as adds variables into said object.

SERVER SIDE:

def create_object(self):
objects = self.server.get_objects_node()
active_object = objects.add_object(self.idx, "object_name")
return active_object

def add_variables_to_object(self, active_object, input):  
    # BREAK UP THE CLUSTER
    for name, value in input_cluster:
        myvar = active_object.add_variable(self.idx, name, value)
        myvar.set_writable()

CLIENTSIDE:

 def write_to_variables(self, variables_values): 
     try:
        for name, value in variables_values:
            node = self.client.get_node(ua.NodeId(name, self.idx))
            node.set_value(value)
            print('Write succeeded')
     except Exception as e:
        print("Failed to write: ", e)

I am having trouble with writing to these tags to the OPC Server. As you can see I am receiving the node using the namespace index, as well as the string name of the variable. I then call the function, set_value.

Now running this, ALL the values are written to the OPC server, however there is an error that prevents the print('Write succeeded') from being output because the program crashes before then:

TypeError: unsupported operand type(s) for &: 'NoneType' and 'int'

Here is the stack trace:

  File "c:\PROJECTS\main.py", line 20, in main
    active_client.write_to_variables(input_cluster)

  File "c:\PROJECTS\client.py", line 28, in write_to_variables
    node.set_value(value)

  File "C:\AppData\Local\Programs\Python\Python39\lib\site-packages\opcua\common\node.py", line 217, in set_value
    self.set_attribute(ua.AttributeIds.Value, datavalue)
  File "C:\AppData\Local\Programs\Python\Python39\lib\site-packages\opcua\common\node.py", line 262, in set_attribute
    result = self.server.write(params)

  File "C:\AppData\Local\Programs\Python\Python39\lib\site-packages\opcua\client\ua_client.py", line 367, in write
    data = self._uasocket.send_request(request)

  File "C:\AppData\Local\Programs\Python\Python39\lib\site-packages\opcua\client\ua_client.py", line 83, in send_request
    data = future.result(self.timeout)

  File "C:\AppData\Local\Programs\Python\Python39\lib\concurrent\futures\_base.py", line 442, in result
    raise TimeoutError()

concurrent.futures._base.TimeoutError

The issue is coming when server.write is called, possibly due to improperly set params. Does value need to be formatted correctly as a ua.DataValue object?

MG7702
  • 17
  • 3
  • No body can guess your problem, if you don't post example values of value. Maybe there are None or something? Maybe also add a stacktrace (Remove the try except) – Schroeder Jul 20 '23 at 06:51
  • Post a [mre] with debugging details. The error means it tried something like ```None & 1```. – relent95 Jul 20 '23 at 07:56
  • The values are Int64. I have added the stack trace as well. The issue may be stemming from params. I have tried this forum in an attempt to format the datavalue correctly (https://stackoverflow.com/questions/63038634/write-a-value-with-opc-ua-python) and still receive the same issue. – MG7702 Jul 20 '23 at 13:23

0 Answers0