Too much Plug & Play: gpsd and upowerd are blocking my serial port

I’m using a 5V FTDI USB TTL serial cable:

[chris@thinkpad ~]$ lsusb |grep FT232
Bus 001 Device 013: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC

We need proper permissions to be able to access the serial port as normal user without root privileges:

[chris@thinkpad ~]$ ls -l /dev/ttyUSB0
crw-rw----. 1 root dialout 188, 0 Aug  3 13:40 /dev/ttyUSB0

So my user account must be added to the dialout group, which can be accomplished with the usermod command:

[chris@thinkpad ~]$ sudo usermod -aG dialout chris
[chris@thinkpad ~]$ #logout and login
[chris@thinkpad ~]$ groups
chris lp wheel cdrom dialout magick

But still I can’t open the serial port, something is blocking it:

[chris@thinkpad ~]$ # configure minicom and disable Hardware Flow Control
[chris@thinkpad ~]$ sudo minicom -s oli
[chris@thinkpad ~]$ minicom oli
minicom: cannot open /dev/ttyUSB0: Device or resource busy

So we need to find out which process is using /dev/ttyUSB0:

[chris@thinkpad ~]$ lsof /dev/ttyUSB0
[chris@thinkpad ~]$ sudo lsof /dev/ttyUSB0
COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF  NODE NAME
gpsd    1079 nobody    6u   CHR  188,0      0t0 47504 /dev/ttyUSB0
upowerd 3266   root   14u   CHR  188,0      0t0 47504 /dev/ttyUSB0

Problem found: gpsd and upowerd are using the serial port, so we need to stop them from doing so:

  1. Change USBAUTO from true to false in /etc/sysconfig/gpsd:
[chris@thinkpad ~]$ sudo vim /etc/sysconfig/gpsd
OPTIONS="-n"
DEVICE="/dev/ttyUSB0"
USBAUTO="false"
  1. Edit /lib/udev/rules.d/95-upower-wup.rules and comment out the SUBSYSTEM line:
[chris@thinkpad ~]$ sudo vim /lib/udev/rules.d/95-upower-wup.rules
###############################
# Watts Up? Pro Devices
#
#SUBSYSTEM=="tty", SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A80?????", ENV{UPOWER_VENDOR}="Watts Up, Inc.", ENV{UPOWER_PRODUCT}="Watts Up? Pro", ENV{UP_MONITOR_TYPE}="wup"

Now remove the usb serial converter and plug it back in:

[chris@thinkpad ~]$ sudo lsof /dev/ttyUSB0
[chris@thinkpad ~]$

And everything is fine:

Minicom connected to OLinuXino via usb serial converter

Minicom connected to OLinuXino via usb serial converter

Update: The next program is driving me crazy, now it is modem-man (modem-manager):

[chris@thinkpad ~]$ sudo lsof /dev/ttyUSB0
COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
modem-man 1069 root   29u   CHR  188,0      0t0 484165 /dev/ttyUSB0
[chris@thinkpad ~]$ cat /var/log/messages |grep modem |tail -n5
Jan 22 18:27:31 thinkpad dbus-daemon[975]: modem-manager[1069]: <info>  (ttyUSB0) opening serial port...
Jan 22 18:27:37 thinkpad dbus-daemon[975]: modem-manager[1069]: <info>  (ttyUSB0) closing serial port...
Jan 22 18:27:37 thinkpad modem-manager[1069]: <info>  (ttyUSB0) closing serial port...
Jan 22 18:27:37 thinkpad modem-manager[1069]: <info>  (ttyUSB0) serial port closed
Jan 22 18:27:37 thinkpad dbus-daemon[975]: modem-manager[1069]: <info>  (ttyUSB0) serial port closed
[chris@thinkpad ~]$ rpm -ql ModemManager |grep blacklist
/lib/udev/rules.d/77-mm-pcmcia-device-blacklist.rules
/lib/udev/rules.d/77-mm-usb-device-blacklist.rules
[chris@thinkpad ~]$

Now edit the file /lib/udev/rules.d/77-mm-usb-device-blacklist.rules and add a new blacklist rule for my device:

# Cygnal Integrated Products, Inc. CP210x Composite Device (USB-Serial)
ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", ENV{ID_MM_DEVICE_IGNORE}="1"

# Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ENV{ID_MM_DEVICE_IGNORE}="1"