Example #1
0
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;
}
Example #2
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;
}
Example #3
0
int CKMotionIO::ReadLineTimeOut(char *buf, int TimeOutms)
{
	int result;
	bool Done;

	do 
	{
		Done=true;
		result = ReadLineTimeOutRaw(buf, TimeOutms);
		
		if (result==0)
		{
			// check if first char is an ESC

			if (buf[0] == 0x1b)
			{
				// it is!  
				
				// if next character is 1, 2, or 3
				// handle it as a write file command
				
				if (buf[1] >=1 && buf[1] <=3)
				{
					// it is a disk command
					HandleDiskIO(buf+1);
				}
				else
				{
					// Send to console
					LogToConsole(buf+1);
				}
				
				Done=false;
			}
		}
	}
	while (!Done);

	return result;
}
Example #4
0
int CKMotionIO::CheckForReady()
{
	char buf[257];
	char *beg;
	char copy[257];
	int nbytes, result;
	bool DetectedError=false;

	for (;;) 
	{
		if (m_Connected)
		{
			if (!NumberBytesAvailToRead(&nbytes, true) && nbytes>0)
			{
				result = ReadLineTimeOutRaw(buf, 100);
				
				if (result==0)
				{
					
					// check if first char is an ESC

					if (buf[0] == 0x1b)
						beg=buf+1;
					else
						beg=buf;
				
					strncpy(copy,beg,255);
					_strupr(copy);

					// check for "Error"
					if (strstr(copy,"ERROR")!=NULL)
					{
						// error, send to console

						DetectedError=true;
					}
					
					
					// check for "Ready"
					if (strcmp(beg,"Ready\r\n"))  
					{
						// no, strange send to console

						LogToConsole(beg);
					}
					else
					{
						// yes! send to console and return Ready

						LogToConsole(beg);
						if (DetectedError)
							return KMOTION_ERROR;  // a line contained the word "error"
						else
							return KMOTION_READY;  
					}
				}
				else
				{
					return KMOTION_TIMEOUT;  // not a whole line for some reason
				}
			}
			else
			{
				return KMOTION_OK;  // no data, return OK, not Ready
			}
		}
		else
		{
			return KMOTION_ERROR;  // not connected return error
		}
	}

	return result;
}