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
4f113090
Commit
4f113090
authored
Jul 07, 2016
by
Marcel
Committed by
ORD
Jul 07, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[xmlimporter] support for values with ListOfLocalizedText (#238)
parent
9a97a01d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
3 deletions
+68
-3
opcua/common/xmlimporter.py
opcua/common/xmlimporter.py
+4
-1
opcua/common/xmlparser.py
opcua/common/xmlparser.py
+15
-1
tests/custom_nodes.xml
tests/custom_nodes.xml
+45
-1
tests/tests_server.py
tests/tests_server.py
+4
-0
No files found.
opcua/common/xmlimporter.py
View file @
4f113090
...
...
@@ -95,7 +95,10 @@ class XmlImporter(object):
attrs
.
DataType
=
self
.
to_nodeid
(
obj
.
datatype
)
# if obj.value and len(obj.value) == 1:
if
obj
.
value
is
not
None
:
attrs
.
Value
=
ua
.
Variant
(
obj
.
value
,
getattr
(
ua
.
VariantType
,
obj
.
valuetype
))
if
obj
.
valuetype
==
'ListOfLocalizedText'
:
attrs
.
Value
=
ua
.
Variant
([
ua
.
LocalizedText
(
txt
)
for
txt
in
obj
.
value
],
None
)
else
:
attrs
.
Value
=
ua
.
Variant
(
obj
.
value
,
getattr
(
ua
.
VariantType
,
obj
.
valuetype
))
if
obj
.
rank
:
attrs
.
ValueRank
=
obj
.
rank
if
obj
.
accesslevel
:
...
...
opcua/common/xmlparser.py
View file @
4f113090
...
...
@@ -167,10 +167,24 @@ class XMLParser(object):
elif
ntag
==
"ListOfExtensionObject"
:
self
.
logger
.
info
(
"Value type not implemented: %s"
,
ntag
)
elif
ntag
==
"ListOfLocalizedText"
:
self
.
logger
.
info
(
"Value type not implemented: %s"
,
ntag
)
obj
.
value
=
self
.
_parse_list_of_localized_text
(
el
)
else
:
self
.
logger
.
info
(
"Value type not implemented: %s"
,
ntag
)
def
_parse_list_of_localized_text
(
self
,
el
):
value
=
[]
for
localized_text_list
in
el
:
for
localized_text
in
localized_text_list
:
ntag
=
self
.
_retag
.
match
(
localized_text
.
tag
).
groups
()[
1
]
for
child
in
localized_text
:
ntag
=
self
.
_retag
.
match
(
child
.
tag
).
groups
()[
1
]
if
ntag
==
'Text'
:
txt
=
""
for
text
in
child
.
itertext
():
txt
+=
text
value
.
append
(
txt
)
return
value
def
_parse_refs
(
self
,
el
,
obj
):
for
ref
in
el
:
if
ref
.
attrib
[
"ReferenceType"
]
==
"HasTypeDefinition"
:
...
...
tests/custom_nodes.xml
View file @
4f113090
<?xml version="1.0" encoding="utf-8"?>
<UANodeSet
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd=
"http://www.w3.org/2001/XMLSchema"
Version=
"1.02"
LastModified=
"2013-03-06T05:36:44.0862658Z"
xmlns=
"http://opcfoundation.org/UA/2011/03/UANodeSet.xsd"
>
<UANodeSet
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd=
"http://www.w3.org/2001/XMLSchema"
Version=
"1.02"
LastModified=
"2013-03-06T05:36:44.0862658Z"
xmlns=
"http://opcfoundation.org/UA/2011/03/UANodeSet.xsd"
xmlns:uax=
"http://opcfoundation.org/UA/2008/02/Types.xsd"
>
<Aliases>
<Alias
Alias=
"LocalizedText"
>
i=21
</Alias>
<Alias
Alias=
"HasModellingRule"
>
i=37
</Alias>
<Alias
Alias=
"HasTypeDefinition"
>
i=40
</Alias>
<Alias
Alias=
"HasSubtype"
>
i=45
</Alias>
<Alias
Alias=
"HasProperty"
>
i=46
</Alias>
<Alias
Alias=
"MyCustomString"
>
ns=1;i=3008
</Alias>
<Alias
Alias=
"MyEnum"
>
ns=1;i=3010
</Alias>
</Aliases>
<UAObject
NodeId=
"i=30001"
BrowseName=
"MyXMLFolder"
>
...
...
@@ -44,6 +50,7 @@
<UAVariable
NodeId=
"i=30006"
BrowseName=
"MyXMLVariableWithoutValue"
DataType=
"String"
>
<References>
<Reference
ReferenceType=
"HasTypeDefinition"
>
i=69
</Reference>
<Reference
ReferenceType=
"Organizes"
IsForward=
"false"
>
i=30002
</Reference>
</References>
...
...
@@ -62,4 +69,41 @@
<Reference
ReferenceType=
"Organizes"
IsForward=
"false"
>
i=30002
</Reference>
</References>
</UAVariable>
<UADataType
NodeId=
"ns=1;i=3010"
BrowseName=
"1:MyEnum"
>
<DisplayName>
MyEnum
</DisplayName>
<Description>
Demonstrates enums
</Description>
<References>
<Reference
ReferenceType=
"HasProperty"
>
ns=1;i=6001
</Reference>
<Reference
ReferenceType=
"HasSubtype"
IsForward=
"false"
>
i=29
</Reference>
</References>
<Definition
Name=
"1:MyEnum"
>
<Field
Name=
"ok"
Value=
"0"
/>
<Field
Name=
"run"
Value=
"1"
/>
<Field
Name=
"error"
Value=
"2"
/>
</Definition>
</UADataType>
<UAVariable
DataType=
"LocalizedText"
ParentNodeId=
"ns=1;i=3010"
ValueRank=
"1"
NodeId=
"ns=1;i=6001"
ArrayDimensions=
"3"
BrowseName=
"EnumStrings"
>
<DisplayName>
EnumStrings
</DisplayName>
<References>
<Reference
ReferenceType=
"HasProperty"
IsForward=
"false"
>
ns=1;i=3010
</Reference>
<Reference
ReferenceType=
"HasModellingRule"
>
i=78
</Reference>
<Reference
ReferenceType=
"HasTypeDefinition"
>
i=68
</Reference>
</References>
<Value>
<uax:ListOfLocalizedText>
<uax:LocalizedText>
<uax:Text>
ok
</uax:Text>
</uax:LocalizedText>
<uax:LocalizedText>
<uax:Text>
run
</uax:Text>
</uax:LocalizedText>
<uax:LocalizedText>
<uax:Text>
error
</uax:Text>
</uax:LocalizedText>
</uax:ListOfLocalizedText>
</Value>
</UAVariable>
</UANodeSet>
tests/tests_server.py
View file @
4f113090
...
...
@@ -134,7 +134,11 @@ class TestServer(unittest.TestCase, CommonTests, SubscriptionTests):
v
=
o
.
get_child
([
"MyXMLFolder"
,
"MyXMLObject"
,
"MyXMLVariable"
])
val
=
v
.
get_value
()
self
.
assertEqual
(
val
,
"StringValue"
)
o
=
self
.
opc
.
get_root_node
().
get_child
([
"Types"
,
"DataTypes"
,
"BaseDataType"
,
"Enumeration"
,
"1:MyEnum"
,
"0:EnumStrings"
])
self
.
assertEqual
(
len
(
o
.
get_value
()
),
3
)
def
test_historize_variable
(
self
):
o
=
self
.
opc
.
get_objects_node
()
var
=
o
.
add_variable
(
3
,
"test_hist"
,
1.0
)
...
...
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