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;