Uart.byteAvailable question: what happens to the byte you just read from it.
steve_b
Posts: 1,563
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."
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
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
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