UNIX Serial I/O

You can generally treat serial ports as sequential files under UNIX, opening them for either INPUT or OUTPUT (or both) as shown below:

open #1, "/dev/tty1a", output

open #2, "/dev/tty1a", input

Once open, you can use the normal PRINT or INPUT statements, although they may not work exactly as you might expect due to the large number and complexity of configurable parameters which affect serial port operations under UNIX. The typical method of setting these parameters (after opening the port) is to use HOSTEX.SBR to invoke the UNIX stty (or equivalent) command. (Refer to the UNIX "man" page or other documentation for further details on serial port settings, a subject which exceeds the scope of this discussion.)

Note that if you are going to use the xcall HOSTEX, "stty..." approach, you must do so after you open the port. Otherwise your changes may be lost when the port is opened.

To output to the port, you can use the PRINT command. Beware, however, that under the UNIX default buffering scheme, the characters may not be "flushed" to the device until a line terminator is output. To input, you can use INPUT or INPUT LINE, but here the subtleties of the port parameters can cause considerable confusion. For character-oriented, rather than line-oriented input, use GET.SBR.

You can turn off output buffering on UNIX or Linux devices by opening the device as an output file and then executing xcall MIAMEX,MX_NOBUF,87,CH where CH is the file channel. Similarly, you can use xcall MIAMEX,MX_FLUSHBUF,8,CH to immediately flush any buffered characters on that channel.

You can do character-level input from a serial port using GET.SBR:

xcall GET, buf, chan, bytes'req, bytes'rcv, timeout

For a more sophisticated approach for serial communications, contact Soft Machines (www.softmach.com) for information on their AutoLog communications package, which, among other wonderful features, includes a subroutine interface from A-Shell. Under Windows, there is also the COMIO.SBR which offers capabilities somewhere in the middle between simple file-oriented I/O and the full feature set of AutoLog.