236
Platforms
©2000-2008 Tibbo Technology Inc.
sub
on_sys_init
' This is always the first event executed.
ser.num =
0
' Supposedly, this would make all subsequent properties and
methods refer to this port.
end
sub
sub
on_ser_data_arrival
' Then, supposing this event executes.
dim
s
as
string
s = ser.getdata(
255
)
' However, this event happens on the second port. So
now ser.num = 1.
end
sub
sub
on_sock_data_arrival
' And then this socket event executes.
ser.txclear
' You meant to do this for ser.num = 0 (as specified at
on_sys_init). But now port.num was changed to 1. You did not explicitly
specify a ser.num here, and now the tx buffer for the wrong port is
cleared. Oops.
end
sub
Same precautions should be taken when using
. This is because
doevents will let other events execute and so serial object events will potentially
execute and cause the ser.num to change.
To recap, only one of two things may change the current ser.num: (1) Manual
change or (2) a serial port event. And you cannot assume the number has
remained unchanged if you set it somewhere else (because a serial port event
might have happened since).
Specifying a port number for a single-port platform may seem
redundant, but it makes your program portable. You will have an easier
time migrating your program to a multi-port platform in the future.
Serial Settings
This topic briefly outlines the range of configurable options available on the serial
port (this does not include the bulk of data on RX and TX buffers, which are
described
).
Opening and closing the serial port
property defines whether the port is opened or closed. The port
is closed by default, so you need to open it explicitly. The serial port won't receive
or transmit the data when it is closed, but you will still be able to access its RX and
TX buffers even at that time.
Serial port lines remapping
Depending on your platform, you may or may not be allowed to remap RTS/
W0out/cout output and CTS/W0&1in/cin input, i.e. choose what I/O pins of the
device these lines should be on. See "Platform-dependent Programming
Information" topic inside your platform specifications section. If your device
supports remapping, you can use
and
properties to
68
239
251
249
261