Serial ports Isis software documentation

Serial ports

This document explains the routines for configuring terminal attributes and doing RS-232 serial communication in Isis.


Opening and initializing a serial port

(initialize-serial-port port baud databits stopbits parity flow) In Unix, you can open a serial port on your machine for reading and writing simply by opening a file in the "/dev" directory of the filesystem using the Isis open- routines. Usually, the first serial port on your computer will correspond to the file name "/dev/ttyS0", and the second will be "/dev/ttyS1", and so on, but check with your system administrator if you are unsure.

After you open the file, you can initialize the RS-232 attributes of the port using initialize-serial-port. The port argument should be the newly-obtained Isis port that connects to that serial port. baud should be an integer baud rate (only standard baud rates are allowed, so check what your computer is capable of). databits should be an integer number of data bits, and stopbits should be the number of stop bits. parity should be Null for no parity, the string "even" for even parity, or "odd" for odd parity. Finally, flow should be either True or False indicating whether RTS-CTS flow control should be used.

The following example opens the serial port for reading and writing, and then configures it for 9600 baud, 8 data bits, 1 stop bit, no parity, and no flow control.

(set sport (open-update "/dev/ttyS0")) (initialize-serial-port sport 9600 8 1 Null False)


Other terminal control routines

(send-break port milliseconds) (drain port) (get-tty-mode port) (set-tty-mode port iflags oflags cflags lflags ispeed ospeed) send-break sends a break condition to the terminal connected to port for the specified number of milliseconds. drain waits for all pending output to the given terminal to be transmitted and then returns True if successful.

get-tty-mode and set-tty-mode are very similar to the C routines tcgetattr and tcsetattr. However, the initialize-serial-port routine described above should be satisfactory for almost all RS-232 applications. If you need to use these functions for more control, please read the termios man page before doing so.

get-tty-mode returns the terminal attributes associated with the given file handle as a list of 6 integers [iflags oflags cflags lflags ispeed ospeed]. set-tty-mode sets the values of these attributes.

iflags, oflags, cflags, and lflags are all bit-fields whose values are obtained by bit-or-ing together the constants listed below. ispeed and ospeed should be integer baud rates that are supported by your machine. For explanations on the meaning of each constant, see the termios man page.

Constants for use in iflags (input attributes):

tty-ignbrk tty-brkint tty-ignpar tty-parmrk tty-inpck tty-istrip tty-inlcr tty-igncr tty-icrnl tty-iuclc tty-ixon tty-ixany tty-ixoff Constants for use in oflags (output attributes): tty-opost tty-olcuc tty-onlcr tty-ocrnl tty-onocr tty-onlret tty-ofill tty-ofdel tty-nldly tty-nl0 tty-nl1 tty-crdly tty-cr0 tty-cr1 tty-cr2 tty-cr3 tty-tabdly tty-tab0 tty-tab1 tty-tab2 tty-tab3 tty-bsdly tty-bs0 tty-bs1 tty-vtdly tty-vt0 tty-vt1 tty-ffdly tty-ff0 tty-ff1 Constants for use in cflags (control attributes): tty-crtscts tty-csize tty-cs5 tty-cs6 tty-cs7 tty-cs8 tty-cstopb tty-cread tty-parenb tty-parodd tty-hupcl tty-clocal Constants for use in lflags (local attributes): tty-isig tty-icanon tty-xcase tty-echo tty-echoe tty-echok tty-echonl tty-noflsh tty-echoctl tty-echoprt tty-echoke tty-flusho tty-pendin tty-iexten tty-tostop