go_away

Author Topic: Axon Uart question  (Read 1544 times)

0 Members and 1 Guest are viewing this topic.

Offline CornelamTopic starter

  • Jr. Member
  • **
  • Posts: 24
  • Helpful? 0
  • I can smell a robot from a mile away
Axon Uart question
« on: January 02, 2009, 04:12:42 PM »
Happy new year folks!  ;D
I'm building a computer-controlled robot (again) and i can't find a way to receive a command bigger then 1 byte.
For example until now i have used "w" together with the uartGetByte() function to make my robot go forwards.
But if i want to use "forwards" as a command? Is there any function that can return more then 1 byte of data form the UART?
Thanks in advance!   

Offline mbateman

  • Full Member
  • ***
  • Posts: 82
  • Helpful? 0
Re: Axon Uart question
« Reply #1 on: January 02, 2009, 04:37:58 PM »
If you teminate all your commands with some character such as \r or \n, then you can loop on the uartGetByte and save the bytes in an array of characters until you receive the end character. Then use the character array as a string to see the result.
Code: [Select]
char result[255];
uint8_t getLine() {
    char temp;
    uint8_t len=0;
    while(1) {
        temp=uart2GetByte();     // Returns -1 if nothing read
        if (temp=='\r') {
            result[len]='\0';           // Null terminate string
            return len;                  // Return the length of the string
        } else if (temp != -1) {
           result[len++]=temp;
        }
    }
}

Offline CornelamTopic starter

  • Jr. Member
  • **
  • Posts: 24
  • Helpful? 0
  • I can smell a robot from a mile away
Re: Axon Uart question
« Reply #2 on: January 02, 2009, 08:39:50 PM »
Thank you very much!
I thought about this but never found time to try it.
 

 


Get Your Ad Here