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
8d8edbd6
Commit
8d8edbd6
authored
Oct 25, 2021
by
oroulet
Committed by
oroulet
Oct 25, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correct vtype_to_argument to suport Node and NodeId and enums
parent
a69566c5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
2 deletions
+36
-2
asyncua/common/manage_nodes.py
asyncua/common/manage_nodes.py
+10
-1
tests/test_common.py
tests/test_common.py
+26
-1
No files found.
asyncua/common/manage_nodes.py
View file @
8d8edbd6
...
...
@@ -2,6 +2,9 @@
High level functions to create nodes
"""
import
logging
from
enum
import
Enum
import
inspect
from
asyncua
import
ua
from
.instantiate_util
import
instantiate
from
.node_factory
import
make_node
...
...
@@ -425,9 +428,15 @@ def _vtype_to_argument(vtype):
arg
=
ua
.
Argument
()
if
hasattr
(
vtype
,
"data_type"
):
arg
.
DataType
=
vtype
.
data_type
elif
inspect
.
isclass
(
vtype
)
and
issubclass
(
vtype
,
Enum
):
arg
.
DataType
=
ua
.
enums_datatypes
[
vtype
]
elif
isinstance
(
vtype
,
ua
.
VariantType
):
arg
.
DataType
=
ua
.
NodeId
(
vtype
.
value
)
elif
hasattr
(
ua
.
VariantType
,
vtype
.
__name__
):
elif
isinstance
(
vtype
,
ua
.
NodeId
):
arg
.
DataType
=
vtype
elif
hasattr
(
vtype
,
"nodeid"
):
# NodeId case but we cannot import Node object here
arg
.
DataType
=
vtype
.
nodeid
elif
hasattr
(
vtype
,
"__name__"
)
and
hasattr
(
ua
.
VariantType
,
vtype
.
__name__
):
arg
.
DataType
=
ua
.
NodeId
(
ua
.
VariantType
[
vtype
.
__name__
].
value
)
else
:
arg
.
DataType
=
ua
.
NodeId
(
vtype
)
...
...
tests/test_common.py
View file @
8d8edbd6
...
...
@@ -1405,7 +1405,7 @@ async def test_custom_method_with_struct(opc):
ua
.
NodeId
(
"ServerMethodWithStruct"
,
10
),
ua
.
QualifiedName
(
'ServerMethodWithStruct'
,
10
),
func
,
[
ua
.
MyStructArg
],
[
ua
.
MyStructArg
]
)
)
mystruct
=
ua
.
MyStructArg
()
mystruct
.
MyUInt32
=
[
78
,
79
]
...
...
@@ -1415,3 +1415,28 @@ async def test_custom_method_with_struct(opc):
result
=
await
opc
.
opc
.
nodes
.
objects
.
call_method
(
methodid
,
mystruct
)
assert
result
.
MyUInt32
==
[
78
,
79
,
100
]
async
def
test_custom_method_with_enum
(
opc
):
idx
=
4
enum_node
=
await
new_enum
(
opc
.
opc
,
idx
,
"MyCustEnumForMethod"
,
[
"titi"
,
"toto"
,
])
await
opc
.
opc
.
load_data_type_definitions
()
@
uamethod
def
func
(
parent
,
myenum1
,
myenum2
,
myenum3
):
assert
myenum1
==
ua
.
MyCustEnumForMethod
.
titi
return
ua
.
MyCustEnumForMethod
.
toto
methodid
=
await
opc
.
server
.
nodes
.
objects
.
add_method
(
ua
.
NodeId
(
"servermethodwithenum"
,
10
),
ua
.
QualifiedName
(
'servermethodwithenum'
,
10
),
func
,
[
ua
.
MyCustEnumForMethod
,
enum_node
,
enum_node
.
nodeid
],
[
ua
.
MyCustEnumForMethod
]
)
result
=
await
opc
.
opc
.
nodes
.
objects
.
call_method
(
methodid
,
ua
.
MyCustEnumForMethod
.
titi
,
ua
.
MyCustEnumForMethod
.
titi
,
ua
.
MyCustEnumForMethod
.
titi
)
assert
result
==
ua
.
MyCustEnumForMethod
.
toto
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