INOS code
In addition to the use cases presented in Use case: INCO procedure with asynchronous part returning results, this page shows how to return 'named results'. 'Named results' is a feature that allows INOS code to return values to a caller (e.g. an HMI) by adding a string/name to it. Especially in case that a function returns multiple results, this feature offers some useful possibilities:
- There's no need for the caller to know the order of results (e.g. 1st results: "axis state", 2nd results: "axis position", etc.)
- As a consequence, the INOS code can change the order of results at any time
- The INOS code may add new results (e.g. "axis error state")
- The INOS code may remove existing results (e.g. "axis position") - if the caller code was programmed error safe
This page focus on the named results, therefore it assumes the reader has already studied the use cases here: Use case: INCO procedure with asynchronous part returning results.
The examples below assume the following code running on the target:
CMcResult CMyModule::MoveXAxisReturnTargetPosition(double arAxisPosition)
{
CINOSTaskExMsg* msg = new CINOSTaskExMsg(eMsgCmd, CmdMoveXAxisReturnTargetPosition, apSync);
msg->AddParam(arAxisPosition);
return PutMsg(msg);
}
void CMyModule::iMoveXAxisReturnTargetPosition(CINOSTaskExMsg* apMsg)
{
real64 rAxisPosition = apMsg->GetParam<real64>();
...
if( pAxis->Move(rAxisPosition, DF_INOS_SYNCHRONOUS) == 0 ) {
++m_MoveCounter;
apMsg->AddResult(m_MoveCounter);
apMsg->AddResult(pAxis->GetState(), "AxisState");
apMsg->AddResult(pAxis->GetType());
apMsg->AddResult(pAxis->GetError(), "AxisError");
apMsg->AddResult(pAxis->GetActPosition());
MsgDone(apMsg);
} else {
MsgDone(apMsg, CINOSTaskEx::eRplError, INOS_MCMSG_CODE_MYMODULE_MOVEXAXISRETURNTARGETPOSITION_FAILED);
}
}
The function does not return any results (except application errors of course).
PC code
Correct usage
- Get the results by order:
int32 iTicketOrError =
CallProcedureEx(
"TargetName",
"PathToProcedure.MoveAxisReturnTargetPosition(0.1234:d)");
if( iTicketOrError < 0 ) {
uint32 uMoveCounter;
uint32 uAxisState;
char cAxisType[256];
uint32 uAxisError;
double dTargetPosition;
}
- Get the named results first, followed by the unnamed results:
int32 iTicketOrError =
CallProcedureEx(
"TargetName",
"PathToProcedure.MoveAxisReturnTargetPosition(0.1234:d)");
if( iTicketOrError < 0 ) {
uint32 uAxisState;
uint32 uAxisError;
uint32 uMoveCounter;
char cAxisType[256];
double dTargetPosition;
}
- Get the results and their names by order:
int32 iTicketOrError =
CallProcedureEx(
"TargetName",
"PathToProcedure.MoveAxisReturnTargetPosition(0.1234:d)");
if( iTicketOrError < 0 ) {
char cResultName[256];
uint32 uMoveCounter;
cResultName, sizeof(cResultName));
cout << "Result name: " << cResultName << endl;
uint32 uAxisState;
cResultName, sizeof(cResultName));
cout << "Result name: " << cResultName << endl;
char cAxisType[256];
cResultName, sizeof(cResultName));
cout << "Result name: " << cResultName << endl;
uint32 uAxisError;
cResultName, sizeof(cResultName));
cout << "Result name: " << cResultName << endl;
double dTargetPosition;
cResultName, sizeof(cResultName));
cout << "Result name: " << cResultName << endl;
}
Forbidden/invalid usage
- It's not possible to get the same result multiple times. Therefore, in the following use case, the final call to CallProcedureExResultByName will for sure return an error:
int32 iTicketOrError =
CallProcedureEx(
"TargetName",
"PathToProcedure.MoveAxisReturnTargetPosition(0.1234:d)");
if( iTicketOrError < 0 ) {
uint32 uMoveCounter;
uint32 uAxisState;
char cAxisType[256];
uint32 uAxisError;
double dTargetPosition;
uint32 uAxisError2;
}