New IT forum
27 June 2022, 10:47:31 am *
Welcome, %1$s. Please login or register.

: PiHub now in stock.
Pages: [1]

Author Topic: USB to serial converter  (Read 4369 times)


  • Newbie
  • *
  • Posts: 13
USB to serial converter
« on: 19 July 2013, 10:30:37 am »

I running two applications on my DP. Each using a USB to serial converter mounted in each USB port on the DP. From one restart to another they intends to swap names /dev/ttyUSB0 <=> /dev/ttyUSB1. Is there some way to prevent this. I am running Debian GNU/Linux 6.0


  • New IT customer
  • Hero Member
  • *
  • Posts: 663
Re: USB to serial converter
« Reply #1 on: 19 July 2013, 07:56:07 pm »

they intends to swap names /dev/ttyUSB0 <=> /dev/ttyUSB1. Is there some way to prevent this
Yes, by creating a custom udev rule file (but i suggest you don't directly mess with the device names).
I can't post the solution, but hopefully I can post a walkthrough for the technique to obtain one.

The trick is to distinguish the two different usb devices, which can be problematic for two identical devices (same Vendor:Model) that do not provide serial numbers.
Determine the differences.
Code: [Select]
[email protected]:~# udevadm info -a -n /dev/ttyUSB0 >catch0
[email protected]:~# udevadm info -a -n /dev/ttyUSB1 >catch1                                       
[email protected]:~# diff catch0 catch1
<   looking at device '/devices/platform/orion-ehci.0/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0/tty/tt
<     KERNEL=="ttyUSB0"
>   looking at device '/devices/platform/orion-ehci.0/usb1/1-1/1-1.3/1-1.3:1.0/ttyUSB1/tty/tt
>     KERNEL=="ttyUSB1"
<   looking at parent device '/devices/platform/orion-ehci.0/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0
<     KERNELS=="ttyUSB0"
>   looking at parent device '/devices/platform/orion-ehci.0/usb1/1-1/1-1.3/1-1.3:1.0/ttyUSB1
>     KERNELS=="ttyUSB1"
<   looking at parent device '/devices/platform/orion-ehci.0/usb1/1-1/1-1.2/1-1.2:1.0':
<     KERNELS=="1-1.2:1.0"
>   looking at parent device '/devices/platform/orion-ehci.0/usb1/1-1/1-1.3/1-1.3:1.0':
>     KERNELS=="1-1.3:1.0"
<   looking at parent device '/devices/platform/orion-ehci.0/usb1/1-1/1-1.2':
<     KERNELS=="1-1.2"
>   looking at parent device '/devices/platform/orion-ehci.0/usb1/1-1/1-1.3':
>     KERNELS=="1-1.3"
<     ATTRS{devpath}=="1.2"
>     ATTRS{devpath}=="1.3"
<     ATTRS{devnum}=="7"
>     ATTRS{devnum}=="8"
The one useful differing attribute above (there being no device serial number) is the devpath, which is related to the physical USB port our 'devices' are plugged into.
As long as we do not physically change where the USB devices are connected, this will remain consistent.

Create a suitably named rule file, e.g. '/etc/udev/rules.d/99-custom-usb-serial.rules'
Code: [Select]
SUBSYSTEM=="tty", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", ATTRS{devpath}=="1.2", SYMLINK+="gadget0"
SUBSYSTEM=="tty", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", ATTRS{devpath}=="1.3", SYMLINK+="gadget1"

You can use 'lsusb' to help fill in the idVendor and idProduct information above.
Code: [Select]
[email protected]:~# lsusb
Bus 001 Device 008: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 001 Device 007: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 001 Device 004: ID 0d8c:013c C-Media Electronics, Inc.
Bus 001 Device 003: ID 05e3:0726 Genesys Logic, Inc.
Bus 001 Device 002: ID 1a40:0101 TERMINUS TECHNOLOGY INC. USB-2.0 4-Port HUB
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Now regardless of the ttyUSB0/ttyUSB1 device designation you will get two symbolic links '/dev/gadget0' and '/dev/gadget1'
which will always be associated with the same physical usb device connection, simply use these as the device names for the serial ports in your application.
(use something more appropriate than 'gadgetX' in your setup :) ).

Advocatus Diaboli - My agenda is not to give you the answer, but to guide your thoughts so you derive it for yourself!


  • Newbie
  • *
  • Posts: 13
Re: USB to serial converter
« Reply #2 on: 20 July 2013, 08:11:17 am »

Thank you Confusticated.

I managed to create symlinks for the two adapters as you described, but I run into another problem:
My applications are written in Java and I am using librxtx-java. The applications complained about not finding the serial ports defined by the links (NoSuchPortException).
A workaround for this is to define a system property for the serial ports. i.e:

inLine code:
System.setProperty("", "/dev/ttyCustomPortxx");

command line:"/dev/ttyCustomPortxx"

Now it works fine.
Pages: [1]

Powered by MySQL Powered by PHP SMF 2.0.10 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!