Hello,
thanks for your response!
It is right that I want a simple array with 5 elements.
The values are not really important, because they will be overwritten later.
I add your code snippet in my code, but it doesn't work.
I can compile the code and execute the program.
But in the UaExpert the variable doesn't look like your attachment from your post.
I try serverals things without a good result.
In the following code I create many Opc Variable, which are work good.
But if I create an array, it will not work correct.
I try to generate a byte-array so the function UaProviderHilscher_OPC_UA_netPROXY_OpcObjectElement_SetDataType() will not be execute.
Please have a look at my code, there must be a further mistake somewhere else.
From location with the comment /* new User Data */ only the UserData will generate and attached at the node.
In the uploaded attachment is an screenshot with my current (new) view.
Best regards
mLang_de
Code: Select all
OpcUa_UInt32 ulInstanceNodeId = (*pptObjectInstanceNodeIdListEntry)->ulInstanceNodeId;
OpcUa_CharA *pszElementName = ptNpxElementDescriptionListEntry->pszElementName;
OpcUa_UInt16 usElementType = ptNpxElementDescriptionListEntry->usElementType;
OpcUa_UInt16 usElementArrayCount = ptNpxElementDescriptionListEntry->usElementArrayCount;
OpcUa_UInt16 usElementTypeByteSize = ptNpxElementDescriptionListEntry->usElementTypeByteSize;
OpcUa_Variant_Initialize(&value);
OpcUa_NodeId_Initialize(&referenceTypeId);
OpcUa_NodeId_Initialize(&parentNodeId);
UaProvider_Hilscher_OPC_UA_netPROXY_NodeInfo_Initialize(&nodeInfo);
UaServer_CreateNumericNodeIdEx(&parentNodeId, ulInstanceNodeId, g_UaProviderHilscher_OPC_UA_netPROXY_uNamespaceIndex);
UaServer_GetNode(pAddressSpace,
&parentNodeId,
&pParent);
referenceTypeId.Identifier.Numeric = OpcUaId_HasComponent;
UaServer_CreateNumericNodeIdEx(&nodeInfo.TypeDefinition, OpcUaId_BaseDataVariableType, 0);
/* this Opc Object represent a Npx Object information and is grouped to the OpcElement therefore the global variable is used */
UaServer_CreateNumericNodeIdEx(&nodeInfo.NodeId, g_uElementNodeIdCounter, g_UaProviderHilscher_OPC_UA_netPROXY_uNamespaceIndex);
g_uElementNodeIdCounter++;
nodeInfo.NodeClass = OpcUa_NodeClass_Variable;
UaServer_CreateLocalizedText(&nodeInfo.sDisplayName, LOCALETEXT_EN_US, pszElementName);
UaServer_CreateQualifiedNameEx(&nodeInfo.sBrowseName, pszElementName, g_UaProviderHilscher_OPC_UA_netPROXY_uNamespaceIndex);
UaServer_CreateLocalizedText(&nodeInfo.sDescription, LOCALETEXT_EN_US, OpcUa_Null);
uStatus = UaProvider_Hilscher_OPC_UA_netPROXY_CreateNode(pAddressSpace,
&pNode,
pParent,
&referenceTypeId,
&nodeInfo);
OpcUa_GotoErrorIfBad(uStatus);
OpcUa_Variable_SetAccessLevel(pNode, OpcUa_AccessLevels_CurrentReadOrWrite);
#if UASERVER_SUPPORT_AUTHORIZATION == OPCUA_CONFIG_NO
OpcUa_Variable_SetUserAccessLevel(pNode, OpcUa_AccessLevels_CurrentReadOrWrite);
#endif
OpcUa_Variable_SetHistorizing(pNode, OpcUa_False);
OpcUa_Variable_SetMinimumSamplingInterval(pNode, 0);
UaServer_UserMgt_SetPermissions((OpcUa_BaseNode*)pNode,
1,
2,
UA_USER_ATTRWRITABLE | UA_USER_WRITABLE | UA_USER_READABLE | UA_USER_BROWSEABLE |
UA_GROUP_READABLE | UA_GROUP_BROWSEABLE |
UA_OTHER_BROWSEABLE);
OpcUa_Variant *pvalue = &value;
if(OpcUaType_Byte != usElementType)
UaProviderHilscher_OPC_UA_netPROXY_OpcObjectElement_SetDataType(&pNode, usElementType, &pvalue, &usElementTypeByteSize);
if((usElementArrayCount > 0) && (usElementType != OpcUaType_String))
{
OpcUa_Variable_SetDataType_Numeric(pNode, OpcUaId_Byte, 0);
OpcUa_Variable_SetValueRank(pNode, OpcUa_ValueRanks_OneDimension);
pArrayDimensions = (OpcUa_UInt32 *)UaServer_Alloc(sizeof(OpcUa_UInt32) * 1);
pArrayDimensions[ 0 ] = 5;
OpcUa_Variable_AttachArrayDimensions(pNode, pArrayDimensions, 1);
OpcUa_Variant_Initialize(&value);
value.Datatype = OpcUaType_Byte;
value.ArrayType = OpcUa_VariantArrayType_Array;
value.Value.Array.Length = 5;
value.Value.Array.Value.ByteArray = (OpcUa_Byte *)UaServer_Alloc(sizeof(OpcUa_Byte) * 5);
OpcUa_UInt32 i = 0;
for(i=0; i<5; i++)
{
value.Value.Array.Value.ByteArray[i] = (i+1)*5;
}
OpcUa_Variable_AttachValue(pNode, &value);
}
else
{
OpcUa_Variable_SetValueRank(pNode, OpcUa_ValueRanks_Scalar);
}
OpcUa_Variable_AttachValue(pNode, &value);
/* new User Data */
NpxObjectElement_T *pNewObjectElement = OpcUa_Null;
UaProviderHilscher_OPC_UA_netPROXY_NpxObjectElementPointer_List_AddEntry(&pNewObjectElement);
pNewObjectElement->Type = UserDataObjectElement;
pNewObjectElement->ulParentObjectId = ptNpxObjectDescriptionListEntry->ulObjectId;
pNewObjectElement->tValueDataType = usElementType;
pNewObjectElement->usTypeByteSize = usElementTypeByteSize;
if(ptNpxElementDescriptionListEntry->usElementArrayCount != 0)
{
pNewObjectElement->ulByteLength = ptNpxElementDescriptionListEntry->usElementTypeByteSize *\
ptNpxElementDescriptionListEntry->usElementArrayCount;
}
else
{
pNewObjectElement->ulByteLength = ptNpxElementDescriptionListEntry->usElementTypeByteSize;
}
pNewObjectElement->ulGroupNumber = ulGroupNumber;
pNewObjectElement->ulByteOffset = ptNpxElementDescriptionListEntry->usElementByteOffset;
pNewObjectElement->ulObjectByteSize = ptNpxObjectDescriptionListEntry->ulByteLength;
pNewObjectElement->ulInstanceNumber = ulNpxObjectInstanceCounter;
/* Set new machine struct as user data of the new node */
OpcUa_BaseNode_SetUserData(pNode, pNewObjectElement);
ElementNodeIdList_T *ptElementNodeIdListEntryTmp = OpcUa_Null;
UaProviderHilscher_OPC_UA_netPROXY_ElementNodeId_List_AddEntry(pptObjectInstanceNodeIdListEntry, &ptElementNodeIdListEntryTmp, nodeInfo.NodeId.Identifier.Numeric);