HeAdLeSs
Posts: 17
Joined: Wed Oct 15, 2014 12:18 pm
Location: Cyprus
Contact: Website

Fix port/path for USB devices

Thu Oct 19, 2017 8:53 am

Hello together.

I've been asking this question in the German forum already, but it seems like nobody could help. Maybe here is someone who could help me.

The problem:
I have a Pi with quite a few USB Devices. 2 mass storage sticks, usb soundcard, Huawei E1750 gsm modem and a Victron USB to serial. To connect all this stuff (and provide enough power) I have also connected 2 USB Hubs. At the active USB Hub are the modem, the usb soundcard and the usb to serial. An inactive hub with the both mass storage devices.
The problems are with the modem and the usb to serial.

1) As both devices have a config file, which would like to have the port/path, it is nessesary that the /dev/-Path is always the same. The decives are always connected and it is a stand alone system. I am not there (and don't want, to be honest) at every restart to reconnect and connect the devices again, to get them in the correct order.

So I've been reading about udev. But can't really get it working. I don't get it, to be honest. But later more about it.

2) Funny thing: Most of the times, the usb to serial gets the path /dev/ttyUSB0. If it gets this path, I am not able to read data. Error (from a Python script): "serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected?)". My wild guess is that there is either another device on the same port (maybe the modem?) or anything wants to read from this port.
The device is connected and working well (at any other port it is just fine)
But it seems like the udev rule for this is working now.

3) udevadm monitor --environment (as well as the messages log file) is showing me that the Pi is connecting and disconnecting the modem every few seconds. That is not normal, isn't it?
I though about power issue. But connected the modem only to the pi. No change, same thing. 4,78V it got. Then on the active usb hub alone, same issue. This time it got 5,02V. I doubt it is a power issue.

In fact I have to admit that I am not a big Linux expert. Over 10 years Windows user :oops: So please be patient with me. ;)

Some data:
sudo ls -l /dev/serial/by-id/

Code: Select all

/dev/serial/by-id/:
insgesamt 0
lrwxrwxrwx 1 root root 13 Okt 19 10:00 usb-HUAWEI_Technology_HUAWEI_Mobile-if00-port0 -> ../../ttyUSB1
lrwxrwxrwx 1 root root 13 Okt 19 10:00 usb-HUAWEI_Technology_HUAWEI_Mobile-if01-port0 -> ../../ttyUSB2
lrwxrwxrwx 1 root root 13 Okt 19 10:00 usb-HUAWEI_Technology_HUAWEI_Mobile-if02-port0 -> ../../ttyUSB3
lrwxrwxrwx 1 root root 12 Jan  1  1970 usb-VictronEnergy_BV_VE_Direct_cable_VE1BOZSG-if00-port0 -> ../../bmv700
My udev rules so far (commented lines are the ones I tried, without success - the only one which works well is the one for the usb to serial). Please notice that the Huawei modem needs 3 ports. That is my biggest issue here. How to get a symlink/name for each port.

Code: Select all

KERNEL=="ttyUSB?", ATTRS{manufacturer}=="VictronEnergy BV", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6015", NAME="bmv700"

#KERNEL=="ttyUSB?",ATTRS{bInterfaceNumber}=="00",KERNELS="1-1.4.4.2:1.0",NAME="umts0"
#KERNEL=="ttyUSB?",ATTRS{bInterfaceNumber}=="01",KERNELS="1-1.4.4.2:1.1",NAME="umts1"
#KERNEL=="ttyUSB?",ATTRS{bInterfaceNumber}=="02",KERNELS="1-1.4.4.2:1.2",NAME="umts2"


#ACTION=="add", SUBSYSTEM=="tty", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1001", SYMLINK+="ttyUSB_Huawei1"

#SUBSYSTEMS=="usb-serial", ENV{.LOCAL_PORT_NUM}="$attr{port_number}"
#KERNEL=="ttyUSB*", SUBSYSTEM=="usb", KERNELS=="1-1.4.1:1.0", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1001", SYMLINK+="huawei$env{.LOCAL_PORT_NUM}"

#KERNEL=="ttyUSB*", KERNELS=="1-1.4.1:1.1", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1001", NAME="huawei1"
#KERNEL=="ttyUSB*", KERNELS=="1-1.4.1:1.2", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1001", NAME="huawei2"

#ACTION=="add", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1001", SYMLINK+="huawei_0"
#ACTION=="add", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1001", SYMLINK+="huawei_1"
#ACTION=="add", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1001", SYMLINK+="huawei_2"

udevadm info -a --name=ttyUSB0 (I've been cutting of the output for the USB Hub):

Code: Select all

pi@RPi2 ~ $ udevadm info -a --name=ttyUSB0

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5.2/1-1.5.2:1.0/ttyUSB0/tty/ttyUSB0':
    KERNEL=="ttyUSB0"
    SUBSYSTEM=="tty"
    DRIVER==""

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5.2/1-1.5.2:1.0/ttyUSB0':
    KERNELS=="ttyUSB0"
    SUBSYSTEMS=="usb-serial"
    DRIVERS=="option1"
    ATTRS{port_number}=="0"

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5.2/1-1.5.2:1.0':
    KERNELS=="1-1.5.2:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="option"
    ATTRS{bInterfaceClass}=="ff"
    ATTRS{bInterfaceSubClass}=="ff"
    ATTRS{bInterfaceProtocol}=="ff"
    ATTRS{bNumEndpoints}=="03"
    ATTRS{supports_autosuspend}=="1"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{bInterfaceNumber}=="00"

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5.2':
    KERNELS=="1-1.5.2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{devpath}=="1.5.2"
    ATTRS{idVendor}=="12d1"
    ATTRS{speed}=="480"
    ATTRS{bNumInterfaces}==" 3"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{busnum}=="1"
    ATTRS{devnum}=="47"
    ATTRS{configuration}=="Huawei   Configuration"
    ATTRS{bMaxPower}=="500mA"
    ATTRS{authorized}=="1"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{maxchild}=="0"
    ATTRS{bcdDevice}=="0000"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{version}==" 2.00"
    ATTRS{urbnum}=="24"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="HUAWEI Technology"
    ATTRS{removable}=="unknown"
    ATTRS{idProduct}=="1001"
    ATTRS{bDeviceClass}=="00"
    ATTRS{product}=="HUAWEI Mobile"
udevadm info -a --name=ttyUSB1:

Code: Select all

pi@RPi2 ~ $ udevadm info -a --name=ttyUSB1

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5.2/1-1.5.2:1.1/ttyUSB1/tty/ttyUSB1':
    KERNEL=="ttyUSB1"
    SUBSYSTEM=="tty"
    DRIVER==""

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5.2/1-1.5.2:1.1/ttyUSB1':
    KERNELS=="ttyUSB1"
    SUBSYSTEMS=="usb-serial"
    DRIVERS=="option1"
    ATTRS{port_number}=="0"

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5.2/1-1.5.2:1.1':
    KERNELS=="1-1.5.2:1.1"
    SUBSYSTEMS=="usb"
    DRIVERS=="option"
    ATTRS{bInterfaceClass}=="ff"
    ATTRS{bInterfaceSubClass}=="ff"
    ATTRS{bInterfaceProtocol}=="ff"
    ATTRS{bNumEndpoints}=="02"
    ATTRS{supports_autosuspend}=="1"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{bInterfaceNumber}=="01"

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5.2':
    KERNELS=="1-1.5.2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{devpath}=="1.5.2"
    ATTRS{idVendor}=="12d1"
    ATTRS{speed}=="480"
    ATTRS{bNumInterfaces}==" 3"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{busnum}=="1"
    ATTRS{devnum}=="53"
    ATTRS{configuration}=="Huawei   Configuration"
    ATTRS{bMaxPower}=="500mA"
    ATTRS{authorized}=="1"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{maxchild}=="0"
    ATTRS{bcdDevice}=="0000"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{version}==" 2.00"
    ATTRS{urbnum}=="10"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="HUAWEI Technology"
    ATTRS{removable}=="unknown"
    ATTRS{idProduct}=="1001"
    ATTRS{bDeviceClass}=="00"
    ATTRS{product}=="HUAWEI Mobile"
And udevadm info -a --ame=ttyUSB2:

Code: Select all

udevadm info -a --ame=ttyUSB2

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5.2/1-1.5.2:1.2/ttyUSB2/tty/ttyUSB2':
    KERNEL=="ttyUSB2"
    SUBSYSTEM=="tty"
    DRIVER==""

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5.2/1-1.5.2:1.2/ttyUSB2':
    KERNELS=="ttyUSB2"
    SUBSYSTEMS=="usb-serial"
    DRIVERS=="option1"
    ATTRS{port_number}=="0"

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5.2/1-1.5.2:1.2':
    KERNELS=="1-1.5.2:1.2"
    SUBSYSTEMS=="usb"
    DRIVERS=="option"
    ATTRS{bInterfaceClass}=="ff"
    ATTRS{bInterfaceSubClass}=="ff"
    ATTRS{bInterfaceProtocol}=="ff"
    ATTRS{bNumEndpoints}=="02"
    ATTRS{supports_autosuspend}=="1"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{bInterfaceNumber}=="02"

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5.2':
    KERNELS=="1-1.5.2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{devpath}=="1.5.2"
    ATTRS{idVendor}=="12d1"
    ATTRS{speed}=="480"
    ATTRS{bNumInterfaces}==" 3"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{busnum}=="1"
    ATTRS{devnum}=="59"
    ATTRS{configuration}=="Huawei   Configuration"
    ATTRS{bMaxPower}=="500mA"
    ATTRS{authorized}=="1"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{maxchild}=="0"
    ATTRS{bcdDevice}=="0000"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{version}==" 2.00"
    ATTRS{urbnum}=="10"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="HUAWEI Technology"
    ATTRS{removable}=="unknown"
    ATTRS{idProduct}=="1001"
    ATTRS{bDeviceClass}=="00"
    ATTRS{product}=="HUAWEI Mobile"
If I can provide any other information needed, please tell me how :)

The 2 biggest problems I have right now is the constant connecting/disconnecting of the modem and how to tell udev to give the modem fix symlinks or names. The usb-to-serial seems like to work at the moment.

Would be great if someone could help me with it. Thanks a lot.

Return to “Advanced users”