Now a method has been added that expects a NodeId as input. In the example, the string is loaded into a UaVariant and then converted to the required type using changeType. However, more complex types are not supported.
So I created a UaNodeId using fromXmlString and assigned it to the UaVariant and then transferred it to the InputArgument using copyTo.
The subsequent call then returns the error BadInValidArgument. The method can be executed via the UaExpert. What have I done wrong?
Code: Select all
bool StringToUaVariant(LPCSTR _in, OpcUa_BuiltInType _type, UaVariant& _out, LPCSTR _logname)
{
switch (_type) {
case OpcUaType_Null:
case OpcUaType_Guid:
case OpcUaType_XmlElement:
case OpcUaType_ExpandedNodeId:
case OpcUaType_StatusCode:
case OpcUaType_QualifiedName:
case OpcUaType_ExtensionObject:
case OpcUaType_DataValue:
case OpcUaType_Variant:
case OpcUaType_DiagnosticInfo:
GLogPrintf(GLOG_OPCUA_ERR, "%s parameter type %u not supported", _logname, _type);
break;
case OpcUaType_NodeId:
_out.setNodeId(UaNodeId::fromXmlString(_in));
GLogPrintf(GLOG_OPCUA_SUB1, "%s parameter type NodeId set", _logname);
return true;
default:
{
_out.setString(_in);
OpcUa_StatusCode status = _out.changeType(_type, OpcUa_False);
if (!OpcUa_IsGood(status)) {
if (_logname) {
String msg = UaStringToString(UaStatus(status).toString());
GLogPrintf(GLOG_OPCUA_ERR, "%s value failed - %s", _logname, msg.c_str());
}
return false;
}
return true;
}
}
return false;
}
Code: Select all
callRequest.inputArguments.create(inputArguments.length());
for (OpcUa_UInt32 i = 0; i < inputArguments.length(); i++) {
UaString argumentName(inputArguments[i].Name);
String name = UaStringToString(argumentName);
LPCSTR _value = jh.getStr(name.c_str());
if (!_value) {
args_ok = false;
break;
}
UaVariant tempValue;
// Try to change to built-in time, more complex types are not supported here
if (!StringToUaVariant(_value, OpcUa_BuiltInType(inputArguments[i].DataType.Identifier.Numeric), tempValue, GetLogname().c_str())) {
args_ok = false;
break;
}
tempValue.copyTo(&callRequest.inputArguments[i]);
}
}