Shop OBEX P1 Docs P2 Docs Learn Events
In one UART, out another. — Parallax Forums

In one UART, out another.

RShirleyRShirley Posts: 12
edited 2005-10-04 16:53 in General Discussion
Hi folks,

I have been trying to get caracters out of one UART, parse and format them, and send them out another UART with no success. The toString always causes me to run out of memory. Any suggestions on how best to do this. The input is time/date from a GPS unit, in ASCII ("09252005011200.000"). I want to sent to a LCD display "09/25/2005, 01:12:00.000".

Thanks, Russell

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-09-26 16:48
    Here is a convert routine

    char[noparse]/noparse buf = new char[noparse][[/noparse]25];
    int index;
    // input· 18 chars 09252005011200.000
    // output 24 chars 09/25/2005, 01:12:00.000
    //·················· 2· 5··· 9·· D· G
    //assume start of message
    index = 0;
    while (index < 24) {
    · while (!rx.byteAvailable()) {
    ··· //do other stuff
    · }
    · buf[noparse][[/noparse]index++] = rx.receiveByte();
    · switch (index) {
    ··· case 2:
    ··· case 5:· buf[noparse][[/noparse]index++] = '/';
    ············ break;
    ··· case 9:· buf[noparse][[/noparse]index++] = ',';
    ············ buf[noparse][[/noparse]index++] = ' ';
    ············ break;
    ··· case 13:
    ··· case 16: buf[noparse][[/noparse]index++] = ':';
    ············ break;
    ··· default:
    · }
    }
    buf[noparse][[/noparse]24] = 0; //closing zero, optional
    tx.writeString(buf,24,0); //write char array, 24 bytes, start at offset 0

    regards peter



    Post Edited (Peter Verkaik) : 9/26/2005 4:48:47 PM GMT
  • RShirleyRShirley Posts: 12
    edited 2005-09-26 19:37
    Peter

    I get an error on the line "buf[noparse][[/noparse]index++] = rx.receiveByte();"
    Left hand "char" not compatible with right hand "int".

    What did I do wrong?

    Thanks, Russell
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-09-26 20:33
    You need to cast

    buf[noparse][[/noparse]index++] = (char)rx.receiveByte();

    regards peter
  • RShirleyRShirley Posts: 12
    edited 2005-10-04 16:53
    Peter,

    I finally got my project complete and functional. Thanks for all your help on this and other troubles i have had.

    Russell
Sign In or Register to comment.