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
5c35942a
Commit
5c35942a
authored
Jan 03, 2021
by
oroulet
Committed by
oroulet
Jan 04, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test for structs of structs and list and fix bugs
parent
5946687c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
7 deletions
+54
-7
asyncua/common/structures104.py
asyncua/common/structures104.py
+6
-3
tests/test_common.py
tests/test_common.py
+48
-4
No files found.
asyncua/common/structures104.py
View file @
5c35942a
...
...
@@ -6,6 +6,7 @@ import logging
import
re
from
asyncua
import
ua
from
asyncua
import
Node
from
asyncua.common.manage_nodes
import
create_encoding
,
create_data_type
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -26,12 +27,12 @@ def new_struct_field(name, dtype, array=False, optional=False, description=""):
field
.
DataType
=
ua
.
NodeId
(
dtype
.
value
,
0
)
elif
isinstance
(
dtype
,
ua
.
NodeId
):
field
.
DataType
=
dtype
elif
isinstance
(
dtype
,
ua
.
Node
):
elif
isinstance
(
dtype
,
Node
):
field
.
DataType
=
dtype
.
nodeid
else
:
raise
ValueError
(
f"Datatype of a field must be a NodeId, not
{
dtype
}
of type
{
type
(
dtype
)
}
"
)
if
array
:
field
.
ValueRan
d
=
ua
.
ValueRank
.
OneOrMoreDimensions
field
.
ValueRan
k
=
ua
.
ValueRank
.
OneOrMoreDimensions
field
.
ArrayDimensions
=
[
1
]
return
field
...
...
@@ -149,7 +150,9 @@ class {name}:
code += " ('
Encoding
', '
Byte
'),
\
n
"
uatypes = []
for field in sdef.Fields:
prefix = '
ListOf
' if field.ValueRank >= 1 else ''
prefix = ""
if field.ValueRank >= 1 or field.ArrayDimensions:
prefix = '
ListOf
'
if field.DataType.NamespaceIndex == 0 and field.DataType.Identifier in ua.ObjectIdNames:
uatype = ua.ObjectIdNames[field.DataType.Identifier]
elif field.DataType in ua.extension_objects_by_datatype:
...
...
tests/test_common.py
View file @
5c35942a
...
...
@@ -1139,20 +1139,20 @@ async def test_custom_enum(opc):
assert
val
==
1
async
def
test_custom_struct
(
opc
):
async
def
test_custom_struct
_
(
opc
):
idx
=
4
await
new_struct
(
opc
.
opc
,
idx
,
"MyStruct"
,
[
new_struct_field
(
"MyBool"
,
ua
.
VariantType
.
Boolean
),
new_struct_field
(
"MyUInt32"
,
ua
.
VariantType
.
UInt32
),
new_struct_field
(
"MyUInt32"
,
ua
.
VariantType
.
UInt32
,
array
=
True
),
])
await
opc
.
opc
.
load_data_type_definitions
()
mystruct
=
ua
.
MyStruct
()
mystruct
.
MyUInt32
=
78
mystruct
.
MyUInt32
=
[
78
,
79
]
var
=
await
opc
.
opc
.
nodes
.
objects
.
add_variable
(
idx
,
"my_struct"
,
ua
.
Variant
(
mystruct
,
ua
.
VariantType
.
ExtensionObject
))
val
=
await
var
.
read_value
()
assert
val
.
MyUInt32
==
78
assert
val
.
MyUInt32
==
[
78
,
79
]
async
def
test_custom_struct_with_optional_fields
(
opc
):
...
...
@@ -1176,3 +1176,47 @@ async def test_custom_struct_with_optional_fields(opc):
assert
val
.
MyInt64
==
-
67
async
def
test_custom_struct_of_struct
(
opc
):
idx
=
4
dtype
=
await
new_struct
(
opc
.
opc
,
idx
,
"MySubStruct"
,
[
new_struct_field
(
"MyBool"
,
ua
.
VariantType
.
Boolean
),
new_struct_field
(
"MyUInt32"
,
ua
.
VariantType
.
UInt32
),
])
await
new_struct
(
opc
.
opc
,
idx
,
"MyMotherStruct"
,
[
new_struct_field
(
"MyBool"
,
ua
.
VariantType
.
Boolean
),
new_struct_field
(
"MySubStruct"
,
dtype
),
])
await
opc
.
opc
.
load_data_type_definitions
()
mystruct
=
ua
.
MyMotherStruct
()
mystruct
.
MySubStruct
=
ua
.
MySubStruct
()
mystruct
.
MySubStruct
.
MyUInt32
=
78
var
=
await
opc
.
opc
.
nodes
.
objects
.
add_variable
(
idx
,
"my_mother_struct"
,
ua
.
Variant
(
mystruct
,
ua
.
VariantType
.
ExtensionObject
))
val
=
await
var
.
read_value
()
assert
val
.
MySubStruct
.
MyUInt32
==
78
async
def
test_custom_list_of_struct
(
opc
):
idx
=
4
dtype
=
await
new_struct
(
opc
.
opc
,
idx
,
"MySubStruct"
,
[
new_struct_field
(
"MyBool"
,
ua
.
VariantType
.
Boolean
),
new_struct_field
(
"MyUInt32"
,
ua
.
VariantType
.
UInt32
),
])
await
new_struct
(
opc
.
opc
,
idx
,
"MyMotherStruct"
,
[
new_struct_field
(
"MyBool"
,
ua
.
VariantType
.
Boolean
),
new_struct_field
(
"MySubStruct"
,
dtype
,
array
=
True
),
])
await
opc
.
opc
.
load_data_type_definitions
()
mystruct
=
ua
.
MyMotherStruct
()
mystruct
.
MySubStruct
=
[
ua
.
MySubStruct
()]
mystruct
.
MySubStruct
[
0
].
MyUInt32
=
78
var
=
await
opc
.
opc
.
nodes
.
objects
.
add_variable
(
idx
,
"my_mother_struct"
,
ua
.
Variant
(
mystruct
,
ua
.
VariantType
.
ExtensionObject
))
val
=
await
var
.
read_value
()
assert
val
.
MySubStruct
[
0
].
MyUInt32
==
78
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