in which the device is one of the serial devices, such as ttyS0.
The setserial command has a large number of parameters. The most common of these are described in Table 4.1. For information on the remainder of the parameters, you should refer to the setserial manual page.
Table 4.1: setserial Command-Line Parameters
Parameter Description | |
---|---|
port port_number | Specify the I/O port address of the serial device. Port numbers should be specified in hexadecimal notation, e.g., 0x2f8. |
irq num | Specify the interrupt request line the serial device is using. |
uart uart_type | Specify the UART type of the serial device. Common values are 16450, 16550, etc. Setting this value to none will disable this serial device. |
fourport | Specifying this parameter instructs the kernel serial driver that this port is one port of an AST Fourport card. |
spd_hi | Program the UART to use a speed of 57.6 kbps when a process requests 38.4 kbps. |
spd_vhi | Program the UART to use a speed of 115 kbps when a process requests 38.4 kbps. |
spd_normal | Program the UART to use the default speed of 38.4 kbps when requested. This parameter is used to reverse the effect of a spd_hi or spd_vhi performed on the specified serial device. |
auto_irq | This parameter will cause the kernel to attempt to automatically determine the IRQ of the specified device. This attempt may not be completely reliable, so it is probably better to think of this as a request for the kernel to guess the IRQ. If you know the IRQ of the device, you should specify that it use the irq parameter instead. |
autoconfig | This parameter must be specified in conjunction with the port parameter. When this parameter is supplied, setserial instructs the kernel to attempt to automatically determine the UART type located at the supplied port address. If the auto_irq parameter is also supplied, the kernel attempts to automatically determine the IRQ, too. |
skip_test | This parameter instructs the kernel not to bother performing the UART type test during auto-configuration. This is necessary when the UART is incorrectly detected by the kernel. |
A typical and simple rc file to configure your serial ports at boot time might look something like that shown in Example 4.1. Most Linux distributions will include something slightly more sophisticated than this one.
Example 4.1: Example rc.serial setserial Commands
# /etc/rc.serial - serial line configuration script.
#
# Configure serial devices
/sbin/setserial /dev/ttyS0 auto_irq skip_test autoconfig
/sbin/setserial /dev/ttyS1 auto_irq skip_test autoconfig
/sbin/setserial /dev/ttyS2 auto_irq skip_test autoconfig
/sbin/setserial /dev/ttyS3 auto_irq skip_test autoconfig
#
# Display serial device configuration
/sbin/setserial -bg /dev/ttyS*
The -bg /dev/ttyS* argument in the last command will print a neatly formatted summary of the hardware configuration of all active serial devices. The output will look like that shown in Example 4.2.
Example 4.2: Output of setserial -bg /dev/ttyS Command
/dev/ttyS0 at 0x03f8 (irq = 4) is a 16550A
/dev/ttyS1 at 0x02f8 (irq = 3) is a 16550A
The stty Command
The name stty probably means "set tty," but the stty command can also be used to display a terminal's configuration. Perhaps even more so than setserial, the stty command provides a bewildering number of characteristics you can configure. We'll cover the most important of these in a moment. You can find the rest described in the stty manual page.
The stty command is most commonly used to configure terminal parameters, such as whether characters will be echoed or what key should generate a break signal. We explained earlier that serial devices are tty devices and the stty command is therefore equally applicable to them.
One of the more important uses of the stty for serial devices is to enable hardware handshaking on the device. We talked briefly about hardware handshaking earlier. The default configuration for serial devices is for hardware handshaking to be disabled. This setting allows "three wire" serial cables to work; they don't support the necessary signals for hardware handshaking, and if it were enabled by default, they'd be unable to transmit any characters to change it.
Surprisingly, some serial communications programs don't enable hardware handshaking, so if your modem supports hardware handshaking, you should configure the modem to use it (check your modem manual for what command to use), and also configure your serial device to use it. The stty command has a crtscts flag that enables hardware handshaking on a device; you'll need to use this. The command is probably best issued from the rc.serial file (or equivalent) at boot time using commands like those shown in Example 4.3.
Example 4.3: Example rc.serial stty Commands
#
stty crtscts ‹ /dev/ttyS0
stty crtscts ‹ /dev/ttyS1
stty crtscts ‹ /dev/ttyS2
stty crtscts ‹ /dev/ttyS3
#
The stty command works on the current terminal by default, but by using the input redirection ("‹") feature of the shell, we can have stty manipulate any tty device. It's a common mistake to forget whether you are supposed to use "‹" or "›"; modern versions of the stty command have a much cleaner syntax for doing this. To use the new syntax, we'd rewrite our sample configuration to look like that shown in Example 4.4.
Example 4.4: Example rc.serial stty Commands Using Modern Syntax
#
stty crtscts -F /dev/ttyS0
stty crtscts -F /dev/ttyS1
stty crtscts -F /dev/ttyS2
stty crtscts -F /dev/ttyS3
#
We mentioned that the stty command can be used to display the terminal configuration parameters of a tty device. To display all of the active settings on a tty device, use:
$
stty -a -F /dev/ttyS1
The output of this command, shown in Example 4.5, gives you the status of all flags for that device; a flag shown with a preceding minus, as in -crtscts, means that the flag has been turned off.