Write service for custom datatypes

Questions regarding the use of the .NET SDK 2.0 for Server or Client development or integration into customer products ...

Moderator: uasdknet

Post Reply
sudhapc
Hero Member
Hero Member
Posts: 28
Joined: 16 Oct 2018, 12:47

Write service for custom datatypes

Post by sudhapc »

Hi Team,

i have one usecase where i have a custom datatype (dynamically generated) under enumerations.
This customdatatype node has enumValues variable node as a child node.
From my client i want to set the value to one of variable node whose datatype is custom datatype.

Am getting badtypemismatch error. i have checked the datatype and valuerank is fine.

ex:
xyz--(DataType Node)
-->EnumValues(Variable node)

myvariablenode-->datatype is the xyz.

from client am sending list of extension objects which has only one item which is holding the value.

pls refer the client side code below.

Code: Select all

byte[] cp;
            var customDataTypeReferenceDescriptions = GetCustomDataTypesFromServer(dataType, session);
            if (customDataTypeReferenceDescriptions.Count > 0)
            {
                var customDataTypeChildNode =
                    session.Browse(customDataTypeReferenceDescriptions[0].NodeId.ToNodeId(session.NamespaceUris),
                        out cp);
                var arrayOfExtensionObjects = ReadArrayOfEnumValues(session, customDataTypeChildNode[0].NodeId.ToNodeId(session.NamespaceUris),
                    Attributes.Value);
                var mappedExtensionObject = arrayOfExtensionObjects.SingleOrDefault(item =>
                    ((EnumValueType) item.Body).DisplayName.ToString(null,CultureInfo.InvariantCulture) == value);
                List<ExtensionObject> listOfExtensionObjects = new List<ExtensionObject>();
                listOfExtensionObjects.Add(mappedExtensionObject);
                return CreateWriteValue(Attributes.Value, new Variant(listOfExtensionObjects),
                    nodeId);
            }


server side code:

Code: Select all

var array = (ExtensionObject[])updateNodesParameter.Value.Value;
            var listOfDataValues = array.Select(item => new EnumValueType
            {
                DisplayName = ((EnumValueType)item.Body).DisplayName,
                Value = ((EnumValueType)item.Body).Value,
                Description = ((EnumValueType)item.Body).Description
            }).ToList();
            updateNodesParameter.Value = new DataValue() { WrappedValue = new Variant(listOfDataValues) };
            var x = m_UpdateNodesParameter.MmdNodeManager.writeToOpcua(m_UpdateNodesParameter.Context,
                m_UpdateNodesParameter.NodeHandle,
                m_UpdateNodesParameter.IndexRange, m_UpdateNodesParameter.Value);
            return x;

User avatar
Support Team
Hero Member
Hero Member
Posts: 3064
Joined: 18 Mar 2011, 15:09

Re: Write service for custom datatypes

Post by Support Team »

Hello,

Enumerated DataTypes have a property either called EnumStrings or called EnumValues. The value of this property describes the DataType.

If a Variable has an enumerated DataType, the value always is sent as Int32. A client can use the information from the property to use a string representation for the numeric value. But the numeric value needs to be sent.
Best regards
Unified Automation Support Team

Post Reply