Hi,
I have successfully designed and implemented a server provider.
Now, I want to access variable values.
I want to fill the values of variables designed with values from my application and vice versa;
I want to use the values of variables set (via Client) in my application.
Where can I access variable values?
Is there a function which handles the communication?
Access Variable Values
Moderator: uasdkc
- Support Team
- Hero Member
- Posts: 3072
- Joined: 18 Mar 2011, 15:09
Re: Access Variable Values
Hello mmii,
please have a look at the Getting Started tutorials in our documentation, there you have an example on how to connect real world data with nodes in your provider: http://documentation.unified-automation ... arted.html. We also recommend to have a look at the demoprovider, as it contains samples for all kinds of use cases of the SDK.
Directly accessing values of variable nodes can be done with OpcUa_Variable_GetValue/OpcUa_Variable_SetValue.
please have a look at the Getting Started tutorials in our documentation, there you have an example on how to connect real world data with nodes in your provider: http://documentation.unified-automation ... arted.html. We also recommend to have a look at the demoprovider, as it contains samples for all kinds of use cases of the SDK.
Directly accessing values of variable nodes can be done with OpcUa_Variable_GetValue/OpcUa_Variable_SetValue.
Best regards
Unified Automation Support Team
Unified Automation Support Team
-
- Full Member
- Posts: 7
- Joined: 23 Nov 2017, 15:04
Re: Access Variable Values
Can you support me with an example?
In servermain.c I have real world data (boolean, double,...).
In uaprovider_xxx_nodes_1.c my nodes designed with UaModeler are described.
For my variable nodes, initial values are set, e.g.: value.Value.Double = (OpcUa_Double) 0.0;.
I want to use an expression like this in servermain.c. But you suggest OpcUa_Variable_SetValue().
I have checked the documentation of OpcUa_Variable_SetValue(): a pointer referencing the variable and the value as a variant to be set are required.
How can I get these?
In my opinion, I have to use unique identifiers for the variables from uaprovider_xxx_nodes_1.c. Is it correct?
I have tried to use:
where di2 is a variant and di2.value contains the real world value, but it doesnt't work, because xxx_Objects_TestObjekt1_TestVariable1is not known by the compiler.
This is the variable i want to set with real world data:
In servermain.c I have real world data (boolean, double,...).
In uaprovider_xxx_nodes_1.c my nodes designed with UaModeler are described.
For my variable nodes, initial values are set, e.g.: value.Value.Double = (OpcUa_Double) 0.0;.
I want to use an expression like this in servermain.c. But you suggest OpcUa_Variable_SetValue().
I have checked the documentation of OpcUa_Variable_SetValue(): a pointer referencing the variable and the value as a variant to be set are required.
How can I get these?
In my opinion, I have to use unique identifiers for the variables from uaprovider_xxx_nodes_1.c. Is it correct?
I have tried to use:
Code: Select all
OpcUa_Variable_SetValue(xxx_Objects_TestObjekt1_TestVariable1,di2)
This is the variable i want to set with real world data:
Code: Select all
/* TestVariable1, ComponentOf TestObjekt1 */
referenceTypeId.Identifier.Numeric = OpcUaId_HasComponent;
UaBase_CreateNumericNodeIdEx(&parentNodeId, xxx_Objects_TestObjekt1, g_UaProviderxxx_uNamespaceIndex1);
UaServer_GetNode(pAddressSpace,
&parentNodeId,
&pParent);
UaBase_CreateNumericNodeIdEx(&nodeInfo.TypeDefinition, OpcUaId_BaseDataVariableType, 0);
UaBase_CreateNumericNodeIdEx(&nodeInfo.NodeId, xxx_Objects_TestObjekt1_TestVariable1, g_UaProviderxxx_uNamespaceIndex1);
nodeInfo.NodeClass = OpcUa_NodeClass_Variable;
UaBase_CreateLocalizedText(&nodeInfo.sDisplayName, g_xxxStringTable1[14], g_xxxStringTable1[3]);
UaBase_CreateQualifiedNameEx(&nodeInfo.sBrowseName, g_xxxStringTable1[3], g_UaProviderxxx_uNamespaceIndex1);
UaBase_CreateLocalizedText(&nodeInfo.sDescription, g_xxxStringTable1[14], g_xxxStringTable1[4]);
uStatus = UaProvider_xxx_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_SetDataType_Numeric(pNode, OpcUaId_Double, 0);
OpcUa_Variable_SetHistorizing(pNode, OpcUa_False);
OpcUa_Variable_SetMinimumSamplingInterval(pNode, 0);
OpcUa_Variable_SetValueRank(pNode, OpcUa_ValueRanks_Scalar);
OpcUa_Variant_Initialize(&value);
value.Value.Double = (OpcUa_Double) 0.0;
value.Datatype = OpcUaType_Double;
value.ArrayType = OpcUa_VariantArrayType_Scalar;
OpcUa_Variable_AttachValue(pNode, &value);
- Support Team
- Hero Member
- Posts: 3072
- Joined: 18 Mar 2011, 15:09
Re: Access Variable Values
Hello mmii,
for setting the value of a node, you first need to retrieve the node (OpcUa_Variable) and then access its value. In our demo server we have an example for that in uaprovider_demo_simulation.c, function UaProvider_Demo_GetNodeValueNumeric. The numeric identifier of the node is passed into the function (in your case that would be xxx_Objects_TestObjekt1_TestVariable1. Based on that, the NodeId of the node is constructed and UaServer_GetNodeById is called to retrieve the OpcUa_Variable. This can then be passed to OpcUa_Variable_GetValue to retrieve the value (OpcUa_Variant) of the node.
for setting the value of a node, you first need to retrieve the node (OpcUa_Variable) and then access its value. In our demo server we have an example for that in uaprovider_demo_simulation.c, function UaProvider_Demo_GetNodeValueNumeric. The numeric identifier of the node is passed into the function (in your case that would be xxx_Objects_TestObjekt1_TestVariable1. Based on that, the NodeId of the node is constructed and UaServer_GetNodeById is called to retrieve the OpcUa_Variable. This can then be passed to OpcUa_Variable_GetValue to retrieve the value (OpcUa_Variant) of the node.
Best regards
Unified Automation Support Team
Unified Automation Support Team
-
- Full Member
- Posts: 7
- Joined: 23 Nov 2017, 15:04
Re: Access Variable Values
Ok, but my problem is that xxx_Objects_TestObjekt1_TestVariable1 is not known in servermain.c.
In my opinion, xxx_Objects_TestObjekt1_TestVariable1 represents an id, because UaProvider_Demo_GetNodeValueNumeric expects int id.
I need to include the relationship between xxx_Objects_TestObjekt1_TestVariable1 and id in servermain.c.
How can I do it?
In my opinion, xxx_Objects_TestObjekt1_TestVariable1 represents an id, because UaProvider_Demo_GetNodeValueNumeric expects int id.
I need to include the relationship between xxx_Objects_TestObjekt1_TestVariable1 and id in servermain.c.
How can I do it?
-
- Full Member
- Posts: 7
- Joined: 23 Nov 2017, 15:04
Re: Access Variable Values
I fixed the problem by including the providers _identifiers_1.h; now it seems to be known: No compiler error by using:mmii wrote: Ok, but my problem is that xxx_Objects_TestObjekt1_TestVariable1 is not known in servermain.c.
In my opinion, xxx_Objects_TestObjekt1_TestVariable1 represents an id, because UaProvider_Demo_GetNodeValueNumeric expects int id.
I need to include the relationship between xxx_Objects_TestObjekt1_TestVariable1 and id in servermain.c.
How can I do it?
Code: Select all
pVal = UaProvider_Demo_GetNodeValueNumeric(xxx_Objects_TestObjekt1_TestVariable1);
Considering your example from demoserver,
Code: Select all
if(pVal)
Without it, I get an Segmentation fault for the second line when I do:
Code: Select all
OpcUa_Variant *pVal = 0;
pVal->Value.UInt32 = 123;
- Support Team
- Hero Member
- Posts: 3072
- Joined: 18 Mar 2011, 15:09
Re: Access Variable Values
Hello mmii,
please use https://webdav.unifiedautomation.com/su ... _form.html to create a support request containing your customer id and an exact description of your issue, including your code, so we can analyze it.
please use https://webdav.unifiedautomation.com/su ... _form.html to create a support request containing your customer id and an exact description of your issue, including your code, so we can analyze it.
Best regards
Unified Automation Support Team
Unified Automation Support Team