Hey guys,
I have had some strange behaviour when using the webbotlib and uartGetGyte(UART) with a buffer. Check out the code below:
if(!uartReceiveBufferIsEmpty(blueUART))
{
rprintf("i:%d ", i);
remoteCommand[i] = uartGetByte(blueUART);
if(remoteCommand[i] != -1)
{
rprintf("i:%d ", i);
while( (remoteCommand[i] != -1) )
{
rprintf("i:%d ", i);
i++;
remoteCommand[i] = uartGetByte(blueUART);
//remoteCommand[i] = uart1GetByte();
}
rprintf("i:%d ", i);
}
else
uartFlushReceiveBuffer(blueUART);
rprintf("i:%d ", i);
}
I found that my program would get stuck in an endless while loop because uartGetByte(UART) will never return -1.
After a while of stuffing around I came up with this working bit of code:
if(!uartReceiveBufferIsEmpty(blueUART))
{
rprintf("i:%d ", i);
remoteCommand[i] = uartGetByte(blueUART);
if(remoteCommand[i] != -1)
{
rprintf("i:%d ", i);
while( !uartReceiveBufferIsEmpty(blueUART) )
{
rprintf("i:%d ", i);
i++;
remoteCommand[i] = uartGetByte(blueUART);
//remoteCommand[i] = uart1GetByte();
}
rprintf("i:%d ", i);
}
else
uartFlushReceiveBuffer(blueUART);
rprintf("i:%d ", i);
}
As you can see I tried both uartGetByte(UART) and uart1GetByte() and neither returns -1. Has anyone else had this problem?