Page 1 of 1

Write service for custom datatypes

Posted: 20 Jul 2020, 11:21
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.

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 =
                        out cp);
                var arrayOfExtensionObjects = ReadArrayOfEnumValues(session, customDataTypeChildNode[0].NodeId.ToNodeId(session.NamespaceUris),
                var mappedExtensionObject = arrayOfExtensionObjects.SingleOrDefault(item =>
                    ((EnumValueType) item.Body).DisplayName.ToString(null,CultureInfo.InvariantCulture) == value);
                List<ExtensionObject> listOfExtensionObjects = new List<ExtensionObject>();
                return CreateWriteValue(Attributes.Value, new Variant(listOfExtensionObjects),

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
            updateNodesParameter.Value = new DataValue() { WrappedValue = new Variant(listOfDataValues) };
            var x = m_UpdateNodesParameter.MmdNodeManager.writeToOpcua(m_UpdateNodesParameter.Context,
                m_UpdateNodesParameter.IndexRange, m_UpdateNodesParameter.Value);
            return x;

Re: Write service for custom datatypes

Posted: 04 Sep 2020, 18:07
by Support Team

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.