old-www/HOWTO/Serial-HOWTO-10.html

246 lines
12 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META NAME="GENERATOR" CONTENT="LinuxDoc-Tools 0.9.21">
<TITLE> Serial HOWTO: Serial Port Devices /dev/ttyS2, etc. </TITLE>
<LINK HREF="Serial-HOWTO-11.html" REL=next>
<LINK HREF="Serial-HOWTO-9.html" REL=previous>
<LINK HREF="Serial-HOWTO.html#toc10" REL=contents>
</HEAD>
<BODY>
<A HREF="Serial-HOWTO-11.html">Next</A>
<A HREF="Serial-HOWTO-9.html">Previous</A>
<A HREF="Serial-HOWTO.html#toc10">Contents</A>
<HR>
<H2><A NAME="ttySN_"></A> <A NAME="s10">10.</A> <A HREF="Serial-HOWTO.html#toc10">Serial Port Devices /dev/ttyS2, etc. </A></H2>
<H2><A NAME="ss10.1">10.1</A> <A HREF="Serial-HOWTO.html#toc10.1">Serial Port Names: ttyS4, etc</A>
</H2>
<P>Common serial port names are /dev/ttyS0, /dev/ttyS1, etc. Then
around the year 2000 came the USB bus with names like /dev/ttyUSB0 and
/dev/ttyACM1 (for the ACM modem on the USB bus). Multiport serial
card used somewhat differnt names (depending on the brand) such as
/dev/ttyE5.</P>
<H2><A NAME="ss10.2">10.2</A> <A HREF="Serial-HOWTO.html#toc10.2">The PCI Bus</A>
</H2>
<P>Since DOS provided for 4 serial ports on the old ISA bus:
COM1-COM4, or ttyS0-ttyS3 in Linux, most serial ports on the newer PCI
bus used higher numbers such as ttyS4 or ttyS14 (prior to kernel
2.6.13). But since most PCs only came with one or two serial ports,
ttyS0 and possibly ttyS1 (for the second port) the PCI bus can now use
ttyS2 (kernel 2.6.15 on). All this permits one to have both ISA
serial ports and PCI serial ports on the same PC with no name
conflicts. 0-1 (or 0-3) are reserved for the old ISA bus (or the
newer LPC bus) and 2-upward (or 4-upward or 14-upward) are used for
PCI, where older schemes are shown in parentheses . It's not required
to be this way but it often is.</P>
<P>If you're using udev (which puts only the device you have on your
computer into the /dev directory at boottime) then there's an easy way
to change the device names by editing files in /etc/udev/. For
example, to change the name of what the kernel detects as ttyS3 to
what you want to name it: ttyS14, add a line similar to this to
/etc/udev/udev.rules<BR> <EM>BUS=="pci" KERNEL=="ttyS3",
NAME="ttyS14"</EM></P>
<P>On-board serial ports on motherboards which have both PCI and ISA
slots are likely to still be ISA ports. Even for all-PCI-slot
motherboards, the serial ports are often not PCI. Instead, they are
either ISA, on an internal ISA bus or on a LPC bus which is intended
for slow legacy I/O devices: serial/parallel ports and floppy drives.</P>
<H2><A NAME="ss10.3">10.3</A> <A HREF="Serial-HOWTO.html#toc10.3">Serial Port Device Names &amp; Numbers </A>
</H2>
<P>Devices in Linux have major and minor numbers. The serial port
ttySx (x=0,1,2, etc.) is major number 4. You can see this (and the
minor numbers too) by typing: "ls -l ttyS*" in the /dev directory. To
find the device names for various devices, see the "devices" file in
the kernel documentation.</P>
<P>There formerly was a "cua" name for each serial port and it behaved
just a little differently. For example, ttyS2 would correspond to
cua2. It was mainly used for modems. The cua major number was 5 and
minor numbers started at 64. You may still have the cua devices in
your /dev directory but they are now deprecated. For details see
Modem-HOWTO, section: cua Device Obsolete.</P>
<P>For creating the old devices in the device directory see:</P>
<P>
<A HREF="#create_dev">Creating Devices In the /dev directory</A></P>
<H2><A NAME="dev_nos"></A> <A NAME="ss10.4">10.4</A> <A HREF="Serial-HOWTO.html#toc10.4">More on Serial Port Names </A>
</H2>
<P>Dos/Windows use the COM name while the messages from the serial driver
use ttyS00, ttyS01, etc. Older serial drivers (2001 ?) used just
tty00, tty01, etc. </P>
<P>The tables below shows some examples of serial device names. The
IO addresses are the default addresses for the old ISA bus (not for
the newer PCI and USB buses).</P>
<P>
<BLOCKQUOTE><CODE>
<PRE>
dos common IO USB-BUS ( ACM => acm modem )
name name major minor address || common name common name
COM1 /dev/ttyS0 4, 64; 3F8 || /dev/ttyUSB0 | /dev/ttyACM0
COM2 /dev/ttyS1 4, 65; 2F8 || /dev/ttyUSB1 | /dev/ttyACM1
COM3 /dev/ttyS2 4, 66; 3E8 || /dev/ttyUSB2 | /dev/ttyACM2
COM4 /dev/ttyS3 4, 67; 2E8 || /dev/ttyUSB3 | /dev/ttyACM3
- /dev/ttyS4 4, 68; various
</PRE>
</CODE></BLOCKQUOTE>
</P>
<H2><A NAME="ss10.5">10.5</A> <A HREF="Serial-HOWTO.html#toc10.5">USB (Universal Serial Bus) Serial Ports</A>
</H2>
<P> For more info see the usb subdirectory in the kernel documentation
directory for files: usb-serial, acm, etc.</P>
<H2><A NAME="ss10.6">10.6</A> <A HREF="Serial-HOWTO.html#toc10.6">Link ttySN to /dev/modem</A>
</H2>
<P> On some installations, two extra devices will be created,
<CODE>/dev/modem</CODE> for your modem and <CODE>/dev/mouse</CODE> for a
mouse. Both of these are symbolic links to the appropriate
device in <CODE>/dev</CODE>.</P>
<P>Historical note: Formerly (in the 1990s) the use of
<CODE>/dev/modem</CODE> (as a link to the modem's serial port) was
discouraged since lock files might not realize that it was really say
<CODE>/dev/ttyS2</CODE>. The newer lock file system doesn't fall into
this trap so it's now OK to use such links.</P>
<H2><A NAME="identify_ttyS"></A> <A NAME="ss10.7">10.7</A> <A HREF="Serial-HOWTO.html#toc10.7">Which Connector on the Back of my PC is ttyS1, etc? </A>
</H2>
<H3>Inspect the connectors</H3>
<P> Inspecting the connectors may give some clues but is often not
definitive. The serial connectors on the back side of a PC are
usually DB connectors with male pins. 9-pin is the most common but
some are 25-pin (especially older PCs like 486s). There may be one
9-pin (perhaps ttyS0 ??) and one 25-pin (perhaps ttyS1 ??). For two
9-pin ones the top one might be ttyS0.</P>
<P>If you only have one serial port connector on the back of your PC,
this may be easy. If you also have an internal modem, a program like
wvdial may be able to tell you what port it's on (unless it's a PnP
that hasn't been enabled yet). A report from setserial (at
boot-time or run by you from the command line) should help you
identify the non-modem ports.</P>
<P>If you have two serial ports it may be more difficult. You could have
only one serial connector but actually have 2 ports, one of which
isn't used (but it's still there electronically). First check manuals
(if any) for your computer. Look at the connectors for meaningful
labels. You might even want to take off the PC's cover and see if
there are any meaningful labels on the card where the internal ribbon
serial cables plug in. Labels (if any) are likely to say something like
"serial 1", "serial 2" or A, B. Which com port it actually is will
depend on jumper or PnP settings (sometimes shown in a BIOS setup
menu). But 1 or A are more likely to be ttyS0 with 2 or B ttyS1.</P>
<H3>Send bytes to the port</H3>
<P> Labels are not apt to be definitive so here's another method. If
the serial ports have been configured correctly per setserial, then
you may send some bytes out a port and try to detect which connector
(if any) they are coming out of. One way to send such a signal is to
copy a long text file to the port using a command like: cp
my_file_name /dev/ttyS1. A voltmeter connected to the DTR pin (see
Serial-HOWTO for Pinout) will display a positive voltage as soon as
you give the copy command.</P>
<P>The transmit pin should go from several volts negative to a voltage
fluctuating around zero after you start sending the bytes. If it doesn't
(but the DTR went positive) then you've got the right port but it's
blocked from sending. This may be due to a wrong IRQ, -clocal being
set, etc. The command "<CODE>stty -F /dev/ttyS1 -a</CODE>" should show
clocal (and not -clocal). If not, change it to clocal.</P>
<P>Another test is to jumper the transmit and receive pins (pins 2 and 3
of either the 25-pin or 9-pin connector) of a test serial port. Then
send something to each port (from the PCs keyboard) and see if it gets
sent back. If it does it's likely the port with the jumper on it.
Then remove the jumper and verify that nothing gets sent back. Note
that if "echo" is set (per stty) then a jumper creates an infinite
loop. Bytes that pass thru the jumper go into the port and come right
back out of the other pin back to the jumper. Then they go back in
and out again and again. Whatever you send to the port repeats itself
forever (until you interrupt it by removing the jumper, etc.). This
may be a good way to test it as the repeating test messages halt when
the jumper is removed.</P>
<P>As a jumper you could use a mini (or micro) jumper cable (sold in some
electronic parts stores) with mini alligator clips. A small scrap of
paper may be used to prevent the mini clips from making electrical
contact where it shouldn't. Metal paper clips can sometimes be bent
to use as jumpers. Whatever you use as a jumper take care not to bend
or excessively scratch the pins. To receive something from a port,
you can go to a virtual terminal (for example Alt-F2 and login) and
type something like "cp /dev/ttyS2 /dev/tty". Then at another virtual
terminal you may send something to ttyS2 (or whatever) by "echo
test_message > /dev/ttyS2". Then go back to the receive virtual
terminal and look for the test_message. See
<A HREF="Serial-HOWTO-16.html#ser_elect_test">Serial Electrical Test Equipment</A> for more info.</P>
<H3>Connect a device to the connector</H3>
<P> Another way to try to identify a serial port is to connect some
physical serial device to it and see if it works. But a problem here
is that it might not work because it's not configured right. A serial
mouse might get detected at boot-time if connected.</P>
<P>You may put a device, such as a serial mouse (use 1200 baud), on a port
and then use minicom or picocom to communicate with that port. Then
by clicking on the mouse, or otherwise sending characters with the
device, see if they get displayed. It not you may have told picocom
the wrong port (such as ttyS0 instead of ttyS1) so try again.</P>
<H3>Missing connectors</H3>
<P> If the software shows that you have more serial ports than you
have connectors for (including an internal modem which counts as a
serial port) then you may have a serial port that has no connector.
Some motherboards come with a serial port with no cable or external
serial DB connector. Someone may build a PC from this and decide not
to use this serial port. There may be a "serial" connector and label
on the motherboard but no ribbon cable connects to its pins. To use
this port you must get a ribbon cable and connector. I've seen
different wiring arrangements for such ribbon cables so beware.</P>
<H2><A NAME="create_dev"></A> <A NAME="ss10.8">10.8</A> <A HREF="Serial-HOWTO.html#toc10.8">Creating Devices In the /dev directory </A>
</H2>
<P>If you don't use devfs (which automatically creates such devices) and
don't have a device "file" that you need, you will have to create it.
Use the <CODE>mknod</CODE> command or with the MAKEDEV shell script.
Example, suppose you needed to create <CODE>ttyS0</CODE>:</P>
<P>
<BLOCKQUOTE><CODE>
<PRE>
linux# mknod -m 666 /dev/ttyS0 c 4 64
</PRE>
</CODE></BLOCKQUOTE>
The MAKEDEV script is easier to use.
See the man page for it. For example, if you needed to make the
device for <CODE>ttyS0</CODE> you would just type:</P>
<P>
<BLOCKQUOTE><CODE>
<PRE>
linux# MAKEDEV ttyS0
</PRE>
</CODE></BLOCKQUOTE>
</P>
<P>If the above command doesn't work (and you are the root user), look
for the MAKEDEV script in the /dev directory and run it.</P>
<P>This handles the devices creation and should set the correct permissions.
For making multiport devices see
<A HREF="Serial-HOWTO-5.html#make_multi">Making multiport devices in the /dev directory</A>.</P>
<HR>
<A HREF="Serial-HOWTO-11.html">Next</A>
<A HREF="Serial-HOWTO-9.html">Previous</A>
<A HREF="Serial-HOWTO.html#toc10">Contents</A>
</BODY>
</HTML>