Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
opcua-asyncio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nikola Balog
opcua-asyncio
Commits
eb47c62c
Commit
eb47c62c
authored
Dec 16, 2023
by
Olivier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make get_child use realtive path from spec as default, update examples
parent
d9d360ea
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
20 deletions
+26
-20
asyncua/common/node.py
asyncua/common/node.py
+16
-10
examples/client-example.py
examples/client-example.py
+2
-2
examples/client-minimal.py
examples/client-minimal.py
+1
-1
examples/client-subscription.py
examples/client-subscription.py
+1
-1
tests/test_common.py
tests/test_common.py
+6
-6
No files found.
asyncua/common/node.py
View file @
eb47c62c
...
...
@@ -574,14 +574,17 @@ class Node:
"""
get a child specified by its path from this node.
A path might be:
* a string representing a
qualified name.
* a string representing a
relative path as per UA spec
* a qualified name
* a list of string
* a list of string
representing browsenames (legacy)
* a list of qualified names
"""
if
isinstance
(
path
,
(
ua
.
QualifiedName
,
str
)):
path
=
[
path
]
rpath
=
self
.
_make_relative_path
(
path
)
if
isinstance
(
path
,
str
):
rpath
=
ua
.
RelativePath
.
from_string
(
path
)
else
:
if
isinstance
(
path
,
ua
.
QualifiedName
):
path
=
[
path
]
rpath
=
self
.
_make_relative_path
(
path
)
bpath
=
ua
.
BrowsePath
()
bpath
.
StartingNode
=
self
.
nodeid
bpath
.
RelativePath
=
rpath
...
...
@@ -600,16 +603,19 @@ class Node:
"""
get children specified by their paths from this node.
A path might be:
* a string representing a
qualified name.
* a string representing a
relative path as per UA spec
* a qualified name
* a list of string
* a list of string
representing browsenames (legacy)
* a list of qualified names
"""
bpaths
:
List
[
ua
.
BrowsePath
]
=
[]
for
path
in
paths
:
if
isinstance
(
path
,
(
ua
.
QualifiedName
,
str
)):
path
=
[
path
]
rpath
=
self
.
_make_relative_path
(
path
)
if
isinstance
(
path
,
str
):
rpath
=
ua
.
RelativePath
.
from_string
(
path
)
else
:
if
isinstance
(
path
,
(
ua
.
QualifiedName
,
str
)):
path
=
[
path
]
rpath
=
self
.
_make_relative_path
(
path
)
bpath
=
ua
.
BrowsePath
()
bpath
.
StartingNode
=
self
.
nodeid
bpath
.
RelativePath
=
rpath
...
...
examples/client-example.py
View file @
eb47c62c
...
...
@@ -44,8 +44,8 @@ async def main():
#await var.write_value(3.9) # set node value using implicit data type
# Now getting a variable node using its browse path
myvar
=
await
client
.
nodes
.
root
.
get_child
(
[
"0:Objects"
,
"2:MyObject"
,
"2:MyVariable"
]
)
obj
=
await
client
.
nodes
.
root
.
get_child
(
[
"0:Objects"
,
"2:MyObject"
]
)
myvar
=
await
client
.
nodes
.
root
.
get_child
(
"/Objects/2:MyObject/2:MyVariable"
)
obj
=
await
client
.
nodes
.
root
.
get_child
(
"Objects/2:MyObject"
)
_logger
.
info
(
"myvar is: %r"
,
myvar
)
# subscribing to a variable node
...
...
examples/client-minimal.py
View file @
eb47c62c
...
...
@@ -16,7 +16,7 @@ async def main():
# Get the variable node for read / write
var
=
await
client
.
nodes
.
root
.
get_child
(
[
"0:Objects"
,
f"
{
nsidx
}
:MyObject"
,
f"
{
nsidx
}
:MyVariable"
]
f"0:Objects/
{
nsidx
}
:MyObject/
{
nsidx
}
:MyVariable"
)
value
=
await
var
.
read_value
()
print
(
f"Value of MyVariable (
{
var
}
):
{
value
}
"
)
...
...
examples/client-subscription.py
View file @
eb47c62c
...
...
@@ -30,7 +30,7 @@ async def main():
client
=
Client
(
url
=
'opc.tcp://localhost:4840/freeopcua/server/'
)
async
with
client
:
idx
=
await
client
.
get_namespace_index
(
uri
=
"http://examples.freeopcua.github.io"
)
var
=
await
client
.
nodes
.
objects
.
get_child
(
[
f"
{
idx
}
:MyObject"
,
f"
{
idx
}
:MyVariable"
]
)
var
=
await
client
.
nodes
.
objects
.
get_child
(
f"
{
idx
}
:MyObject/
{
idx
}
:MyVariable"
)
handler
=
SubscriptionHandler
()
# We create a Client Subscription.
subscription
=
await
client
.
create_subscription
(
500
,
handler
)
...
...
tests/test_common.py
View file @
eb47c62c
...
...
@@ -442,8 +442,8 @@ async def test_browse_references(opc):
async
def
test_browsename_with_spaces
(
opc
):
o
=
opc
.
opc
.
nodes
.
objects
v
=
await
o
.
add_variable
(
3
,
"BNVariable with spaces and %
&+?/
"
,
1.3
)
v2
=
await
o
.
get_child
(
"
3:BNVariable with spaces and %&+?/
"
)
v
=
await
o
.
add_variable
(
3
,
"BNVariable with spaces and %
+?
"
,
1.3
)
v2
=
await
o
.
get_child
(
"
/3:BNVariable with spaces and %+?
"
)
assert
v
==
v2
await
opc
.
opc
.
delete_nodes
([
v
])
...
...
@@ -451,7 +451,7 @@ async def test_browsename_with_spaces(opc):
async
def
test_non_existing_path
(
opc
):
root
=
opc
.
opc
.
nodes
.
root
with
pytest
.
raises
(
ua
.
UaStatusCodeError
):
await
root
.
get_child
(
[
"0:Objects"
,
"0:Server"
,
"0:nonexistingnode"
]
)
await
root
.
get_child
(
"0:Objects/0:Server/0:nonexistingnode"
)
async
def
test_bad_attribute
(
opc
):
...
...
@@ -463,7 +463,7 @@ async def test_bad_attribute(opc):
async
def
test_get_node_by_nodeid
(
opc
):
root
=
opc
.
opc
.
nodes
.
root
server_time_node
=
await
root
.
get_child
(
[
"0:Objects"
,
"0:Server"
,
"0:ServerStatus"
,
"0:CurrentTime"
]
"/Objects/Server/ServerStatus.CurrentTime"
)
correct
=
opc
.
opc
.
get_node
(
ua
.
NodeId
(
ua
.
ObjectIds
.
Server_ServerStatus_CurrentTime
))
assert
server_time_node
==
correct
...
...
@@ -657,13 +657,13 @@ async def test_same_browse_name(opc):
o2
=
await
f
.
add_object
(
"ns=2;i=204;"
,
"2:MyBName"
)
v2
=
await
o2
.
add_variable
(
"ns=2;i=205;"
,
"2:MyBNameTarget"
,
2.0
)
nodes
=
await
objects
.
get_child
(
[
"2:MyBNameFolder"
,
"2:MyBName"
,
"2:MyBNameTarget"
]
,
return_all
=
True
"/2:MyBNameFolder/2:MyBName/2:MyBNameTarget"
,
return_all
=
True
)
assert
len
(
nodes
)
==
2
assert
nodes
[
0
]
==
v
assert
nodes
[
1
]
==
v2
[
nodes
]
=
await
objects
.
get_children_by_path
(
[
[
"2:MyBNameFolder"
,
"2:MyBName"
,
"2:MyBNameTarget"
]
]
[
"/2:MyBNameFolder/2:MyBName/2:MyBNameTarget"
]
)
assert
len
(
nodes
)
==
2
assert
nodes
[
0
]
==
v
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment