Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 35 additions & 17 deletions NodeSetToAML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3115,36 +3115,37 @@ private void ProcessEnumerations(ref AttributeTypeType att, NodeId nodeId)

private void ProcessOptionSets(ref AttributeTypeType att, NodeId nodeId)
{
NodeId OptionSetsPropertyId = m_modelManager.FindFirstTarget(nodeId, HasPropertyNodeId, true, "OptionSetValues");

if (OptionSetsPropertyId != null && m_modelManager.IsTypeOf(nodeId, NumberNodeId))
// This should not be done via the Localized text. Should be from Field Definitions.
UADataType dataType = m_modelManager.FindNode<UADataType>(nodeId);
if ( dataType != null )
{
att.AttributeDataType = "";
var OptionSetsPropertyNode = FindNode<UANode>(OptionSetsPropertyId);
var OptionSets = OptionSetsPropertyNode as UAVariable;
Opc.Ua.LocalizedText[] OptionSetValues = OptionSets.DecodedValue.Value as Opc.Ua.LocalizedText[];
foreach (var OptionSetValue in OptionSetValues)
if (dataType != null &&
dataType.Definition != null &&
dataType.Definition.IsOptionSet == true)
{
if( OptionSetValue.Text != null && OptionSetValue.Text.Length > 0 )
if (dataType.Definition.Field != null)
{
AttributeType a = new AttributeType( new System.Xml.Linq.XElement( defaultNS + "Attribute" ) );
a.Name = OptionSetValue.Text;
a.AttributeDataType = "xs:boolean";
att.Attribute.Insert( a, false );
foreach(DataTypeField field in dataType.Definition.Field)
{
if ( !string.IsNullOrEmpty( field.Name ))
{
AttributeType a = new AttributeType(new System.Xml.Linq.XElement(defaultNS + "Attribute"));
a.Name = field.Name;
a.AttributeDataType = "xs:boolean";
att.Attribute.Insert(a, false);
}
}
}
}
}


if (nodeId == NodeIdNodeId || nodeId == ExpandedNodeIdNodeId)
{

// add NodeId

var added2 = new AttributeType(new System.Xml.Linq.XElement(defaultNS + "Attribute"));
added2.Name = "ServerInstanceUri";
added2.AttributeDataType = "xs:anyURI";
att.Attribute.Insert( added2, false);
att.Attribute.Insert(added2, false);

added2 = new AttributeType(new System.Xml.Linq.XElement(defaultNS + "Attribute"));
added2.Name = "Alias";
Expand Down Expand Up @@ -3614,6 +3615,23 @@ private void AddOptionSetFieldDefinition( AttributeFamilyType attribute, UANode
}

attribute.Attribute.Insert(optionSetFields, false, true);

NodeId optionSetsPropertyId = m_modelManager.FindFirstTarget(
optionSetNode.DecodedNodeId, HasPropertyNodeId, true, "OptionSetValues");

if (optionSetsPropertyId != null && m_modelManager.IsTypeOf(optionSetNode.DecodedNodeId, NumberNodeId))
{
UANode optionSetsPropertyNode = FindNode<UANode>(optionSetsPropertyId);
UAVariable optionSets = optionSetsPropertyNode as UAVariable;

Opc.Ua.LocalizedText[] optionSetValues = optionSets.DecodedValue.Value as Opc.Ua.LocalizedText[];
AttributeType optionSetValuesAttribute = AddModifyAttribute(attribute.Attribute, "OptionSetValues",
Opc.Ua.DataTypes.LocalizedText, new Variant(optionSetValues), bListOf: true);
optionSetValuesAttribute.AdditionalInformation.Append(OpcUaTypeOnly);
RemoveNodeIdsFromDefinition(optionSetValuesAttribute);
AddModifyAttribute(optionSetValuesAttribute.Attribute, "NodeId", "NodeId",
new Variant(optionSetsPropertyId));
}
}
else
{
Expand Down
7 changes: 5 additions & 2 deletions SystemTest/NodeSetFiles/TestAml.xml
Original file line number Diff line number Diff line change
Expand Up @@ -468,12 +468,15 @@
<Value>
<ListOfLocalizedText xmlns="http://opcfoundation.org/UA/2008/02/Types.xsd">
<LocalizedText>
<Text>Active</Text>
<Locale>fr</Locale>
<Text>Activer</Text>
</LocalizedText>
<LocalizedText>
<Text>Unacknowledged</Text>
<Locale>de</Locale>
<Text>Nicht bestätigt</Text>
</LocalizedText>
<LocalizedText>
<Locale>en</Locale>
<Text>Unconfirmed</Text>
</LocalizedText>
</ListOfLocalizedText>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
using Aml.Engine.CAEX;
using Aml.Engine.CAEX.Extensions;
using Aml.Engine.Services;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Opc.Ua;
using System;
using System.Collections.Generic;
using System.Linq;

namespace SystemTest
{
[TestClass]
public class TestOptionSetEmptyValues
public class TestOptionSet
{
#region Tests

Expand All @@ -19,7 +15,7 @@ public void TestOperationalHealthOptionSet()
{
AttributeTypeLibType attributeLibrary = GetFxAcAttributes();
AttributeFamilyType attributeFamilyType = attributeLibrary[ "OperationalHealthOptionSet" ];
TestOptionSet( attributeFamilyType );
TestOptionSetCount( attributeFamilyType );
}

[TestMethod, Timeout( TestHelper.UnitTestTimeout )]
Expand All @@ -29,7 +25,7 @@ public void TestAggregatedHealthOptionSet()
AttributeFamilyType attributeFamilyType = attributeLibrary[ "AggregatedHealthDataType" ];
Assert.IsNotNull( attributeFamilyType );
AttributeType attributeType = attributeFamilyType.Attribute[ "AggregatedOperationalHealth" ];
TestOptionSet( attributeType );
TestOptionSetCount( attributeType );
}

[TestMethod, Timeout( TestHelper.UnitTestTimeout )]
Expand All @@ -42,7 +38,7 @@ public void TestInstance()
Assert.IsNotNull( internalElementType );
AttributeType value = internalElementType.Attribute[ "Value" ];
Assert.IsNotNull( value );
TestOptionSet( value );
TestOptionSetCount( value );
}

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

[TestMethod, Timeout(TestHelper.UnitTestTimeout)]
[DataRow("0", "fr", "Activer")]
[DataRow("1", "de", "Nicht bestätigt")]
[DataRow("2", "en", "Unconfirmed")]
public void TestFieldValues(string index, string localeId, string value)
{
CAEXDocument document = GetDocument("TestAml.xml.amlx");
string amlId = TestHelper.BuildAmlId("", TestHelper.Uris.Test, "3009");
CAEXObject initialObject = document.FindByID(amlId);
Assert.IsNotNull(initialObject, "Unable to find Initial Object");
AttributeFamilyType theObject = initialObject as AttributeFamilyType;
Assert.IsNotNull(theObject, "Unable to Cast Initial Object");


AttributeType values = GetAttribute(theObject.Attribute, "OptionSetValues");
Assert.IsNotNull(values.AdditionalInformation);
Assert.AreEqual(1, values.AdditionalInformation.Count);
Assert.AreEqual("OpcUa:TypeOnly", values.AdditionalInformation[0]);

AttributeType nodeIdAttribute = GetAttribute(values, "NodeId");
AttributeType rootNodeIdAttribute = GetAttribute(nodeIdAttribute, "RootNodeId");
AttributeType numericId = GetAttribute(rootNodeIdAttribute, "NumericId");
Assert.AreEqual(numericId.Value, "6239");


AttributeType indexAttribute = GetAttribute(values, index);
AttributeType localeAttribute = GetAttribute(indexAttribute, localeId);
Assert.AreEqual(localeAttribute.Value, value);
}



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

public void TestOptionSet( AttributeTypeType attributeFamilyType )
public void TestOptionSetCount( AttributeTypeType attributeFamilyType )
{
Assert.IsNotNull( attributeFamilyType );
Assert.IsTrue( attributeFamilyType.Attribute.Count >= 4 );
Expand Down