Main Page
Namespaces
Classes
Files
File List
python-opcua
examples
client-minimal.py
Go to the documentation of this file.
1
import
sys
2
sys.path.insert(0,
".."
)
3
4
5
from
opcua
import
Client
6
7
8
if
__name__ ==
"__main__"
:
9
10
client = Client(
"opc.tcp://localhost:4840/freeopcua/server/"
)
11
# client = Client("opc.tcp://admin@localhost:4840/freeopcua/server/") #connect using a user
12
try
:
13
client.connect()
14
15
# Client has a few methods to get proxy to UA nodes that should always be in address space such as Root or Objects
16
root = client.get_root_node()
17
print(
"Objects node is: "
, root)
18
19
# Node objects have methods to read and write node attributes as well as browse or populate address space
20
print(
"Children of root are: "
, root.get_children())
21
22
# get a specific node knowing its node id
23
#var = client.get_node(ua.NodeId(1002, 2))
24
#var = client.get_node("ns=3;i=2002")
25
#print(var)
26
#var.get_data_value() # get value of node as a DataValue object
27
#var.get_value() # get value of node as a python builtin
28
#var.set_value(ua.Variant([23], ua.VariantType.Int64)) #set node value using explicit data type
29
#var.set_value(3.9) # set node value using implicit data type
30
31
# Now getting a variable node using its browse path
32
myvar = root.get_child([
"0:Objects"
,
"2:MyObject"
,
"2:MyVariable"
])
33
obj = root.get_child([
"0:Objects"
,
"2:MyObject"
])
34
print(
"myvar is: "
, myvar)
35
36
finally
:
37
client.disconnect()
ros_opcua_impl_python_opcua
Author(s): Denis Štogl
, Daniel Draper
autogenerated on Tue Jan 19 2021 03:12:43