I'm trying to manage the Quality Status of the tags in my opcua server but I could not find the way to set the StatusCode properly. Find here a snippet of my code. I'm reading the server tag thanks to a standard and free client named Integration Objects.
import sys
sys.path.insert(0, "..")
import time
from opcua import ua, Server
server = Server()
server.set_endpoint("opc.tcp://0.0.0.0:4841/freeopcua/server/")
uri = "http://examples.freeopcua.github.io"
idx = server.register_namespace(uri)
objects = server.get_objects_node()
myobj = objects.add_object(idx, "MyObject")
myvar = myobj.add_variable(idx, "MyVariable", 6.7)
myvar.set_writable() # Set MyVariable to be writable by clients
server.start()
try:
count = 0
while True:
time.sleep(1)
count += 0.1
myvar.set_data_value(count)
# here I'd like to set programmatically the StatusCode of myvar variable
print(myvar.get_value())
print("\n")
except Exception as e:
print('\nOPC failed:', str(e))
input("...fine errore...")
finally:
server.stop()