int CKMotionIO::ServiceConsole() { int nbytes, timeout; char b[MAX_LINE]; if (KMotionLock() == KMOTION_LOCKED) // quick check if it is available { if (!NumberBytesAvailToRead(&nbytes, false) && nbytes>0) { // some data in the buffer timeout = ReadLineTimeOutRaw(b,100); if (!timeout) { if (b[0]==0x1b) // skip over esc if there is one LogToConsole(b+1); else LogToConsole(b); } } ReleaseToken(); } return 0; }
int CKMotionIO::ServiceConsole() { int nbytes; int timeout; char buf[MAX_LINE]; if (KMotionLock() == KMOTION_LOCKED) // quick check if it is available { //if (!NumberBytesAvailToRead(&nbytes, false) && nbytes>0) //Instead of making one call with a long time out we first make a call with a short time out, //if data is read we need to check if we had a timeout and ask again with a greater value. timeout = ReadLineTimeOutRaw(buf,0); // likely we will get a timeout sometimes nbytes = strlen(buf); if(nbytes>0) { // some data in the buffer if(timeout){ //if previos call timed out we can try again with a longer timout adding read bytes to buffer pointer timeout = ReadLineTimeOutRaw(buf + nbytes ,100); } if (!timeout) { if (buf[0]==0x1b) // skip over esc if there is one LogToConsole(buf+1); else LogToConsole(buf); } } ReleaseToken(); } return 0; }