Shop OBEX P1 Docs P2 Docs Learn Events
Uart.byteAvailable question: what happens to the byte you just read from it. — Parallax Forums

Uart.byteAvailable question: what happens to the byte you just read from it.

steve_bsteve_b Posts: 1,563
edited 2005-01-30 17:03 in General Discussion
Hey folks,

we wondering, when you do a:
if(rxUart.byteAvailable()){
······· Rx_in = (char)rxUart.receiveByte();
······· buffer.append(Rx_in); }

What happens in the rxUart buffer?!· Does it remove the byte you read and move all the other bytes up one?· Or is there some sort of array constructed and each call to byteAvailable just moves you to the next array slot?

also...what does the 'buffer.append' routine do?· And while I'm at it....buffer.clear too!

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·

Steve
http://members.rogers.com/steve.brady
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."

Comments

  • ZaggyZaggy Posts: 10
    edited 2005-01-30 16:18
    Steve,

    Since you helped me, I figured I would return the favor. I looked through the code and the receiveByte method has a 2 byte buffer and yes it does move to the next slot.

    As for the Stringbuffer , the append manages an array of chars and if the Stringbuffer needs to grows it throws away the old char array, which is an Object. The Clear method just resets the pointer to 0.

    Joe
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-01-30 17:03
    The uart class as provided by Parallax uses a buffer of 128 ints for each

    uart. Each buffer has a head pointer (store incoming bytes) and a tail

    pointer (read stored bytes). The buffer is empty if tailpointer == headpointer.

    (hence only 255 bytes can be stored). The byteAvailable() method checks

    wether tailponter != headpointer to see if there are any bytes in the buffer.

    The receiveByte() method reads the character pointed to by tailpointer

    and then increments tailpointer. The int holding the requested byte

    is read from the buffer, and then extra code is used to determine wether

    the low byte or highbyte must be returned.



    I have an adapted uart class here

    http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/core/

    in which I have redefined the buffer to be a public char array and thus

    the extra code is not required (speeds up access). This class also supports

    parity by use of the UartTools class (also at the above link).

    Furthermore this class has definitions dirTransmitStop and dirReceiveStop

    that allow for Uart definitions while not starting the Uart. (I use that

    when I have more than 5·Uarts so I must switch between them).

    If you want to use that adapted class, rename your current Uart.java

    to Uart_parallax.java and download Uart.java and UartTools.java from

    the link above to your lib/stamp/core directory.



    regards peter
Sign In or Register to comment.