238
Platforms
©2000-2008 Tibbo Technology Inc.
Outgoing data uses similar "data committing" concept as the incoming data. The
objective is to be able to commit the data for sending once, even if the data was
prepared bit by bit. This way your application can avoid sending out data in small
chunks.
topic details this.
UART mode settings
Several settings are unique to
mode. The serial port has all the usual
UART-related communication parameters:
,
.
There is no property to select the number of stop bits. Second stop bit can be
emulated by setting ser.parity= 3- PL_SER_PR_MARK.
The baudrate property actually keeps a divisor value. You can set any baudrate
you want by providing the correct divisor. There is even a read-only
property that allows you to calculate the divisor value in a platform-independent
way, by returning the required divisor value (for the current platform) to reach
9600bps.
The actual baudrate is calculated as follows: baudrate=(9600*ser.div9600)/ser.
baudrate. For example, if we need to achieve 38400bps and ser.div9600 returns
12, then we need to set ser.baudrate=3, because (9600*12)/38400=3. This serves
as a platform-independent baudrate calculation, as ser.div9600 will return different
values for different platforms.
For example:
function
set_baud(baud
as
integer
)
as
integer
'baud: 0- 1200, 1-2400, 2-4800, 3- 9600, 4-19200, other-38400
select
case
baud
case
0
: ser.baudrate=ser.div9600*
8
'9600/1200=8
case
1
: ser.baudrate=ser.div9600*
4
'9600/2400=4
case
2
: ser.baudrate=ser.div9600*
2
'9600/4800=2
case
3
: ser.baudrate=ser.div9600*
8
'9600/9600=1
case
4
: ser.baudrate=ser.div9600/
2
'19200/9600=2
case
else
: ser.baudrate=ser.div9600/
4
'38400/9600=4
end
function
The serial port can be used in full-duplex or half-duplex mode, as determined by
the
for details). In the full-duplex
mode, the serial port can optionally use the
. in the half-duplex
of the direction control signal.
In the UART mode, the serial port can recognize so-called 'escape sequences'. They
are defined using the
and
properties.
When such a sequence is recognized, a special event (
) is generated
and the port is disabled. Of course this can be achieved programmatically, but it
would require you to parse all incoming data and really slow things down. Escape
sequences were implemented with efficiency and speed in mind.
Escape sequences are rather arbitrary. They follow the style of escape sequences
that Tibbo introduced before. However, they are useful for certain things. For
example , if your application has a normal mode and serial 'setup' mode, you can
use this sequence to switch into setup mode.
Escape sequence will work even if you are using
, and that makes
them especially powerful. If you are building a device which just routes the data
between a serial interface and an Ethernet interface, you will use buffer shorting
for performance, but you could still detect the escape sequences to switch into the
240
226
248
260
249
250
255
226
253
250
251
251
259
245