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:

  1. The (old) Serial Manager: This supports the cradle port only, but is available in all OS versions from 3.0 upwards.
  2. 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.

Port IDs

To open a serial port, you have to specify its id. There are the following possibilities (taken from the PalmOS SDK docs): 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

close-serial new-serial? open-serial serial-get-cts serial-get-timeout
serial-info serial-input serial-output serial-receive-flush serial-send-flush
serial-set-break! serial-set-cts! serial-set-irda! serial-set-rx! serial-set-timeout!
serial-status serial?