Using openport

The openport script is a generic script, written in the UNIX operating system shell script language. This language has built-in default stty modes that will initialize the serial port. The script is meant to run as a background process. Because it is generic, all of the default options it uses may not be valid on a particular operating system. An example of the openport script is listed below. Check all stty options against the UNIX stty documentation if problems occur using this script.

When used in conjunction with a port-to-port conversion, openport is invoked as a background job before entering PRO/5. It requires a port name and possibly some stty options such as:

openport /dev/tty11 1200 &

The openport script has built-in some default stty modes for most conversion requirements. Additional stty options given by you when openport is invoked may override the built-in options. This script will open the specified port, perform an initial stty call to set various modes, and then keep the port open. Keeping the port open is important because the UNIX operating system may set the port back to a default state when the port is closed. Once openport is invoked, the modes may be adjusted further on the desired port with additional stty commands such as:

stty -parodd </dev/tty01

It is not necessary to modify openport and restart it.

# openport
#
(
usage="usage: openport /dev/ttyxx {stty args}"
default="9600 -echo -inlcr -icrnl -igncr -opost ixon
 ixoff -ixany -xcase -icanon"
# see what the return value is from a good stty (XENIX
 bug)
good=`stty -echo ; stty echo ; echo $?`
# save the current tty modes and see how to set minimum
 timeout
STTY=`stty -g`
TIMEOUT='min 1 time 0'
stty $TIMEOUT
if [ "$?" != "$good" ]
then
TIMEOUT="eof '^a' eol '^a'"
stty $TIMEOUT
if [ "$?" != "$good" ]
then
TIMEOUT="eof ^a eol ^a"
stty $TIMEOUT
if [ "$?" != "$good" ]
then
echo "I can't figure out how to do the stty"
exit 1
fi
fi
fi
stty $STTY
# OK, let's do it
if [ "$1" ]
then
device=$1; shift
if [ -c $device ]
then
(
stty $default $TIMEOUT $@
if [ "$?" = "$good" ]
then
while true
do
sleep 30
done
else
echo "openport: bad stty arg"
echo "stty " $default $@
exit 1
fi
) < $device
else
echo "openport: $device not serial"
exit 1
fi
else
echo "openport: no arguments"
echo "$usage"
exit 1
fi
) < /dev/tty