ModelDesign DefaultValue for Arrays of KeyValuePair (any value type)|OPC UA Standard|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
ModelDesign DefaultValue for Arrays of KeyValuePair (any value type)
Avatar
Alessandro_
New Member
Members
Forum Posts: 2
Member Since:
12/04/2024
sp_UserOfflineSmall Offline
1
01/09/2025 - 08:46
sp_Permalink sp_Print sp_EditHistory

I need to define a default value for the properties of my custom events. These properties are arrays of KeyValuePair objects, mimicking Map<String, SomeType>. In my case, the values can be either of type String or a custom structure.

Here’s an example of my current setup:

 

<ObjectType SymbolicName=”Custom:CustomEventType” BaseType=”ua:BaseEventType”>
    <Description>A custom event.</Description>
    <Children>
        <Property SymbolicName=”Custom:MapOfStrings” DataType=”ua:KeyValuePair” ValueRank=”Array” ModellingRule=”Mandatory”>
            <DefaultValue>
                <!– TODO –>
            </DefaultValue>
        </Property>
        <Property SymbolicName=”Custom:MapOfCustomDataType” DataType=”ua:KeyValuePair” ValueRank=”Array” ModellingRule=”Mandatory”>
            <DefaultValue>
                <!– TODO –>
            </DefaultValue>
        </Property>
    </Children>
</ObjectType>

<DataType SymbolicName=”Custom:CustomDataType” BaseType=”ua:Structure”>
    <Description>A custom structure.</Description>
    <Fields>
        <Field Name=”Name” DataType=”ua:String” ValueRank=”Scalar”>
            <Description>Some name.</Description>
        </Field>
        <Field Name=”Value” DataType=”ua:Int32″ ValueRank=”Array”>
            <Description>Some values.</Description>
        </Field>
    </Fields>
</DataType>

 

I’m struggling to define the DefaultValue part for these arrays. The default can be either:

  1. An empty array.
  2. An array with a dummy value.

Unfortunately, I couldn’t find any examples or resources addressing this specific case. Does anyone have suggestions or references for implementing this?

Avatar
Randy Armstrong
Admin
Forum Posts: 1585
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
01/12/2025 - 04:58
sp_Permalink sp_Print

The best way to get the XML for a default value is to create a simple test program

var dict = new List<Opc.Ua.KeyValuePair>();

public void SaveAsXml(ISystemContext context, Stream ostrm)
{
ServiceMessageContext messageContext = new ServiceMessageContext {
NamespaceUris = context.NamespaceUris,
ServerUris = context.ServerUris,
Factory = context.EncodeableFactory
};

XmlWriterSettings settings = Utils.DefaultXmlWriterSettings();
settings.CloseOutput = true;
using (XmlWriter writer = XmlWriter.Create(ostrm, settings))
{
XmlQualifiedName root = new XmlQualifiedName(“DefaultValue”, “https://opcfoundation.org/UA/ModelDesign.xsd”));

using (XmlEncoder encoder = new XmlEncoder(root, writer, messageContext))
{

encoder.WriteEncodeableArray(“ListOfExtensionObjects”, dict.ToArray(), typeof(KeyValuePair));

encoder.Close();
}
}
}

Avatar
Alessandro_
New Member
Members
Forum Posts: 2
Member Since:
12/04/2024
sp_UserOfflineSmall Offline
3
01/13/2025 - 01:38
sp_Permalink sp_Print sp_EditHistory

<DefaultValue xmlns=”https://opcfoundation.org/UA/ModelDesign.xsd”>
    <uax:ListOfExtensionObjects />
</DefaultValue>

I gave it a try and it seems to be enough for any kind of value; thank you!

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 23
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1450
Posts: 4909