0

I am interested in Reading InputArguments and OutputArgument nodes of a Method node from the client. Assuming I have 2 InputArguments and I am trying to read the first InputArgument.

    UA_Variant v;
    UA_NodeId n = UA_NODEID_NUMERIC(0, node_id_inp_arg);
    UA_Client_readValueAttribute(client, n, &v);
    UA_Argument* a = (UA_Argument*)v.data;
    std::cout<<(char*)a[0].name.data<<"\n";    // Prints junk
    std::cout<<a[0].arrayDimensionsSize<<"\n"; // Works
    //Need to access other attributes as well

I am doing like the above, but unfortunately not succeeded. Anyone who can help can be greatly appreciated. I would like to do the same thing for OutputArguments as well. Thank you.

Indri
  • 41
  • 1
  • 6

2 Answers2

0

Methods do not have their input and output argument in the address space, and therefore you cannot "read" them. Input and output arguments are passed to/from the CallMethod service. (There may be descriptions of input and output arguments in the address space, but I do not think that is what you want).

There is UA_Client_CallServerMethod in open62541 to call the UA methods.

ZbynekZ
  • 1,532
  • 10
  • 16
  • I do not want to read the input argument values, but the Signature of IputArgument. Like how many input arguments are there and the types?. As far as I know, the InputArgument and OutputArgumets are of PropertyType and are HasProperty references of the method node. So, why can't we use UA_Client_readValueAttribute si read the Property Node? – Indri May 17 '20 at 18:13
0

I figured out a solution, but this is not very straight forward

UA_ReadRequest request;
UA_ReadValueId id;
UA_ReadRequest_init(&request);
UA_ReadValueId_init(&id);
id.attributeId          = UA_ATTRIBUTEID_VALUE;
id.nodeId               = node; /* NodeId of the Input or Output Argument*/
request.nodesToRead     = &id;
request.nodesToReadSize = 1;
size_t argLen           = argument_length; /* Cardinatlity of argument */

UA_ReadResponse response = UA_Client_Service_read(m_client, request);

UA_StatusCode retval = UA_STATUSCODE_GOOD;
if(response.responseHeader.serviceResult != UA_STATUSCODE_GOOD){
    retval = response.responseHeader.serviceResult;
} else if(response.resultsSize != 1 || !response.results[0].hasValue){
    retval = UA_STATUSCODE_BADNODEATTRIBUTESINVALID;
}else if(response.results[0].value.type != &UA_TYPES[UA_TYPES_EXTENSIONOBJECT]){
    retval = UA_STATUSCODE_BADTYPEMISMATCH;
}if(retval != UA_STATUSCODE_GOOD) {
    UA_ReadResponse_deleteMembers(&response);
    return retval;
}
retval = UA_STATUSCODE_BADNOTFOUND;

UA_ExtensionObject *value = reinterpret_cast<UA_ExtensionObject*>(response.results[0].value.data);

for(size_t l(0); l < argLen; l++){
    UA_Argument* arg = reinterpret_cast<UA_Argument*>(value[l].content.decoded.data);
    /* Do my stuff*/
}
Indri
  • 41
  • 1
  • 6