Skip to content

Commit b149c96

Browse files
Fix for Issue 145 Option Set Values is missing NodeId (#148)
1 parent 95f03df commit b149c96

File tree

3 files changed

+75
-28
lines changed

3 files changed

+75
-28
lines changed

NodeSetToAML.cs

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3115,36 +3115,37 @@ private void ProcessEnumerations(ref AttributeTypeType att, NodeId nodeId)
31153115

31163116
private void ProcessOptionSets(ref AttributeTypeType att, NodeId nodeId)
31173117
{
3118-
NodeId OptionSetsPropertyId = m_modelManager.FindFirstTarget(nodeId, HasPropertyNodeId, true, "OptionSetValues");
3119-
3120-
if (OptionSetsPropertyId != null && m_modelManager.IsTypeOf(nodeId, NumberNodeId))
3118+
// This should not be done via the Localized text. Should be from Field Definitions.
3119+
UADataType dataType = m_modelManager.FindNode<UADataType>(nodeId);
3120+
if ( dataType != null )
31213121
{
3122-
att.AttributeDataType = "";
3123-
var OptionSetsPropertyNode = FindNode<UANode>(OptionSetsPropertyId);
3124-
var OptionSets = OptionSetsPropertyNode as UAVariable;
3125-
Opc.Ua.LocalizedText[] OptionSetValues = OptionSets.DecodedValue.Value as Opc.Ua.LocalizedText[];
3126-
foreach (var OptionSetValue in OptionSetValues)
3122+
if (dataType != null &&
3123+
dataType.Definition != null &&
3124+
dataType.Definition.IsOptionSet == true)
31273125
{
3128-
if( OptionSetValue.Text != null && OptionSetValue.Text.Length > 0 )
3126+
if (dataType.Definition.Field != null)
31293127
{
3130-
AttributeType a = new AttributeType( new System.Xml.Linq.XElement( defaultNS + "Attribute" ) );
3131-
a.Name = OptionSetValue.Text;
3132-
a.AttributeDataType = "xs:boolean";
3133-
att.Attribute.Insert( a, false );
3128+
foreach(DataTypeField field in dataType.Definition.Field)
3129+
{
3130+
if ( !string.IsNullOrEmpty( field.Name ))
3131+
{
3132+
AttributeType a = new AttributeType(new System.Xml.Linq.XElement(defaultNS + "Attribute"));
3133+
a.Name = field.Name;
3134+
a.AttributeDataType = "xs:boolean";
3135+
att.Attribute.Insert(a, false);
3136+
}
3137+
}
31343138
}
31353139
}
31363140
}
3137-
31383141

31393142
if (nodeId == NodeIdNodeId || nodeId == ExpandedNodeIdNodeId)
31403143
{
3141-
31423144
// add NodeId
3143-
31443145
var added2 = new AttributeType(new System.Xml.Linq.XElement(defaultNS + "Attribute"));
31453146
added2.Name = "ServerInstanceUri";
31463147
added2.AttributeDataType = "xs:anyURI";
3147-
att.Attribute.Insert( added2, false);
3148+
att.Attribute.Insert(added2, false);
31483149

31493150
added2 = new AttributeType(new System.Xml.Linq.XElement(defaultNS + "Attribute"));
31503151
added2.Name = "Alias";
@@ -3620,6 +3621,23 @@ private void AddOptionSetFieldDefinition( AttributeFamilyType attribute, UANode
36203621
}
36213622

36223623
attribute.Attribute.Insert(optionSetFields, false, true);
3624+
3625+
NodeId optionSetsPropertyId = m_modelManager.FindFirstTarget(
3626+
optionSetNode.DecodedNodeId, HasPropertyNodeId, true, "OptionSetValues");
3627+
3628+
if (optionSetsPropertyId != null && m_modelManager.IsTypeOf(optionSetNode.DecodedNodeId, NumberNodeId))
3629+
{
3630+
UANode optionSetsPropertyNode = FindNode<UANode>(optionSetsPropertyId);
3631+
UAVariable optionSets = optionSetsPropertyNode as UAVariable;
3632+
3633+
Opc.Ua.LocalizedText[] optionSetValues = optionSets.DecodedValue.Value as Opc.Ua.LocalizedText[];
3634+
AttributeType optionSetValuesAttribute = AddModifyAttribute(attribute.Attribute, "OptionSetValues",
3635+
Opc.Ua.DataTypes.LocalizedText, new Variant(optionSetValues), bListOf: true);
3636+
optionSetValuesAttribute.AdditionalInformation.Append(OpcUaTypeOnly);
3637+
RemoveNodeIdsFromDefinition(optionSetValuesAttribute);
3638+
AddModifyAttribute(optionSetValuesAttribute.Attribute, "NodeId", "NodeId",
3639+
new Variant(optionSetsPropertyId));
3640+
}
36233641
}
36243642
else
36253643
{

SystemTest/NodeSetFiles/TestAml.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,15 @@
468468
<Value>
469469
<ListOfLocalizedText xmlns="http://opcfoundation.org/UA/2008/02/Types.xsd">
470470
<LocalizedText>
471-
<Text>Active</Text>
471+
<Locale>fr</Locale>
472+
<Text>Activer</Text>
472473
</LocalizedText>
473474
<LocalizedText>
474-
<Text>Unacknowledged</Text>
475+
<Locale>de</Locale>
476+
<Text>Nicht bestätigt</Text>
475477
</LocalizedText>
476478
<LocalizedText>
479+
<Locale>en</Locale>
477480
<Text>Unconfirmed</Text>
478481
</LocalizedText>
479482
</ListOfLocalizedText>
Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
using Aml.Engine.CAEX;
22
using Aml.Engine.CAEX.Extensions;
3-
using Aml.Engine.Services;
43
using Microsoft.VisualStudio.TestTools.UnitTesting;
5-
using Opc.Ua;
6-
using System;
74
using System.Collections.Generic;
8-
using System.Linq;
95

106
namespace SystemTest
117
{
128
[TestClass]
13-
public class TestOptionSetEmptyValues
9+
public class TestOptionSet
1410
{
1511
#region Tests
1612

@@ -19,7 +15,7 @@ public void TestOperationalHealthOptionSet()
1915
{
2016
AttributeTypeLibType attributeLibrary = GetFxAcAttributes();
2117
AttributeFamilyType attributeFamilyType = attributeLibrary[ "OperationalHealthOptionSet" ];
22-
TestOptionSet( attributeFamilyType );
18+
TestOptionSetCount( attributeFamilyType );
2319
}
2420

2521
[TestMethod, Timeout( TestHelper.UnitTestTimeout )]
@@ -29,7 +25,7 @@ public void TestAggregatedHealthOptionSet()
2925
AttributeFamilyType attributeFamilyType = attributeLibrary[ "AggregatedHealthDataType" ];
3026
Assert.IsNotNull( attributeFamilyType );
3127
AttributeType attributeType = attributeFamilyType.Attribute[ "AggregatedOperationalHealth" ];
32-
TestOptionSet( attributeType );
28+
TestOptionSetCount( attributeType );
3329
}
3430

3531
[TestMethod, Timeout( TestHelper.UnitTestTimeout )]
@@ -42,7 +38,7 @@ public void TestInstance()
4238
Assert.IsNotNull( internalElementType );
4339
AttributeType value = internalElementType.Attribute[ "Value" ];
4440
Assert.IsNotNull( value );
45-
TestOptionSet( value );
41+
TestOptionSetCount( value );
4642
}
4743

4844
[TestMethod, Timeout(TestHelper.UnitTestTimeout)]
@@ -75,6 +71,36 @@ public void TestFieldDefinitions(string attributeName, string attributeValue)
7571
Assert.IsNull(valueAttribute.Attribute[ "ValidBits" ]);
7672
}
7773

74+
[TestMethod, Timeout(TestHelper.UnitTestTimeout)]
75+
[DataRow("0", "fr", "Activer")]
76+
[DataRow("1", "de", "Nicht bestätigt")]
77+
[DataRow("2", "en", "Unconfirmed")]
78+
public void TestFieldValues(string index, string localeId, string value)
79+
{
80+
CAEXDocument document = GetDocument("TestAml.xml.amlx");
81+
string amlId = TestHelper.BuildAmlId("", TestHelper.Uris.Test, "3009");
82+
CAEXObject initialObject = document.FindByID(amlId);
83+
Assert.IsNotNull(initialObject, "Unable to find Initial Object");
84+
AttributeFamilyType theObject = initialObject as AttributeFamilyType;
85+
Assert.IsNotNull(theObject, "Unable to Cast Initial Object");
86+
87+
88+
AttributeType values = GetAttribute(theObject.Attribute, "OptionSetValues");
89+
Assert.IsNotNull(values.AdditionalInformation);
90+
Assert.AreEqual(1, values.AdditionalInformation.Count);
91+
Assert.AreEqual("OpcUa:TypeOnly", values.AdditionalInformation[0]);
92+
93+
AttributeType nodeIdAttribute = GetAttribute(values, "NodeId");
94+
AttributeType rootNodeIdAttribute = GetAttribute(nodeIdAttribute, "RootNodeId");
95+
AttributeType numericId = GetAttribute(rootNodeIdAttribute, "NumericId");
96+
Assert.AreEqual(numericId.Value, "6239");
97+
98+
99+
AttributeType indexAttribute = GetAttribute(values, index);
100+
AttributeType localeAttribute = GetAttribute(indexAttribute, localeId);
101+
Assert.AreEqual(localeAttribute.Value, value);
102+
}
103+
78104

79105

80106
#endregion
@@ -88,7 +114,7 @@ private CAEXDocument GetDocument(string fileName = "AmlFxTest.xml.amlx")
88114
return document;
89115
}
90116

91-
public void TestOptionSet( AttributeTypeType attributeFamilyType )
117+
public void TestOptionSetCount( AttributeTypeType attributeFamilyType )
92118
{
93119
Assert.IsNotNull( attributeFamilyType );
94120
Assert.IsTrue( attributeFamilyType.Attribute.Count >= 4 );

0 commit comments

Comments
 (0)