Open ghost opened 5 years ago
What server are you using?
i wrote a server using opcua like this:
from opcua import Server
server = Server()
url = "opc.tcp://10.0.0.55:4840"
server.set_endpoint(url)
name = "OPCUA_SERVER"
addspace = server.register_namespace(name)
node = server.get_objects_node()
Param = node.add_object(addspace, "Parameters")
Test = Param.add_variable(addspace, "Test", 0)
Test.set_writable()
server.start()
thanks!
I encountered the same problem. Have you found the cause of the problem?
reading and writing nodes works! so please provide more details code snippets and what server type!? variable type please make sure if you create variables to provide a propper variant format otherwise it can make problems because python is dynamicly typed and opcua is strict typed! lg
I used the “python-opcua/examples/server-minimal.py” as a test Server. This is working gut and the function set_value is no problem too. But when i try to write certain values through "client-minimal.py" occurred the Error "concurrent.futures._base.TimeoutError".
The Client lick this import sys sys.path.insert(0, "..")
import time from opcua import ua, Client
if name == "main":
client = Client("opc.tcp://localhost:4845/freeopcua/server/")
# client = Client("opc.tcp://admin@localhost:4840/freeopcua/server/") #connect using a user
try:
client.connect()
# Client has a few methods to get proxy to UA nodes that should always be in address space such as Root or Objects
root = client.get_root_node()
print("Root node is: ", root)
# Node objects have methods to read and write node attributes as well as browse or populate address space
print("Children of root are: ", root.get_children())
# get a specific node knowing its node id
var = client.get_node(ua.NodeId(1, 2))
print(var)
# var = client.get_node("ns=2;i=1")
#print('value', var.get_data_value())# get value of node as a DataValue object
#var.get_value() # get value of node as a python builtin
#var.set_value(ua.Variant([50], ua.VariantType.Double)) #set node value using explicit data type
var.set_value(11) # set node value using implicit data type
# Now getting a variable node using its browse path
myvar = root.get_child(["0:Objects", "2:MyObject", "2:MyVariable"])
obj = root.get_child(["0:Objects", "2:MyObject"])
print("myvar is: ", myvar)
print("myobj is: ", obj)
# Stacked myvar access
print("myvar is: ", root.get_children()[0].get_children()[1].get_variables()[0].get_value())
finally:
client.disconnect()
could you tell me which one causes that? so i can try to reproduce?
This is the Server
import sys sys.path.insert(0, "..") import time
from opcua import ua, Server server = Server() server.set_endpoint("opc.tcp://0.0.0.0:4845/freeopcua/server/") objects = server.get_objects_node() uri = "http://examples.freeopcua.github.io" idx = server.register_namespace(uri)
myobj = objects.add_object(idx, "MyObject") myvar = myobj.add_variable(idx, "MyVariable", 6.7) myvar.set_writable() # Set MyVariable to be writable by clients print(myvar)
server.start() try: count = 0 while True: time.sleep(1) count += 0.1 myvar.set_value(count) finally:
server.stop()
This is the Error:
Traceback (most recent call last):
File "D:/Masterarbeit/program/MA_OPC_UA/OPC_UA_Client.py", line 31, in
Fist of all thank you for your help , I am a newbie, recently I am work with OPCUA and that makes me excited and depressed:)
var = client.get_node(ua.NodeId(1, 2)) <--- is type object and not variable you can only write variables!
you should use uaexpert to check the ids befor try to write them var = client.get_node(ua.NodeId(2, 2))
to simplify you can client.get_node("ns=2;i=2")
Thank you very much, the problem has been resolved. :)))
as a client i try to set the value of a node on my server like this:
On the server "Test" is already set as writeable.
But i always get this error:
somebody may know whats happening here?
thx cheers