go_away

Author Topic: Webbotlib uartGetByte(UART) difference to Axon Source Code  (Read 947 times)

0 Members and 1 Guest are viewing this topic.

Offline klimsTopic starter

  • Robot Overlord
  • ****
  • Posts: 188
  • Helpful? 2
Webbotlib uartGetByte(UART) difference to Axon Source Code
« on: November 16, 2010, 03:21:26 PM »
Hey guys,

I have had some strange behaviour when using the webbotlib and uartGetGyte(UART) with a buffer. Check out the code below:
Code: [Select]
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:
Code: [Select]
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?
« Last Edit: November 18, 2010, 03:27:51 AM by klims »

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,136
  • Helpful? 109
Re: Webbotlib uartGetByte(UART) bug?
« Reply #1 on: November 17, 2010, 04:39:49 AM »
I'm guessing your problem is that you are storing the result of uartGetByte straight into the remoteCommand arrary. You are then testing the value from the array rather than the return from uartGetByte. eg if 'remoteCommand' is defined as an array of 'uint8_t' or 'char' then thats the problem as they are both unsigned. So if uartGetByte returns -1 then you are storing 0xFF in the remoteCommand array. This will never equal -1 as its now an unsigned number ie 255.

So I would change the code to check the return value from uartGetByte:-
Code: [Select]
int nextByte = uartGetByte(blueUART);
while(nextByte != -1){
    remoteCommand[i] = nextByte;
    rprintf("i:%d ",i);
    i++;
    nextByte = uartGetByte(blueUART);
}
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline klimsTopic starter

  • Robot Overlord
  • ****
  • Posts: 188
  • Helpful? 2
Re: Webbotlib uartGetByte(UART) bug?
« Reply #2 on: November 18, 2010, 03:25:20 AM »
Right as usual Webbot  :)

I had taken my bit of code from something written using Admin's original libraries a while back. I'll try to change the thread description to match.


thanks guys
« Last Edit: November 18, 2010, 03:28:42 AM by klims »

 


Get Your Ad Here

data_list