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
c217b806
Commit
c217b806
authored
Oct 08, 2016
by
olivier R-D
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add missing file, add small test and fix related import bug
parent
cf2066d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
3 deletions
+69
-3
opcua/common/xmlimporter.py
opcua/common/xmlimporter.py
+14
-3
tests/tests_xml.py
tests/tests_xml.py
+55
-0
No files found.
opcua/common/xmlimporter.py
View file @
c217b806
...
...
@@ -149,12 +149,23 @@ class XmlImporter(object):
raise
Exception
(
"Error val should a dict"
,
name
,
val
)
else
:
for
attname
,
v
in
val
.
items
():
# tow possible values:
# either we get value directly
# or a dict if it s an object or a list
if
type
(
v
)
is
str
:
setattr
(
ext
,
attname
,
to_python
(
v
,
ext
,
attname
))
else
:
for
attname2
,
v2
in
v
.
items
():
obj2
=
getattr
(
ext
,
attname
)
setattr
(
obj2
,
attname2
,
to_python
(
v2
,
obj2
,
attname2
))
# so we habve either an object or a list...
obj2
=
getattr
(
ext
,
attname
)
if
not
isinstance
(
obj2
,
ua
.
NodeId
)
and
not
hasattr
(
obj2
,
"ua_types"
):
# we probably have a list
my_list
=
[]
for
vtype
,
v2
in
v
.
items
():
my_list
.
append
(
ua_type_to_python
(
v2
,
vtype
))
setattr
(
obj
,
attname
,
my_list
)
else
:
for
attname2
,
v2
in
v
.
items
():
setattr
(
obj2
,
attname2
,
to_python
(
v2
,
obj2
,
attname2
))
return
ext
def
_add_variable_value
(
self
,
obj
):
...
...
tests/tests_xml.py
0 → 100644
View file @
c217b806
from
opcua
import
ua
from
opcua
import
uamethod
@
uamethod
def
func
(
parent
,
value
,
string
):
return
value
*
2
class
XmlTests
(
object
):
def
test_xml_import
(
self
):
self
.
srv
.
import_xml
(
"tests/custom_nodes.xml"
)
o
=
self
.
opc
.
get_objects_node
()
v
=
o
.
get_child
([
"MyXMLFolder"
,
"MyXMLObject"
,
"MyXMLVariable"
])
val
=
v
.
get_value
()
self
.
assertEqual
(
val
,
"StringValue"
)
node_path
=
[
"Types"
,
"DataTypes"
,
"BaseDataType"
,
"Enumeration"
,
"1:MyEnum"
,
"0:EnumStrings"
]
o
=
self
.
opc
.
get_root_node
().
get_child
(
node_path
)
self
.
assertEqual
(
len
(
o
.
get_value
()),
3
)
# Check if method is imported
node_path
=
[
"Types"
,
"ObjectTypes"
,
"BaseObjectType"
,
"1:MyObjectType"
,
"1:MyMethod"
]
o
=
self
.
opc
.
get_root_node
().
get_child
(
node_path
)
self
.
assertEqual
(
len
(
o
.
get_referenced_nodes
()),
4
)
# Check if InputArgs are imported and can be read
node_path
=
[
"Types"
,
"ObjectTypes"
,
"BaseObjectType"
,
"1:MyObjectType"
,
"1:MyMethod"
,
"InputArguments"
]
o
=
self
.
opc
.
get_root_node
().
get_child
(
node_path
)
input_arg
=
o
.
get_data_value
().
Value
.
Value
[
0
]
self
.
assertEqual
(
input_arg
.
Name
,
'Context'
)
def
test_xml_export
(
self
):
o
=
self
.
opc
.
nodes
.
objects
.
add_object
(
2
,
"xmlexportobj"
)
m
=
o
.
add_method
(
2
,
"callme"
,
func
,
[
ua
.
VariantType
.
Double
,
ua
.
VariantType
.
String
],
[
ua
.
VariantType
.
Float
])
# set an arg dimension to a list to test list export
inputs
=
m
.
get_child
(
"InputArguments"
)
val
=
inputs
.
get_value
()
val
[
0
].
ArrayDimensions
=
[
2
,
2
]
inputs
.
set_value
(
val
)
#get all nodes and export
nodes
=
[
o
,
m
]
nodes
.
extend
(
m
.
get_children
())
self
.
opc
.
export_xml
(
nodes
,
"export.xml"
)
self
.
opc
.
delete_nodes
(
nodes
)
self
.
opc
.
import_xml
(
"export.xml"
)
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