Find the answer to your Linux question:
Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By Medivh8076
Hi, I have a python script (not written by me) that connects to a USB device; it sets the port to '4.1-1' The best I can figure from searching around ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2013
    Posts
    1

    USB access in linux


    Hi,

    I have a python script (not written by me) that connects to a USB device; it sets the port to '4.1-1'

    The best I can figure from searching around is this number comes from something like this:

    lrwxrwxrwx 1 root root 0 May 29 18:32 ttyUSB0 -> ../../../../devices/pci0000:00/0000:00:1d.7/usb4/4-4/4-4:1.0/ttyUSB0
    lrwxrwxrwx 1 root root 0 May 29 18:32 ttyUSB1 -> ../../../../devices/pci0000:00/0000:00:1d.7/usb4/4-4/4-4:1.2/ttyUSB1
    lrwxrwxrwx 1 root root 0 May 29 18:32 ttyUSB2 -> ../../../../devices/pci0000:00/0000:00:1d.7/usb4/4-4/4-4:1.3/ttyUSB2

    Does anybody have an idea what these identifiers represent in linux?

    Thanks!

  2. #2
    Just Joined! Medivh8076's Avatar
    Join Date
    Apr 2006
    Posts
    5
    The numbers represent bus/port/device numbers and form a route to a particular USB device.

    If you plug your device in and look at the dmesg output you'll see something like this:

    Code:
    Aug 31 10:05:06 strongmint kernel: [   67.365951] usb 2-2: new full-speed USB device number 2 using xhci_hcd
    Aug 31 10:05:06 strongmint kernel: [   67.402598] usb 2-2: New USB device found, idVendor=067b, idProduct=2303
    Aug 31 10:05:06 strongmint kernel: [   67.402603] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
    Aug 31 10:05:06 strongmint kernel: [   67.402606] usb 2-2: Product: USB-Serial Controller D
    Aug 31 10:05:06 strongmint kernel: [   67.402608] usb 2-2: Manufacturer: Prolific Technology Inc. 
    Aug 31 10:05:06 strongmint kernel: [   67.431243] usbcore: registered new interface driver usbserial
    Aug 31 10:05:06 strongmint kernel: [   67.431257] usbcore: registered new interface driver usbserial_generic
    Aug 31 10:05:06 strongmint kernel: [   67.431267] usbserial: USB Serial support registered for generic
    Aug 31 10:05:06 strongmint kernel: [   67.434554] usbcore: registered new interface driver pl2303
    Aug 31 10:05:06 strongmint kernel: [   67.434575] usbserial: USB Serial support registered for pl2303
    Aug 31 10:05:06 strongmint kernel: [   67.434601] pl2303 2-2:1.0: pl2303 converter detected
    I plugged my serial device in to bus 2, port 2 and it's registered it as the first device on that port (2-2:1.0)

    Unplugging and plugging in to a different port I get:

    Code:
    Aug 31 10:05:33 strongmint kernel: [  873.025242] pl2303 2-2:1.0: device disconnected
    Aug 31 10:18:44 strongmint kernel: [  883.449427] usb 1-1.2: new full-speed USB device number 5 using ehci-pci
    Aug 31 10:18:44 strongmint kernel: [  883.542586] usb 1-1.2: New USB device found, idVendor=067b, idProduct=2303
    Aug 31 10:18:44 strongmint kernel: [  883.542596] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
    Aug 31 10:18:44 strongmint kernel: [  883.542602] usb 1-1.2: Product: USB-Serial Controller D
    Aug 31 10:18:44 strongmint kernel: [  883.542607] usb 1-1.2: Manufacturer: Prolific Technology Inc. 
    Aug 31 10:18:44 strongmint kernel: [  883.543167] pl2303 1-1.2:1.0: pl2303 converter detected
    Aug 31 10:18:44 strongmint kernel: [  883.545209] usb 1-1.2: pl2303 converter now attached to ttyUSB0
    Hmm, 1-1.2:1.0 looks a bit weird. The easiest way to understand this is to run lsusb and get the output as a tree:

    Code:
    lsusb -t
    Code:
    /:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 5000M
    /:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M
    /:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/3p, 480M
        |__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/6p, 480M
            |__ Port 2: Dev 5, If 0, Class=vend., Driver=pl2303, 12M
            |__ Port 5: Dev 3, If 0, Class='bInterfaceClass 0xe0 not yet handled', Driver=btusb, 12M
            |__ Port 5: Dev 3, If 1, Class='bInterfaceClass 0xe0 not yet handled', Driver=btusb, 12M
            |__ Port 6: Dev 4, If 0, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M
            |__ Port 6: Dev 4, If 1, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M
    So Bus 01, Port 1 (1-1) looks like an internal 6 port hub, and my serial device is now plugged in to the first port (2) of that hub (1-1.2) and is the first device on that hub (1-1.2:1) and it only has the one interface (If 0) so the route to the serial interface is (1-1.2:1.0).

    Some devices (such as the webcam controlled by the uvcvideo driver) have multiple interfaces (video and light?) which are 1-1.6:1.0 and 1-1.6:1.1 respectively.


    N.B Ignore the Dev field in the output of lsusb. This auto increments when new devices are plugged and doesn't really help you out.


    So how can you get to the port number you need? Well, you can find the specific device you're looking from from lsusb using the -d flag and providing the vendor and product ids obtained from the dmesg output:

    Code:
    lsusb -d 067b:2303
    Code:
    Bus 001 Device 007: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
    Not overly useful by itself, but it does give us the bus to look within.

    We could parse the tree from the lsusb -t output and work it out that way, or we could root around in the /sys/ folder to find what we want:

    Code:
    ls -ltrah /sys/bus/usb-serial/devices
    Code:
    lrwxrwxrwx 1 root root 0 Aug 31 10:07 ttyUSB0 -> ../../../devices/pci0000:00/0000:00:1c.4/0000:03:00.0/usb1/1-1/1-1.2:1.0/ttyUSB0
    In this instance I know I've only got the one serial device so I could parse this path to get the address.

    Or:

    Now that I know where my serial devices are, I can cat some information about them (not sure if this is the best way):

    Code:
    cat /sys/bus/usb/devices/1-1/1-1.2/1-1.2\:1.0/uevent
    Code:
    DEVTYPE=usb_interface
    DRIVER=pl2303
    PRODUCT=67b/2303/400
    TYPE=0/0/0
    INTERFACE=255/0/0
    MODALIAS=usb:v067Bp2303d0400dc00dsc00dp00icFFisc00ip00in00
    The product code there tells me that this is the device I'm looking for.


    I hope some approximation of that is useful to you.
    Miven likes this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •