2023年8月4日 星期五

USB conception

/sys/bus/usb/devices
1-0:1.0  3-0:1.0  3-10:1.0  3-11      3-11:1.1  3-4      3-4.2      3-4.4      3-4.4:1.1  3-4.4:1.3  3-4.4:1.5  3-4.4:1.7  3-4.4:1.9  3-8:1.0  3-9:1.0  4-0:1.0  usb2  usb4
2-0:1.0  3-10     3-10:1.1  3-11:1.0  3-11:1.2  3-4:1.0  3-4.2:1.0  3-4.4:1.0  3-4.4:1.2  3-4.4:1.4  3-4.4:1.6  3-4.4:1.8  3-8        3-9      3-9:1.1  usb1     usb3

解析:
<bus>-<port[.port[.port]]>:<config>.<interface>
For more info:
1. 【USB笔记】接口描述符Interface Descriptor
2. Understand USB (in Linux)
3. superuser.com/

dmesg
[13363.344895] cdc_acm 3-4.4:1.0: ttyACM0: USB ACM device
[13363.345308] cdc_acm 3-4.4:1.2: ttyACM1: USB ACM device
[13363.346187] cdc_acm 3-4.4:1.4: ttyACM2: USB ACM device
[13363.346989] cdc_acm 3-4.4:1.6: ttyACM3: USB ACM device
4G/5G 模組會有數個 multi interface (MI)
Windows:
    裝罝管理員裡, com port(右鍵,內容)
    詳細資料,屬性,硬體識別碼
    USB\VID_1E2D&PID_0069&REV_0000&MI_02

Linux:
    $ cat /sys/devices/pci0000:00/0000:00:14.0/usb3/3-4/3-4.4/3-4.4:1.6/bInterfaceNumber
    $ ls /sys/devices/pci0000:00/0000:00:14.0/usb3/3-4/3-4.4/3-4.4:1.6/tty





好用tool: lsusb.py
lsusb.py
Output:
$ ./lsusb.py -i
 WARNING: Failure to read usb.ids
usb1              1d6b:0002 09 1IF  [USB 2.00,   480 Mbps,   0mA] (xhci-hcd 0000:00:0d.0) hub
usb2              1d6b:0003 09 1IF  [USB 3.10, 10000 Mbps,   0mA] (xhci-hcd 0000:00:0d.0) hub
usb3              1d6b:0002 09 1IF  [USB 2.00,   480 Mbps,   0mA] (xhci-hcd 0000:00:14.0) hub
  3-4               1a40:0101 09 1IF  [USB 2.00,   480 Mbps, 100mA] () hub
    3-4.2             047d:2048 00 1IF  [USB 2.00,   1.5 Mbps, 100mA] (Primax Kensington Eagle Trackball)
      3-4.2:1.0         (IF) 03:01:02 1EP  () usbhid hidraw0 (hid-generic) input15 (hid-generic)
    3-4.4             1e2d:0069 ef 10IFs [USB 2.00,   480 Mbps, 500mA] (Cinterion Wireless Modules PLSx3 f7b292b4)
      3-4.4:1.0         (IF) 02:02:01 1EP  () cdc_acm tty/ttyACM0
      3-4.4:1.1         (IF) 0a:00:00 2EPs () cdc_acm
      3-4.4:1.2         (IF) 02:02:01 1EP  () cdc_acm tty/ttyACM1
      3-4.4:1.3         (IF) 0a:00:00 2EPs () cdc_acm
      3-4.4:1.4         (IF) 02:02:01 1EP  () cdc_acm tty/ttyACM2
      3-4.4:1.5         (IF) 0a:00:00 2EPs () cdc_acm
      3-4.4:1.6         (IF) 02:02:01 1EP  () cdc_acm tty/ttyACM3
      3-4.4:1.7         (IF) 0a:00:00 2EPs () cdc_acm
      3-4.4:1.8         (IF) 02:06:00 1EP  () cdc_ether net/wwx00a0c6292b40
      3-4.4:1.9         (IF) 0a:00:00 2EPs () cdc_ether
  3-8               04f3:0c11 00 1IF  [USB 2.00,    12 Mbps, 100mA] (ELAN ELAN:Fingerprint)
    3-8:1.0           (IF) ff:00:00 5EPs ()
  3-9               13d3:56a2 ef 2IFs [USB 2.00,   480 Mbps, 500mA] (Azurewave USB2.0 HD UVC WebCam 0x0001)
    3-9:1.0           (IF) 0e:01:00 1EP  () uvcvideo video4linux/video1 video4linux/video0 input/input19
    3-9:1.1           (IF) 0e:02:00 0EPs () uvcvideo
  3-10              8087:0029 e0 2IFs [USB 2.01,    12 Mbps, 100mA] ()
    3-10:1.0          (IF) e0:01:01 3EPs () btusb bluetooth/hci0
    3-10:1.1          (IF) e0:01:01 2EPs () btusb
  3-11              1044:7a3c 00 3IFs [USB 2.00,    12 Mbps, 500mA] (GIGABYTE Fusion RGB KB)
    3-11:1.0          (IF) 03:01:01 1EP  () usbhid hidraw1 (hid-generic) input16 (hid-generic)
    3-11:1.1          (IF) 03:01:01 1EP  () usbhid hidraw2 (hid-generic) input32 (hid-generic)
    3-11:1.2          (IF) 03:01:00 1EP  () usbhid hidraw3 (hid-generic) input34 input39 input35 input33 input36 (hid-generic)
usb4              1d6b:0003 09 1IF  [USB 3.10, 20000 Mbps,   0mA] (xhci-hcd 0000:00:14.0) hub



#!/bin/bash

# Function to check if the VID and PID match
function check_vid_pid {
    local vid_pid_dir="$1"
    local vid="$2"
    local pid="$3"

    local device_vid=$(cat "$vid_pid_dir/idVendor" 2>/dev/null)
    local device_pid=$(cat "$vid_pid_dir/idProduct" 2>/dev/null)

    if [[ "$device_vid" == "$vid" && "$device_pid" == "$pid" ]]; then
        echo "$vid_pid_dir"
        exit 0
    fi
}

# Search for the USB device with matching VID and PID
function search_usb_device {
    local vid="$1"
    local pid="$2"

    for device in /sys/bus/usb/devices/*; do
        if [[ -d "$device" ]]; then
            check_vid_pid "$device" "$vid" "$pid"
        fi
    done

    echo "USB device with VID=$vid and PID=$pid not found."
    exit 1
}

function detail_usb_info {
    vid_pid_dir=$1
    ver=$(cat $vid_pid_dir/version)
    echo "$vid_pid_dir, $(cat $vid_pid_dir/speed)Mbits, $(cat $vid_pid_dir/bMaxPower), USB$ver"
   #udevadm info $vid_pid_dir
}

function find_ttyUSB_ACM {
    path=$1
    for ttyname in $(find $1 -maxdepth 3 -type d | grep ttyACM); do
        echo $ttyname
    done
    
    for ttyname in $(find $1 -maxdepth 2 -type d | grep ttyUSB); do
        echo $ttyname
    done
}

# Usage: ./find_usb_device.sh VID PID
if [[ $# -ne 2 ]]; then
    echo "Usage: $0 VID PID"
    exit 1
fi

path=$(search_usb_device "$1" "$2")
detail_usb_info $path/

find_ttyUSB_ACM $path/

output:
./find_usb_device.sh 1e2d 0069
/sys/bus/usb/devices/3-2/, 480Mbits, 500mA, USB 2.00
/sys/bus/usb/devices/3-2/3-2:1.6/tty/ttyACM3
/sys/bus/usb/devices/3-2/3-2:1.4/tty/ttyACM2
/sys/bus/usb/devices/3-2/3-2:1.2/tty/ttyACM1
/sys/bus/usb/devices/3-2/3-2:1.0/tty/ttyACM0

沒有留言:

張貼留言