我最初在 SU 上问了这个问题,但是它与 Ubuntu 密切相关,所以我把它移到这里。
我安装了433Mhz 收发器在我的 Ubuntu 系统 (3.8.0-35) 上。它是一种 USB 转串行设备,并且以某种方式被识别:
dmesg
输出:
[ 324.051498] usb 3-1: new full-speed USB device number 2 using xhci_hcd
[ 324.088070] usb 3-1: New USB device found, idVendor=10c4, idProduct=8668
[ 324.088081] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 324.088087] usb 3-1: Product: NETUSB1100 NEWMSG
[ 324.088093] usb 3-1: Manufacturer: HZWB
[ 324.102259] hid-generic 0003:10C4:8668.0002: hiddev0,hidraw1: USB HID v1.01 Device [HZWB NETUSB1100 NEWMSG ] on usb-0000:0e:00.0-1/input0
lsusb
输出:
Bus 003 Device 002: ID 10c4:8668 Cygnal Integrated Products, Inc.
我想访问它(通过接收命令例如),但我无法获得相关路径。插入后/dev
的内容没有改变,所以肯定缺少了一些东西。/dev
为了创建/dev/...
可在脚本中使用设备路径,还必须执行哪些其他步骤?
编辑后莱肯斯泰因的答案:输出tree /sys/bus/usb/drivers/
以下内容modprobe cp210x
(删除了不相关的部分)。请注意,重新启动后,上面3-1
的内容变为了3-2
以下内容。我在测试中考虑到了这一点。
/sys/bus/usb/drivers/
├── cp210x
│ ├── bind
│ ├── module -> ../../../../module/usbserial
│ ├── uevent
│ └── unbind
├── hub
│ ├── 1-0:1.0 -> ../../../../devices/pci0000:00/0000:00:1a.0/usb1/1-0:1.0
│ ├── 1-1:1.0 -> ../../../../devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1:1.0
│ ├── 2-0:1.0 -> ../../../../devices/pci0000:00/0000:00:1d.0/usb2/2-0:1.0
│ ├── 2-1:1.0 -> ../../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1:1.0
│ ├── 3-0:1.0 -> ../../../../devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-0:1.0
│ ├── 4-0:1.0 -> ../../../../devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb4/4-0:1.0
│ ├── bind
│ ├── module -> ../../../../module/usbcore
│ ├── new_id
│ ├── remove_id
│ ├── uevent
│ └── unbind
├── usb
│ ├── 1-1 -> ../../../../devices/pci0000:00/0000:00:1a.0/usb1/1-1
│ ├── 1-1.2 -> ../../../../devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2
│ ├── 1-1.3 -> ../../../../devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.3
│ ├── 1-1.4 -> ../../../../devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.4
│ ├── 1-1.6 -> ../../../../devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.6
│ ├── 2-1 -> ../../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1
│ ├── 3-2 -> ../../../../devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-2
│ ├── bind
│ ├── uevent
│ ├── unbind
│ ├── usb1 -> ../../../../devices/pci0000:00/0000:00:1a.0/usb1
│ ├── usb2 -> ../../../../devices/pci0000:00/0000:00:1d.0/usb2
│ ├── usb3 -> ../../../../devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3
│ └── usb4 -> ../../../../devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb4
├── usbhid
│ ├── 1-1.2:1.0 -> ../../../../devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2/1-1.2:1.0
│ ├── 3-2:1.0 -> ../../../../devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-2/3-2:1.0
│ ├── bind
│ ├── module -> ../../../../module/usbhid
│ ├── new_id
│ ├── remove_id
│ ├── uevent
│ └── unbind
├── usbserial
│ ├── bind
│ ├── module -> ../../../../module/usbserial
│ ├── uevent
│ └── unbind
├── usbserial_generic
│ ├── bind
│ ├── module -> ../../../../module/usbserial
│ ├── uevent
│ └── unbind
编辑:dmesg
在 cp210x.ko 重新编译并重启后添加(使用新的 cp210x.ko)
[ 1.352918] usb 3-2: new full-speed USB device number 2 using xhci_hcd
[ 1.389854] usb 3-2: New USB device found, idVendor=10c4, idProduct=8668
[ 1.389865] usb 3-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 1.389871] usb 3-2: Product: NETUSB1100 NEWMSG
[ 1.389877] usb 3-2: Manufacturer: HZWB
[ 1.399869] usbcore: registered new interface driver usbhid
[ 1.399872] usbhid: USB HID core driver
[ 1.406870] hid-generic 0003:10C4:8668.0001: hiddev0,hidraw0: USB HID v1.01 Device [HZWB NETUSB1100 NEWMSG ] on usb-0000:0e:00.0-2/input0
经过手册modprobe cp210x
,多余的线条dmesg
。
[ 1313.312593] usbcore: registered new interface driver usbserial
[ 1313.312642] usbcore: registered new interface driver usbserial_generic
[ 1313.312674] usbserial: USB Serial support registered for generic
[ 1313.329536] usbcore: registered new interface driver cp210x
[ 1313.329575] usbserial: USB Serial support registered for cp210x
(end of file)
答案1
当通用 HID 驱动程序拥有某个设备时,这清楚地表明该设备缺少更具体的驱动程序。我为您的设备(10[Cc]4
和8668
)搜索了内核树(3.13),但没有找到该设备的驱动程序。我找到的最接近的是模块cp210x
,但它没有您的8668
设备的条目。
您可以尝试手动将设备绑定到驱动cp210x
程序(更改3-1
为中列出的地址dmesg
):
sudo modprobe cp210x
sudo tee /sys/bus/usb/drivers/usbhid/unbind <<<3-1
sudo tee /sys/bus/usb/drivers/cp210x/bind <<<3.1
尝试编辑 cp210x 模块并将您的产品 ID 添加到列表中:
apt-get source linux-headers-$(uname -r)
cd linux-lts-*/drivers/usb/serial
wget https://gist.github.com/Lekensteyn/8544581/raw/cp210x-10c4-8668.patch
patch < cp210x-10c4-8668.patch
如果你不想获取 124MB 的源代码,你只需要 Makefile 和 cp210x.c 文件。请参阅https://gist.github.com/Lekensteyn/8544581针对基于 3.8.0-35-generic 的已修补版本。
然后构建模块(如果尚未安装,build-essential
请使用以下命令安装包):apt-get
make -C /usr/src/linux-headers-$(uname -r) M=$PWD cp210x.ko
然后卸载旧模块(如果有)并加载新构建的模块(如果已启用安全启动,则需要禁用它):
sudo rmmod cp210x
sudo insmod cp210x.ko
答案2
我使用 shell 脚本来管理识别设备节点并使用自定义 cp210x 驱动程序。它们还提供了适当的 udev 规则和脚本,以便在 CP210X 设备热插拔时动态执行脚本。
github.com/RishiGupta12/serial-communication-manager/tree/master/drivers/cp210x-silicon-labs