Ubuntu 串口设备 USB tty

Ubuntu 串口设备 USB tty

概述

研究Ubuntu下串口设备的连接,简单的讲就是看有没有连接上,至于使用后面再说。

USB

使用命令如下可以查看USB接口的信息, dmesg命令用于显示开机信息,开机信息也保存在/var/log目录中,名称为dmesg的文件里。。参考链接

robots@Robots-ubuntu1604:~$ dmesg|grep usb

使用戴尔有线键盘和一个单片机进行测试,当连接戴尔键盘时可以看到最后信息,

robots@Robots-ubuntu1604:~$ dmesg|grep usb
[ 5647.766886] usb 1-2: new low-speed USB device number 8 using xhci_hcd
[ 5647.922281] usb 1-2: New USB device found, idVendor=413c, idProduct=2113
[ 5647.922288] usb 1-2: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[ 5647.922292] usb 1-2: Product: Dell KB216 Wired Keyboard
[ 5647.926885] input: Dell KB216 Wired Keyboard as /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/0003:413C:2113.0009/input/input33
[ 5647.987283] hid-generic 0003:413C:2113.0009: input,hidraw0: USB HID v1.11 Keyboard [Dell KB216 Wired Keyboard] on usb-0000:00:14.0-2/input0
[ 5647.992092] input: Dell KB216 Wired Keyboard as /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.1/0003:413C:2113.000A/input/input34
[ 5648.051504] hid-generic 0003:413C:2113.000A: input,hidraw1: USB HID v1.11 Device [Dell KB216 Wired Keyboard] on usb-0000:00:14.0-2/input1

虽然信息很多,但是只需要关注几个关键点就能知道具体的信息,如下表示这个设备已经成功识别,并且是一个低速USB设备,编号8,具体点是Dell KB216 Wired Keyboard。

[ 5647.766886] usb 1-2: new low-speed USB device number 8 using xhci_hcd
[ 5647.922281] usb 1-2: New USB device found, idVendor=413c, idProduct=2113
[ 5647.922288] usb 1-2: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[ 5647.922292] usb 1-2: Product: Dell KB216 Wired Keyboard

当使用单片机接入USB时,可以看到信息,都比较有用,全速USB设备,编号11,

[ 5811.809661] usb 1-2: new full-speed USB device number 11 using xhci_hcd
[ 5811.959355] usb 1-2: New USB device found, idVendor=1a86, idProduct=7523
[ 5811.959361] usb 1-2: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[ 5811.959366] usb 1-2: Product: USB2.0-Serial
[ 5811.960959] usb 1-2: ch341-uart converter now attached to ttyUSB0

注意,这表示这个设备已经连接到了ttyUSB0端口,ch341就是带数字签名的USB转UART串口驱动。

[ 5811.960959] usb 1-2: ch341-uart converter now attached to ttyUSB0

使用命令ls /dev/ttyUSB*可以看到,已经出现了设备ttyUSB0,对于USB设备也可以使用lsusb命令。接下来可以使用串口调试工具进行调试了。

robots@Robots-ubuntu1604:~$ ls /dev/ttyUSB*
/dev/ttyUSB0
robots@Robots-ubuntu1604:~$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 093a:2532 Pixart Imaging, Inc. 
Bus 001 Device 012: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter
Bus 001 Device 005: ID 8087:0aaa Intel Corp. 
Bus 001 Device 010: ID 413c:2113 Dell Computer Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

查看详细信息

使用udevadm info --attribute-walk --name=/dev/ttyUSB0命令可以实现对所有内容的查看,可以按照下面的属性设置rules文件。

$ udevadm info --attribute-walk --name=/dev/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/pci0000:00/0000:00:14.0/usb1/1-10/1-10.3/1-10.3:1.0/ttyUSB0/tty/ttyUSB0':
    KERNEL=="ttyUSB0"
    SUBSYSTEM=="tty"
    DRIVER==""

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10.3/1-10.3:1.0/ttyUSB0':
    KERNELS
  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值