241
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
You can also find out how much committed data the RX buffer currently contains
with the
property (see
for explanation of what
committed data is).
Sometimes you need to clear the RX buffer without actually extracting the data. In
such cases the
comes in handy.
The TX buffer
Similarly to the RX buffer, the TX buffer also has a
property which
lets you discover its capacity.
Unlike the RX buffer, the TX buffer has two "data length" properties:
and
. The txlen property returns the amount of committed data
waiting to be sent from the buffer (you commit the data by using the
method). The newtxlen property returns the amount of data which has entered the
buffer, but has not yet been committed for sending.
property, which directly tells you how much
space is left in it. This does not take into account uncommitted data in the buffer --
actual free space is ser.txfree-ser.newtxlen!
ser.txlen + ser.txfree = ser.txbuffsize.
When you want to clear the TX buffer without sending anything, use the
method.
An example illustrating the difference between ser.txlen and ser.newtxlen:
sub
on_sys_init
dim
x,y
as
word
' declare variables
ser.rxbuffrq(
1
)
' Request one page for the rx buffer.
ser.txbuffrq(
5
)
' Request 5 pages for the tx buffer (which we will use).
sys.buffalloc
' Actually allocate the buffers.
ser.setdata(
"foofoo"
)
' Set some data to send.
ser.setdata(
"bar"
)
' Some more data to send.
ser.send
' Start sending the data (commit).
ser.setdata(
"baz"
)
' Some more data to send.
x = ser.txlen
' Check total amount of data in the tx buffer.
y = ser.newtxlen
' Check length of data not yet committed. Should be 3.
end
sub
'Set up a breakpoint HERE.
Don't step through the code. The sending is fast -- by the time you reach x and y
by stepping one line at a time, the buffer will be empty and x and y will be 0. Set a
breakpoint at the end of the code, and then check the values for the variables (by
using the
).
Receiving Data
In a typical system, there is a constant need to handle an inflow of data. A simple
approach is to use polling. You just poll the buffer in a loop and see if it contains
any data, and when fresh data is available, you do something with it. This would
look like this:
263
236
263
266
267
256
264
266
266
33