Society of Robots - Robot Forum

Software => Software => Topic started by: Cornelam on January 02, 2009, 04:12:42 PM

Title: Axon Uart question
Post by: Cornelam 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!   
Title: Re: Axon Uart question
Post by: mbateman 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;
        }
    }
}
Title: Re: Axon Uart question
Post by: Cornelam on January 02, 2009, 08:39:50 PM
Thank you very much!
I thought about this but never found time to try it.