244
Platforms
©2000-2008 Tibbo Technology Inc.
dim
s
as
string
s =
"This is a long string waiting to be sent. Send me already!"
sub
on_button_pressed
ser.notifysent(ser.txbuffsize-len(s))
' causes the on_ser_data_sent
event to fire when the tx buffer has space for our string
end
sub
sub
on_ser_data_sent
ser.setdata(s)
' put data in tx buffer
ser.send
' start sending it.
end
sub
When we press the button,
event is generated, so now the
system knows we have a string to send. Using
we make the
event when the necessary amount of free
space becomes available. This event will only be fired once -- and will be fired
immediately if there is already enough available space.
Within the on_ser_data_sent event handler we put the data in the TX buffer and
start sending it.
Amount of data that will trigger on_ser_data_sent does not include
uncommitted data in the TX buffer.
Handling Buffer Overruns
Handling RX buffer overruns
is generated when an RX buffer overrun has
occurred. It means the data has been arriving to the UART faster than you were
handling it and that some data got lost.
This event is generated just once, no matter how much data is lost. A new event
will be generated only after exiting the handler for the previous one. In the UART/
full-duplex mode (see
for details) you can typically prevent this
from happening by using the flow control (
).
Typically, the user of your system wants to know when an overrun has occurred.
For example, you could blink a red LED when this happens.
sub
on_ser_overrun
pat.play(
"R-R-R-R"
)
end
sub
Are TX buffer overruns possible?
TX buffer overruns are not possible. The serial port won't let you overload its TX
buffer. If you try to add more data to the TX buffer than the free space in the
buffer allows to store then the data you are adding will be truncated.
See
for explanation on how to TX data correctly.
273
257
258
259
226
253
243