Serial port access with UDEV

On Thu, 2009-09-17 at 12:43 -0500, driveoldford wrote:
I have several software packages for Windoz that provide for a phone/fax answering machine. In the newer wine, I can install, but cannot get access to the Com port. I have created the ln -s in dosdevices, and even did a chmod 777 on dev/ttyS0. The user is a member of groups associated w/ modems, dialout, etc.

I always get "the port is being accessed by another program". I am stuck on two very different machines. Both run Open SuSe 11.0 Anyone solved this?

I had a similar problem with a WINE app that downloads files from a logger. BTW, it applies to all programs, e.g. Kermit and minicom, as well as WINE apps that are run by normal users.


With current, udev-based, kernels its necessary to reset the permissions of /dev/ttyS[0-9] each time the device is created. I added a local rule file to /etc/udev/rules.d:

$ cat 99-local.rules 
# Locally defined rules.

# Give world read/write access to ttyS* and ttyUSB* serial devices
KERNEL=="tty[A-Z]*", GROUP="uucp", MODE="0666"

This works under Fedora 6 through Fedora 16.

Under earlier releases it was sufficient to add a line containing:

chmod uga+rw /dev/ttyS*

to /etc/rc.d/rc.local so it got run at boot time, but although this used to work for the /dev/ttyS* devices, which are created as permanently installed serial ports are recognised at boot time, it won't work for USB adapters and other serial devices which are plugged in as they are needed. However, with the change-over from the old "System V init" service/daemon management system to the new "systemd" service management its likely to disappear entirely because the /etc/rc.d structure that contains it is now a legacy structure, only retained because not all daemons have yet been migrated over to "systemd".

On Fedora 6 thru 16 and WINE 1.1.23 thru 1.5.0 this works with all real serial ports (I have one on the motherboard and another four on an IPC multiport serial card) without needing to add COMn: symlinks to the dosdevices directory. I have never been able to access USB serial adapters from WINE, probably because they need special Windows drivers.

UDEV always creates /dev/ttyS[0-3] regardless of the number of serial ports defined by the hardware. If you're unsure how many hardware serial ports are installed in your system. The setserial utility will tell you this. Run the command:

setserial -a /dev/ttyS0

as root. The -a option tells setserial to report everything it knows about the serial device. There are three possible outcomes:

  1. # setserial -a /dev/ttyS0
    /dev/ttyS0, Line 0, UART: 16550A, Port: 0x03f8, IRQ: 4
    Baud_base: 115200, close_delay: 50, divisor: 0
    closing_wait: 3000
    Flags: spd_normal skip_test

    This means the device file exists and is mapped to a physical serial port, known as a UART. The following word is its type: usually it will be an 8250, 16550 or 16550A.

  2. # setserial -a /dev/ttyS0
    /dev/ttyS0, Line 0, UART: unknown, Port: 0x03f8, IRQ: 4
    Baud_base: 115200, close_delay: 50, divisor: 0
    closing_wait: 3000
    Flags: spd_normal skip_test auto_irq

    This means that the device file exists but it is mapped to a broken or non-existent UART, described as 'unknown'.

  3. # setserial -a /dev/ttyS4
    /dev/ttyS4: No such file or directory

    The device file doesn't exist.

Ports /dev/ttyS[4-9]

A default Fedora kernel only creates /dev/ttyS[0-3] regardless of the number of hardware devices that are installed. If you've installed more than four in total by adding multiport serial PCI adapter(s), then the kernel must be told how many serial ports are available for use.

Do this by using the kernel boot argument:


where n is the number of installed hardware serial ports. This number must include those on the motherboard as well as all the ports on multiport PCI adapter(s). The argument, preceded by a space, is appended to kernel boot command. It can be tested by editing the boot command line at boot time. See Making the GRUB boot menu visible for details of how to make temporary changes to the boot command line.

When you're happy that its working, it can be made permanent by modifying GRUB's boot parameters. How you do this depends on which version of GRUB your Linux distro uses: