240
Platforms
©2000-2008 Tibbo Technology Inc.
Using Buffers
Once you have allocated memory for the TX and RX buffers you can start sending
and receiving data through them.
Sending Data (through TX buffer)
Sending data is a two-step process. First, you put the data in the TX buffer using
the
method, and then you perform the actual sending (commit the
data) using the
method. For example:
ser.setdata (
"Foo"
)
' Placed our data in the TX buffer - not being sent
out yet.
' ... more code...
ser.setdata (
"Bar"
)
' Added even more data to our buffer, waiting to be
sent.
ser.send
' Now data will actually start going out. Data sent will be
'FooBar'.
Since this is a two-step process, you may first prepare a large block of data in the
TX buffer and only then commit this data (this may come handy in some
applications).
TiOS features non-blocking operation. This means that on ser.send, for
example, the program does not halt and wait until the data is
completely sent. In fact, execution resumes immediately, even before
the first byte goes out. Your program will not freeze just because you
ordered it to send a large chunk of data.
Receiving Data (through RX buffer)
Receiving data is a one-step process. To extract the data from a buffer, use the
method. Data may only be extracted once from a buffer. Once
extracted, it is no longer in the buffer. For example:
dim
whatigot
as
string
whatigot = ser.getdata(
255
)
The variable whatigot now contains up to 255 bytes of data which came from the
TX buffer of the serial port.
Buffer Memory Status
You cannot effectively use a buffer without knowing what its status is. Is it
overflowing? Can you add more data? etc. Thus, each of the serial buffers has
certain properties which allow you to monitor it:
The RX buffer
You can check the total capacity of the buffer with the
property.
264
264
253
262