INOS code
The following INCO function (MoveXAxis) "just" puts a message into the tasks message queue. Later, when the message will be 'dispatched' by the task, it'll actually perform an axis Move (iMoveXAxis). The function does not return any results (except the INOS_MCMSG_CODE_MYMODULE_MOVEXAXIS_FAILED application error in case the move fails).
CMcResult CMyModule::MoveXAxis(double arAxisPosition)
{
CINOSTaskExMsg* msg = new CINOSTaskExMsg(eMsgCmd, CmdMoveXAxis, apSync);
msg->AddParam(arAxisPosition);
return PutMsg(msg);
}
void CMyModule::iMoveXAxis(CINOSTaskExMsg* apMsg)
{
real64 rAxisPosition = apMsg->GetParam<real64>();
...
if( pAxis->Move(rAxisPosition, DF_INOS_SYNCHRONOUS) == 0 ) {
MsgDone(apMsg);
} else {
MsgDone(apMsg, CINOSTaskEx::eRplError, INOS_MCMSG_CODE_MYMODULE_MOVEXAXIS_FAILED);
}
}
PC code
Correct usage
- Standard case: Start move, wait until the move finishes and check whether it succeeded or failed. Another (sligthly more complicated) solution:
int32 iTicketOrError =
CallProcedureEx(
"TargetName",
"PathToProcedure.MoveXAxis(0.1234:d)");
...
if( iTicketOrError < 0 ) {
}
}
Another possiblity to do the same (but even more complicated): int32 iTicketOrError =
CallProcedureEx(
"TargetName",
"PathToProcedure.MoveXAxis(0.1234:d)");
...
...
...
}
}
- Start move and check whether moving the axis succeeded or failed - wait for the result using a timeout:
int32 uTimeoutMs = 5000;
int32 iTicketOrError =
CallProcedureEx(
"TargetName",
"PathToProcedure.MoveXAxis(0.1234:d)");
if( iTicketOrError < 0 ) {
...
}
}
else
{
}
}
Strange (but valid) usage
- Start move and wait until finished (or failed) - but don't check whether the move succeeded or failed:
int32 iTicketOrError =
CallProcedureEx(
"TargetName",
"PathToProcedure.MoveXAxis(0.1234:d)");
if( iTicketOrError < 0 ) {
}
} else {
}
This use case is considered to be strange because the application should normally be interested in handling errors. Moreover, if the application really doesn't care about errors, MoveXAxis() should better be implemented to not return a ticket by changing the return type to 'void'. Like this it'd obvious that the function is just "fire'n'forget". When too many calls like this are done, the results that were sent by the target but never picked up by the application accumulate in libinco_32 and will eventually fill up the buffer used to store them. When that happens, to avoid unbounded memory usage, libinco_32 will start to drop the oldest stored results to make space for new ones when they arrive. This is accompanied by a warning printed to stderr.
- Start move but don't wait for any result (fire'n'forget):
int32 iTicketOrError =
CallProcedureEx(
"TargetName",
"PathToProcedure.MoveXAxis(0.1234:d)");
if( iTicketOrError > 0 ) {
}
This use case is considered to be strange because the application should normally be interested in handling errors. Moreover, if the application really doesn't care about errors, MoveXAxis() should better be implemented to not return a ticket by changing the return type to 'void'. Like this it'd obvious that the function is just "fire'n'forget". When too many calls like this are done, the results that were sent by the target but never picked up by the application accumulate in libinco_32 and will eventually fill up the buffer used to store them. When that happens, to avoid unbounded memory usage, libinco_32 will start to drop the oldest stored results to make space for new ones when they arrive. This is accompanied by a warning printed to stderr.
- Waiting multiple times for the same async procedure:
int32 iTicketOrError =
CallProcedureEx(
"TargetName",
"PathToProcedure.MoveXAxis(0.1234:d)");
if( iTicketOrError < 0 ) {
uint32 uError;
...
} else {
}
The code above waits twice for the same procedure to have finished it's asynchronous part. Doing so is not forbidden (but probably doesn't makes any sense either).
Forbidden/invalid usage
- It's not possible to get the same result multiple times. Therefore, in the following use case, the second call to CallProcedureExResult() will for sure return an error:
int32 iTicketOrError =
CallProcedureEx(
"TargetName",
"PathToProcedure.MoveXAxis(0.1234:d)");
if( iTicketOrError < 0 ) {
uint32 uError;
}