How to write an array from UaExpert

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

Moderator: uasdkc

Post Reply
mLang_de
Sr. Member
Sr. Member
Posts: 14
Joined: 31 Jul 2013, 12:51

How to write an array from UaExpert

Post by mLang_de »

Hello support team,

I create some array variables.
Is it right, that every array is an OpcUa_UInt32 type?
The OpcUa_Variable_AttachArrayDimensions function only accept as second parameter a UInt32 pointer.
Following is a part from code, which are create the array.

Code: Select all

	case OpcUaType_Byte:
		OpcUa_Variable_SetDataType_Numeric(pNode, OpcUaId_Byte, 0);
		OpcUa_Boolean_Initialize(&(**ppvalue).Value.Byte);
		OpcUa_Variant_SetByte(*ppvalue, 0xFF);
	    OpcUa_Variable_SetValueRank(pNode, OpcUa_ValueRanks_OneOrMoreDimensions);
	    pArrayDimensions = (OpcUa_UInt32 *)UaServer_Alloc(sizeof(OpcUa_UInt32) * 5);
	    pArrayDimensions[ 0 ] = 5;
	    pArrayDimensions[ 1 ] = 10;
	    pArrayDimensions[ 2 ] = 15;
	    pArrayDimensions[ 3 ] = 20;
	    pArrayDimensions[ 4 ] = 25;
	    OpcUa_Variable_AttachArrayDimensions(pNode, pArrayDimensions, 5);
The array will be shown in the UaExpert as I expect (picture: see attachment).
I see the created array, but can't edit it.
I try several time to enter a new value in the field Value->Value. It is only possible to enter a number between 0 - 255.
That's ok, because the variable are from the type OpcUa_SByte.
But how can I edit the complete array?

Thanks in advance!

Best regards
mLang_de

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

Re: How to write an array from UaExpert

Post by Support Team »

Hello mLang_de,

An array can certainly be of any type. Only the array dimensions are defined as OpcUa_UInt32. In this case here you created an array with five dimensions.

I think you wanted to create a simple array with 5 elements, holding the values 5, 10, 15, 20, 25?!

Code: Select all

    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);
    for(i=0; i<5; i++)
    {
        value.Value.Array.Value.ByteArray[i] = (i+1)*5;
    }
    OpcUa_Variable_AttachValue(pNode, &value);
You can write the Values in the Attribute Window of the UaExpert:

mLang_de
Sr. Member
Sr. Member
Posts: 14
Joined: 31 Jul 2013, 12:51

Re: How to write an array from UaExpert

Post by mLang_de »

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);

Post Reply