Back to index
LispMe serial port access
Please read the
PalmOS documentation
describing many details of the Pilot's user interface, event and resource
system. This chapter shows the Scheme aspect only.
LispMe supports accessing the Palm's serial ports via standard
Scheme ports. The API is very similar to the
socket library, e.g., there is a new foreign
datatype serial with associated operations and two functions
to retrieve its input and output port used by display, read
etc.
Successful tests included communication with a PC terminal program via the
cradle (RS-232) port at various baud rates upto 115200 and controlling
my Meade LX200 telescope also via RS-232.
Connecting two Palms via IRComm
worked, too (use the 'ircm' port id for this), but I couldn't
test USB connections yet.
Unfortunately, PalmOS uses two different set of functions for
the serial port:
- The (old) Serial Manager: This supports the cradle port only, but
is available in all OS versions from 3.0 upwards.
- The New Serial Manager: This supports all kinds of serial ports
(including RS232, IrDA, USB), but
is available only in OS versions from 3.3 upwards.
Since I don't know the shares of the different OS versions, LispMe
supports both methods. Use
new-serial? to
see if your Palm supports the New Serial Manager.
To open a serial port, you have to specify its id. There are the
following possibilities (taken from the PalmOS SDK docs):
- Logical port IDs:
- #x8000 Cradle port, auto-detect cradle type
- #x8001 IR port
- #x8002 Console port (PalmOS 4.0)
- #x8003 Cradle RS232 port (PalmOS 4.0)
- #x8004 Cradle USB port (PalmOS 4.0)
- #x800n reserved for future types
- Physical port IDs:
- 'u328' cradle port using the 68328 UART
- 'u650' IR port on upgraded Palm III
- 'ircm' IRComm virtual port
(You can use buf-get-u32
to convert those 'wide character literals' to the UInt32
expected by open-serial, e.g. (buf-get-u32 "u328" 0))
I'm not quite happy with the current method of specifying the
port by the low-level id. Suggestions?
Writing
Use the standard procedures display, write, and
newline with the optional output port argument. The
output port for a serial device can be retrieved by
serial-output.
Reading
Use the standard procedures read, read-char, and
read-line with the input port argument. The
input port for a serial device can be retrieved by
serial-input.
Data is read from the port until the item to be read is complete, e.g.,
when using read until a complete SEXPR is read or when using
read-line until a linefeed character is read. When the receive
buffer is empty, but the item to be read is not yet complete, LispMe
waits for serial-get-timeout
ticks for further data to arrive. If no data arrives in time,
end-of-file is assumed and the current read operation interprets
the data read upto now. Further reads will return [eof] until
new data has arrived.
Pickling and unpickling
When a session is pickled,
all open serial devices are
closed, so that other sessions or application can use the serial ports,
too. When the session is unpickled later, the serial ports are
reopened using the parameters stored with the pickled data. This
method works surprisingly well for the simple serial protocol.
Associated language elements