Hello again,
I will describe my problem more detailed.
I will add my own global variable at an Opc-Variable.
Here are the code for my global structs:
Code: Select all
/*============================================================================
* Structs and global variables for managing custom user data
*===========================================================================*/
/* Enum of custom user data types */
enum _UserDataType
{
UserDataTemperature,
UserDataMachine,
UserDataMachineSwitch,
UserDataObject,
UserDataObjectElement
};
typedef enum _UserDataType UserDataType;
/* All user data structs contain the same header with type information.
* This concept is application specific and only an example.
* You can store whatever you like in UserData.
*/
struct _UserDataCommon
{
UserDataType Type; /* Currently only the type info is needed in the common header */
};
typedef struct _UserDataCommon UserDataCommon;
struct _NpxObjectElement
{
/* User data header */
UserDataType Type;
/* Protocol information */
OpcUa_Double *pValue;
};
typedef struct _NpxObjectElement NpxObjectElement;
struct _NpxObject
{
/* User data header */
UserDataType Type;
/* Protocol information */
NpxObjectElement *pElement;
OpcUa_NodeId nodeId;
};
typedef struct _NpxObject NpxObject;
In the file uaprovider_NAME.c are the global variables definitions:
Code: Select all
NpxObject *g_pMyNpxObject = OpcUa_Null;
NpxObjectElement g_dMyNpxObjectElement;
I edit the functionparameters from the createAddressSpace-fct.. I think it isn't really necessary, but I take the custom_provider-example for assist.
Therefore I add the new created NpxObject-reference to my gloabal variables here:
Code: Select all
static OpcUa_StatusCode UaProvider_Hilscher_types_CreateAddressSpace()
{
OpcUa_InitializeStatus(OpcUa_Module_Server, "UaProvider_Hilscher_types_CreateAddressSpace");
NpxObject *pNewNpxObject = OpcUa_Null;
uStatus = UaProvider_Hilscher_types_CreateAddressSpace1(&pNewNpxObject);
OpcUa_GotoErrorIfBad(uStatus);
g_pMyNpxObject = pNewNpxObject;
g_pMyNpxObject->pElement = &g_dMyNpxObjectElement;
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
OpcUa_FinishErrorHandling;
}
At the create_AddressSpace-fct I add at first the pointer for my struct. Therefore I add the global variables as extern (file: uaprovider_NAME_nodes1.c):
Code: Select all
OpcUa_StatusCode UaProvider_Hilscher_types_CreateAddressSpace1(NpxObject **a_ppNewNpxObject)
{
UaServer_AddressSpace* pAddressSpace = &(g_pHilscher_typesProvider->AddressSpace);
UaServer_AddressSpace* pServerAddressSpace = OpcUa_Null;
OpcUa_BaseNode *pNode;
OpcUa_BaseNode *pParent;
OpcUa_DataVariable *pVariable = OpcUa_Null;
OpcUa_NodeId nodeId;
OpcUa_NodeId referenceTypeId;
OpcUa_NodeId dataTypeId;
OpcUa_NodeId typeNodeId;
OpcUa_NodeId parentNodeId;
OpcUa_Variant value;
OpcUa_LocalizedText localizedText;
OpcUa_UInt32 *pArrayDimensions;
OpcUa_Int32 i = 0;
OpcUa_StatusCode statusCode = 0;
UaProvider_Hilscher_types_NodeInfo nodeInfo;
NpxObject *pNewNpxObject = OpcUa_Null;
NpxObjectElement *pNewNpxObjectElement = OpcUa_Null;
OpcUa_Variant *pValue = OpcUa_Null;
.
.
.
After the initialisation I create some object and folders. After that I will add my own defined struct. In the first part a object is created for organize the new object.:
Code: Select all
/* Device Desciption, ComponentOf Objects */
UaServer_CreateNumericNodeIdEx(&parentNodeId, Hilscher_types_Objects_netPROXY_device_0_group_0_Objects, g_UaProviderHilscher_types_uNamespaceIndex1);
UaServer_GetNode(pAddressSpace,
&parentNodeId,
&pParent);
UaServer_CreateNumericNodeIdEx(&nodeInfo.TypeDefinition, Hilscher_types_NpxDeviceDescriptionTypeId, g_UaProviderHilscher_types_uNamespaceIndex1);
UaServer_CreateNumericNodeIdEx(&nodeInfo.NodeId, Hilscher_types_Objects_netPROXY_device_0_group_0_Objects_Device_Desciption, g_UaProviderHilscher_types_uNamespaceIndex1);
nodeInfo.NodeClass = OpcUa_NodeClass_Object;
UaServer_CreateLocalizedText(&nodeInfo.sDisplayName, g_Hilscher_typesStringTable1[77], g_Hilscher_typesStringTable1[12]);
UaServer_CreateQualifiedNameEx(&nodeInfo.sBrowseName, g_Hilscher_typesStringTable1[12], g_UaProviderHilscher_types_uNamespaceIndex1);
UaServer_CreateLocalizedText(&nodeInfo.sDescription, g_Hilscher_typesStringTable1[77], g_Hilscher_typesStringTable1[0]);
uStatus = UaProvider_Hilscher_types_CreateNode(pAddressSpace,
&pNode,
pParent,
&referenceTypeId,
&nodeInfo);
OpcUa_GotoErrorIfBad(uStatus);
OpcUa_Object_SetEventNotifier(pNode, 0);
Now I will creat the own objects:
Code: Select all
/******* NEW ****************/
/* Create and initialize new object struct */
/*NpxObject**/
pNewNpxObject = (NpxObject*)OpcUa_Alloc(sizeof(NpxObject));
OpcUa_ReturnErrorIfAllocFailed(pNewNpxObject);
OpcUa_MemSet(pNewNpxObject, 0, sizeof(NpxObject));
pNewNpxObject->Type = UserDataObject;
/* Device Desciption, ComponentOf Objects */
UaServer_CreateNumericNodeIdEx(&parentNodeId, Hilscher_types_Objects_netPROXY_device_0_group_0_Objects, g_UaProviderHilscher_types_uNamespaceIndex1);
UaServer_GetNode(pAddressSpace,
&parentNodeId,
&pParent);
UaServer_CreateNumericNodeIdEx(&nodeInfo.TypeDefinition, Hilscher_types_NpxDeviceDescriptionTypeId, g_UaProviderHilscher_types_uNamespaceIndex1);
UaServer_CreateNumericNodeIdEx(&nodeInfo.NodeId, Hilscher_types_Objects_netPROXY_device_0_group_0_Objects_Device_Desciption+100, g_UaProviderHilscher_types_uNamespaceIndex1);
nodeInfo.NodeClass = OpcUa_NodeClass_Object;
UaServer_CreateLocalizedText(&nodeInfo.sDisplayName, g_Hilscher_typesStringTable1[77], "Mein Objekt");
UaServer_CreateQualifiedNameEx(&nodeInfo.sBrowseName, "Mein_Objekt", g_UaProviderHilscher_types_uNamespaceIndex1);
UaServer_CreateLocalizedText(&nodeInfo.sDescription, g_Hilscher_typesStringTable1[77], g_Hilscher_typesStringTable1[0]);
uStatus = UaProvider_Hilscher_types_CreateNode(pAddressSpace,
&pNode,
pParent,
&referenceTypeId,
&nodeInfo);
OpcUa_GotoErrorIfBad(uStatus);
OpcUa_Object_SetEventNotifier(pNode, 0);
OpcUa_NodeId_CopyTo(&nodeInfo.NodeId, &pNewNpxObject->nodeId);
/* Set new object struct as user data of the new node */
OpcUa_BaseNode_SetUserData(pNode, pNewNpxObject);
/* Create and initialize new object element struct */
pNewNpxObjectElement = (NpxObjectElement*)OpcUa_Alloc(sizeof(NpxObjectElement));
OpcUa_ReturnErrorIfAllocFailed(pNewNpxObjectElement);
OpcUa_MemSet(pNewNpxObjectElement, 0, sizeof(NpxObjectElement));
pNewNpxObjectElement->Type = UserDataObjectElement;
/* Create ObjectElement property */
nodeInfo.NodeId.Identifier.Numeric++;
UaServer_CreateNumericNodeIdEx(&nodeInfo.TypeDefinition, OpcUaId_PropertyType, 0);
uStatus = UaServer_CreateDataVariable(pAddressSpace,
&pVariable,
pNode,
nodeInfo.NodeId.Identifier.Numeric,
g_UaProviderHilscher_types_uNamespaceIndex1,
"Element_1");
OpcUa_GotoErrorIfBad(uStatus);
OpcUa_Variable_SetDataType_Numeric(pVariable, OpcUaId_Double, 0);
pValue = OpcUa_Variable_GetValue(pVariable);
pValue->Datatype = OpcUaType_Double;
pValue->Value.Double = 48.0;
OpcUa_BaseNode_SetUserData(pVariable, pNewNpxObjectElement);
pNewNpxObject->pElement = pNewNpxObjectElement;
*a_ppNewNpxObject = pNewNpxObject;
/******* NEW ENDE ***********/
After compiling, I can browse the new objects and my global struct content all pointer-address's and nodeID's. Only my variable g_pMyNpxObject->pElement->pValue is everytime 0. I expect 48.
What and where is my mistake?
A Screenshot from the UaExpert I added as attachment.
Thanks in advance!
Kind regards
mLang_de