I am trying to read my Omron NX102 PLC OPCUA Server
. I have a Data Structure
in the PLC with fields as STRING
and an DOUBLE
array of length 4
.
I can read all the information correctly from UA Expert and my code as well.
typedef struct {
UA_String describe;
size_t arSize;
UA_Double* arguments;
} dArgument;
static UA_DataTypeMember dArgument_members[2] = {
{
UA_TYPENAME("describe") /* .memberName */
& UA_TYPES[UA_TYPES_STRING], /* .memberType */
0, /* .padding */
false, /* .isArray */
false /* .isOptional */
},
{
UA_TYPENAME("arguments") /* .memberName */
& UA_TYPES[UA_TYPES_DOUBLE], /* .memberType */
0, /* .padding */
true, /* .isArray */
false /* .isOptional */
}
};
static const UA_DataType dArgumentType = {
UA_TYPENAME("dArgument") /* .typeName */
{4, UA_NODEIDTYPE_NUMERIC, {5001}}, /* .typeId */
{4, UA_NODEIDTYPE_NUMERIC, {5002}}, /* .binaryEncodingId, the numeric
identifier used on the wire (the
namespaceindex is from .typeId) */
sizeof(dArgument), /* .memSize */
UA_DATATYPEKIND_STRUCTURE, /* .typeKind */
false, /* .pointerFree */
false, /* .overlayable (depends on endianness and
the absence of padding) */
2, /* .membersSize */
dArgument_members
};
And printing the information from the main()
as:
UA_ReadRequest request;
UA_ReadRequest_init(&request);
UA_ReadValueId ids[3];
UA_ReadValueId_init(&ids[0]);
ids[0].attributeId = UA_ATTRIBUTEID_VALUE;
ids[0].nodeId = UA_NODEID_STRING(4, (char*)"moveAbsoluteArgument");
request.nodesToRead = ids;
request.nodesToReadSize = 1;
UA_DataValue reading[3];
UA_ReadResponse response = UA_Client_Service_read(client, request);
reading[0] = *response.results;
dArgument* arg = (dArgument*)reading[0].value.data;
for (int i = 0; i < arg->arSize; i++)
printf(" args[%d]: %f Describe: %.*s\n\n\n\n\n\n", i, arg->arguments[i],
arg>describe.data, arg->describe.data);
The moment I change the Type of describe
from UA_String
to UA_UInt16
, it does not populate the arSize
and I can not read the extension object
. Somehow UA_UInt16
is messing up my Extension Object
. The Structure is as below:
UAExpert can read the data correctly as shown below but not the code I am trying (below).
Could someone please help with what I am doing wrong?
The code I am trying is:
typedef struct {
UA_UInt16 describe;
size_t arSize;
UA_Double* arguments;
} dArgument;
static UA_DataTypeMember dArgument_members[2] = {
{
UA_TYPENAME("describe") /* .memberName */
& UA_TYPES[UA_TYPES_UINT16], /* .memberType */
0, /* .padding */
false, /* .isArray */
false /* .isOptional */
},
{
UA_TYPENAME("arguments") /* .memberName */
& UA_TYPES[UA_TYPES_DOUBLE], /* .memberType */
0, /* .padding */
true, /* .isArray */
false /* .isOptional */
}
};
static const UA_DataType dArgumentType = {
UA_TYPENAME("dArgument") /* .typeName */
{4, UA_NODEIDTYPE_NUMERIC, {5001}}, /* .typeId */
{4, UA_NODEIDTYPE_NUMERIC, {5002}}, /* .binaryEncodingId, the numeric
identifier used on the wire (the
namespaceindex is from .typeId) */
sizeof(dArgument), /* .memSize */
UA_DATATYPEKIND_STRUCTURE, /* .typeKind */
false, /* .pointerFree */
false, /* .overlayable (depends on endianness and
the absence of padding) */
2, /* .membersSize */
dArgument_members
};
And the main()
UA_ReadRequest request;
UA_ReadRequest_init(&request);
UA_ReadValueId ids[3];
UA_ReadValueId_init(&ids[0]);
ids[0].attributeId = UA_ATTRIBUTEID_VALUE;
ids[0].nodeId = UA_NODEID_STRING(4, (char*)"moveAbsoluteArgument");
// set here the nodes you want to read
request.nodesToRead = ids;
request.nodesToReadSize = 1;
UA_DataValue reading[3];
UA_ReadResponse response = UA_Client_Service_read(client, request);
reading[0] = *response.results;
dArgument* arg = (dArgument*)reading[0].value.data;
for (int i = 0; i < arg->arSize; i++)
printf(" args[%d]: %f Describe: %d\n\n\n\n\n\n", i, arg->arguments[i], arg->describe);