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
d5c7acb2
Commit
d5c7acb2
authored
Mar 09, 2021
by
oroulet
Committed by
oroulet
Mar 09, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make sure passing structc as method argument works
parent
12c0e7a0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
5 deletions
+49
-5
asyncua/common/manage_nodes.py
asyncua/common/manage_nodes.py
+3
-1
examples/server-data-type-definition.py
examples/server-data-type-definition.py
+3
-3
tests/test_common.py
tests/test_common.py
+32
-0
tests/test_unit.py
tests/test_unit.py
+11
-1
No files found.
asyncua/common/manage_nodes.py
View file @
d5c7acb2
...
...
@@ -422,7 +422,9 @@ def _vtype_to_argument(vtype):
if
isinstance
(
vtype
,
ua
.
Argument
):
return
vtype
arg
=
ua
.
Argument
()
if
isinstance
(
vtype
,
ua
.
VariantType
):
if
hasattr
(
vtype
,
"data_type"
):
arg
.
DataType
=
vtype
.
data_type
elif
isinstance
(
vtype
,
ua
.
VariantType
):
arg
.
DataType
=
ua
.
NodeId
(
vtype
.
value
)
else
:
arg
.
DataType
=
ua
.
NodeId
(
vtype
)
...
...
examples/server-data-type-definition.py
View file @
d5c7acb2
...
...
@@ -20,11 +20,11 @@ async def main():
await
new_struct
(
server
,
idx
,
"MyStruct"
,
[
new_struct_field
(
"MyBool"
,
ua
.
VariantType
.
Boolean
),
new_struct_field
(
"MyUInt32
"
,
ua
.
VariantType
.
UInt32
),
new_struct_field
(
"MyUInt32
List"
,
ua
.
VariantType
.
UInt32
,
array
=
True
),
])
await
new_struct
(
server
,
idx
,
"MyOptionalStruct"
,
[
new_struct_field
(
"MyBool"
,
ua
.
VariantType
.
Boolean
),
new_struct_field
(
"MyUInt32
"
,
ua
.
VariantType
.
UInt32
),
new_struct_field
(
"MyUInt32
List"
,
ua
.
VariantType
.
UInt32
,
array
=
True
),
new_struct_field
(
"MyInt64"
,
ua
.
VariantType
.
Int64
,
optional
=
True
),
])
await
new_enum
(
server
,
idx
,
"MyEnum"
,
[
...
...
@@ -38,7 +38,7 @@ async def main():
await
server
.
nodes
.
objects
.
add_variable
(
idx
,
"my_enum"
,
ua
.
MyEnum
.
toto
)
await
server
.
nodes
.
objects
.
add_variable
(
idx
,
"my_struct"
,
ua
.
Variant
(
ua
.
MyStruct
(),
ua
.
VariantType
.
ExtensionObject
))
my_struct_optional
=
ua
.
MyOptionalStruct
()
my_struct_optional
.
MyUInt32
=
45
my_struct_optional
.
MyUInt32
List
=
[
45
,
67
]
my_struct_optional
.
MyInt64
=
-
67
await
server
.
nodes
.
objects
.
add_variable
(
idx
,
"my_struct_optional"
,
ua
.
Variant
(
my_struct_optional
,
ua
.
VariantType
.
ExtensionObject
))
...
...
tests/test_common.py
View file @
d5c7acb2
...
...
@@ -1343,3 +1343,35 @@ async def test_custom_struct_of_struct_with_spaces(opc):
var
=
await
opc
.
opc
.
nodes
.
objects
.
add_variable
(
idx
,
"my mother struct"
,
mystruct
)
val
=
await
var
.
read_value
()
assert
val
.
My_Sub_Struct
.
My_UInt32
==
78
async
def
test_custom_method_with_struct
(
opc
):
idx
=
4
data_type
,
nodes
=
await
new_struct
(
opc
.
opc
,
idx
,
"MyStructArg"
,
[
new_struct_field
(
"MyBool"
,
ua
.
VariantType
.
Boolean
),
new_struct_field
(
"MyUInt32"
,
ua
.
VariantType
.
UInt32
,
array
=
True
),
])
await
opc
.
opc
.
load_data_type_definitions
()
@
uamethod
def
func
(
parent
,
mystruct
):
print
(
mystruct
)
mystruct
.
MyUInt32
.
append
(
100
)
return
mystruct
methodid
=
await
opc
.
server
.
nodes
.
objects
.
add_method
(
ua
.
NodeId
(
"ServerMethodWithStruct"
,
10
),
ua
.
QualifiedName
(
'ServerMethodWithStruct'
,
10
),
func
,
[
ua
.
MyStructArg
],
[
ua
.
MyStructArg
]
)
mystruct
=
ua
.
MyStructArg
()
mystruct
.
MyUInt32
=
[
78
,
79
]
assert
data_type
.
nodeid
==
mystruct
.
data_type
result
=
await
opc
.
opc
.
nodes
.
objects
.
call_method
(
methodid
,
mystruct
)
assert
result
.
MyUInt32
==
[
78
,
79
,
100
]
tests/test_unit.py
View file @
d5c7acb2
...
...
@@ -332,7 +332,17 @@ def test_guid():
assert
v
==
v2
def
test_nodeid
():
def
test_nodeid_guid_string
():
n
=
ua
.
GuidNodeId
(
identifier
=
uuid
.
uuid4
())
s
=
n
.
to_string
()
n2
=
ua
.
NodeId
.
from_string
(
s
)
s2
=
n2
.
to_string
()
print
(
n
,
n2
,
s
,
s2
)
assert
n
==
n2
assert
s
==
s2
def
test__nodeid
():
nid
=
ua
.
NodeId
()
assert
nid
.
NodeIdType
==
ua
.
NodeIdType
.
TwoByte
nid
=
ua
.
NodeId
(
446
,
3
,
ua
.
NodeIdType
.
FourByte
)
...
...
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