U ATS L: Sing Erial With Inux
U ATS L: Sing Erial With Inux
This document assumes that you are already familiar with Linux.
Contents
Related Documentation........................................................................... 2
Contributions ................................................................................... 2
Gather What You Need to Get Started.................................................... 2
Quick Start .............................................................................................. 3
Setup........................................................................................................ 4
Create Devices ................................................................................. 4
MAKEDEV Example ............................................................... 5
Configure Interface .......................................................................... 5
isafile Example ......................................................................... 6
Assign Serial Driver......................................................................... 6
setserial Example ...................................................................... 7
Configuration .......................................................................................... 7
View Your Hardware Resources ..................................................... 7
Enable FIFO Buffers........................................................................ 7
FIFO Example .......................................................................... 8
Configure struct termios .................................................................. 8
Select AT-485 Transceiver Mode ........................................................... 8
rs485 Example .......................................................................... 9
Test the Setup.......................................................................................... 9
Troubleshooting and Common Questions............................................... 10
Error Codes ...................................................................................... 10
Common Questions.......................................................................... 11
Assign Driver .......................................................................................... 12
Sample isafile after Edit .......................................................................... 14
Sample isafile after Edit for Non-Interrupt Sharing Interfaces............... 15
Sample /etc/rc.d/rc.serial File.................................................................. 17
natinst.com™, National Instruments™, and NI-Serial ™ are trademarks of National Instruments Corporation. Product and company names
mentioned herein are trademarks or trade names of their respective companies.
322538A-01 © Copyright 1999 National Instruments Corp. All rights reserved. August 1999
Related Documentation
The following documents contain information that you might find helpful
as you read this manual:
• Linux Serial-Programming-HOWTO by Peter Baumann. You can find
the latest version of this document at the following locations:
ftp://metalab.unc.edu:/pub/Linux/docs/HOWTO/Serial-
Programming-HOWTO
http://metalab.unc.edu/LDP/HOWTO/Serial-Programming
-HOWTO.html
• Linux Serial-HOWTO by David Lawyer. You can find the latest version
of this document at the following locations:
ftp://metalab.unc.edu:/pub/Linux/docs/HOWTO/Serial-
HOWTO
http://metalab.unc.edu/LDP/HOWTO/Serial-HOWTO.html
Contributions
Thanks to Vern Howie for providing suggestions and examples from his
serial suite. Also, thanks to David Lawyer, Greg Hankins, and Peter
Baumann for providing so much information in their HOWTOs.
Quick Start
This section is for experienced Linux users who are familiar with the
isapnp and setserial tools. If you are not familiar with either of these
tools or if you require a detailed explanation of the steps, skip to the next
section, Setup.
1. If you do not have enough available serial devices ( /dev/ttyS*) for
each port on your multiport interface, create a new serial device by
entering the following:
linux# cd /dev
linux /dev# ./MAKEDEV ttyS<port number>
2. Find and configure the port address and IRQ of your AT serial
interface.
a. Enter the following:
linux# pnpdump > isafile
linux# pico isafile
Setup
After you install the serial hardware (as shown in your AT serial getting
started manual), follow these steps to set up the serial interface.
Create Devices
Create a device for each port on your multiport interface. You only need
to do this step once. Port address is the I/O address of the device, and port
number is the device/serial port number of the port. Port number is used in
the following context: ttyS<port number>. Since the serial ports built
into your computer are typically named from /dev/ttyS0 to
/dev/ttyS3, the port number you choose needs to be four or greater.
MAKEDEV Example
Enter the following to make the devices for a two-port interface:
linux# cd /dev
linux /dev# ./MAKEDEV ttyS4
linux /dev# ./MAKEDEV ttyS5
Configure Interface
Follow these instructions to find and configure the port address and IRQ of
your AT serial interface.
Note Repeat this section each time you add another interface or physical device to the
computer.
isafile Example
The edited isafile file for a two-port AT serial interface should be
similar to following (refer to Sample isafile after Edit for a sample
isafile). If you have an old AT interface that does not share interrupts,
refer to Sample isafile after Edit for Non-Interrupt Sharing Interfaces.
# (DEBUG)
(READPORT 0x???)
(ISOLATE PRESERVE)
(IDENTIFY *)
(VERBOSITY 2)
(CONFLICT (IO FATAL)(IRQ FATAL)(DMA FATAL)(MEM FATAL))
# information about other interfaces...
(CONFIGURE NICd???/???????? (LD ?
(IO 0 (SIZE 8)(BASE 0x0100)) # <port address> = 0x100
(IO 1 (SIZE 8)(BASE 0x0110)) # <port address> = 0x110
(INT 0 (IRQ 3 (MODE +E))) # <irq> = 3
(ACT Y)
))
Note Repeat this step each time you restart your computer or until you set up your
/etc/rc.d/rc.serial file. (Refer to Assign Driver for more information on setting up
the /etc/rc.d/rc.serial file.)
Enter the following to use setserial to tell the kernel each device’s
UART, port address, and IRQ. Use the <port address> and <irq>
values from your edited isafile.
linux# setserial /dev/ttyS<port number> uart 16550A
port <port address> irq <irq> ^fourport
Note The ^fourport flag is required regardless of how many ports you have on your
interface. The ^fourport flag tells the serial driver that you are not using an AST
four-port interface.
Configuration
View Your Hardware Resources
To see what system resources your serial interface is using, use the
setserial command, as follows:
linux# setserial -gv /dev/ttyS*
Table 1-1 shows the receive FIFO trigger levels and corresponding
rx_trigger values.
The hardware issues a receive full interrupt when the number of characters
in the receive FIFO rises above the trigger level. For more information on
the FIFO buffers, refer to your serial getting started manual.
FIFO Example
Enter the following to set the receive FIFO trigger level to 14 for
/dev/ttyS5:
linux AT-SERIAL# ./FIFOtrigger 5 0xC0
rs485 Example
Enter the following to select Four-Wire Mode for /dev/ttyS5:
linux AT-SERIAL# ./rs485 5 0
Solution The /dev/ttyS<port number> does not exist in the /dev directory. Enter the
following to create the device:
linux# cd /dev
linux /dev# ./MAKEDEV ttyS<port number>
Error Code Couldn't change i/o privilege level: Operation not permitted
Solution The program requires superuser privileges. Either exit and log in as root, or enter
the following:
linux$ su
Password: <enter the root password>
linux# <run the program>
Error Code setserial: Cannot set serial info: Address already in use
Solution Make sure you are entering the correct port address into setserial. Also, make
sure you are entering 0x if you are specifying a hex number.
linux# setserial /dev/ttyS<port number> uart 16550a port
0x<port address> irq <irq> ^fourport
Solution Make sure the device was configured correctly in setserial. Enter the
following:
linux# setserial -gv /dev/ttyS<port number>
/dev/ttyS4, UART: 16550A, Port: 0xdff0, IRQ: 11
If the port listing does not match the one configured by the isapnp step,
reconfigure the device by entering the following:
linux# setserial /dev/ttyS<port number> uart 16550a port
<port address> irq <irq> ^fourport
Devices labeled with UART: unknown are available for use. To designate
the available device when using setserial, enter the following:
linux# setserial /dev/ttyS<port number> uart 16550a
port 0x<port address> irq <irq> ^fourport
Assign Driver
Use these instructions to automatically assign the driver at startup using
/etc/rc.d/rc.serial.
You should not change the /etc/rc.d/rc.serial file until you have
your serial interfaces installed and configured. If you add another device or
interface to your computer, and your isafile changes, make sure you also
change /etc/rc.d/rc.serial.