Commit 4f113090 authored by Marcel's avatar Marcel Committed by ORD

[xmlimporter] support for values with ListOfLocalizedText (#238)

parent 9a97a01d
......@@ -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:
......
......@@ -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":
......
<?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>
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment