ubuntu18.04 串口设备和串口号绑定

8 篇文章 0 订阅

参考:

  1. linux系统下串口设备和串口号绑定link
  2. Ubuntu17.04下串口设备如何绑定USB端口号link
  3. LINUX下 Udev详解link

TX2只带了两个 USB 接口,外接多个传感器的时候就得用 USB 扩展器,输入命令判断是否与传感器连接

  1. 查看端口
$ cd /dev && ll ttyUSB*
crwxrwxrwx 1 root dialout 188, 0 12月  5 11:34 ttyUSB0
crwxrwxrwx 1 root dialout 188, 1 12月  5 11:37 ttyUSB1
crwxrwxrwx 1 root dialout 188, 2 12月  5 11:34 ttyUSB2

$ ll  /dev/serial/by-id/
total 0
drwxr-xr-x 2 root root 100 12月  5 11:37 ./
drwxr-xr-x 4 root root  80 12月  5 11:34 ../
lrwxrwxrwx 1 root root  13 12月  5 11:34 usb-FTDI_FT232R_USB_UART_AB0LYN6O-if00-port0 -> ../../ttyUSB2
lrwxrwxrwx 1 root root  13 12月  5 11:37 usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0 -> ../../ttyUSB1
lrwxrwxrwx 1 root root  13 12月  5 11:34 usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0002-if00-port0 -> ../../ttyUSB0


当用相同的USB接口芯片时,也不知道对应关系,通过拔插和 lsusb 命令

$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 1ea7:0066  
Bus 001 Device 003: ID 0eef:0005 D-WAV Scientific Co., Ltd 
Bus 001 Device 002: ID 05e3:0610 Genesys Logic, Inc. 4-port hub
Bus 001 Device 008: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC
Bus 001 Device 009: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light
Bus 001 Device 006: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light
Bus 001 Device 005: ID 2109:2817 VIA Labs, Inc. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

知道ID 0403:6001 既({idVendor}:{idProduct})对应的 USB 传感器

udevadm info -a -p $(udevadm info -q path -n /dev/ttyUSB0)

这个是绿联的设备,KERNELS==“1-2”

在这里插入图片描述
需要用到KERNELS、idProduct、idVendor 三个信息,注意到传感器的KERNELS 1-2.4是 USB 扩展器KERNELS 1-2 的分支

KERNELS 1-2.4
ATTRS{idProduct} 6001
ATTRS{idVendor} 0403

在这里插入图片描述

$ udevadm info -a -p $(udevadm info -q path -n /dev/ttyUSB0) | grep serial
    SUBSYSTEMS=="usb-serial"
    ATTRS{serial}=="0003"
    ATTRS{serial}=="000000000"
    ATTRS{serial}=="3530000.xhci"
$ udevadm info -a -p $(udevadm info -q path -n /dev/ttyUSB1) | grep serial
    SUBSYSTEMS=="usb-serial"
    ATTRS{serial}=="0001"
    ATTRS{serial}=="000000000"
    ATTRS{serial}=="3530000.xhci"
$ udevadm info -a -p $(udevadm info -q path -n /dev/ttyUSB2) | grep serial
    SUBSYSTEMS=="usb-serial"
    ATTRS{serial}=="0002"
    ATTRS{serial}=="000000000"
    ATTRS{serial}=="3530000.xhci"

  1. 在/etc/udev/rules.d/目录下创建自己的99-*.rules文件
sudo gedit /etc/udev/rules.d/99-sensor-usb.rules

写入:

KERNELS=="1-2.4", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SYMLINK+="tp_sloar",MODE:="0777"
KERNELS=="1-2.2", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK+="stem32",MODE:="0777"
KERNELS=="1-2.3", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK+="imu_b9",MODE:="0777"

SYMLINK 相当于起的别名
MODE 0777->crwxrwxrwx 是文件类型加权限
参考 Ubuntu文件属性简介及简单修改方法

  1. 重启并查看配置是否生效
    重启
$reboot

等待开机,查看端口

$ ll /dev | grep ttyUSB
lrwxrwxrwx   1 root root           7 125 11:34 gps0 -> ttyUSB0
lrwxrwxrwx   1 root root           7 125 11:37 gps1 -> ttyUSB1
lrwxrwxrwx   1 root root           7 125 11:37 imu_b9 -> ttyUSB1
lrwxrwxrwx   1 root root           7 125 11:34 stem32 -> ttyUSB0
lrwxrwxrwx   1 root root           7 125 11:34 tp_sloar -> ttyUSB2
crwxrwxrwx   1 root dialout 188,   0 125 11:34 ttyUSB0
crwxrwxrwx   1 root dialout 188,   1 125 11:37 ttyUSB1
crwxrwxrwx   1 root dialout 188,   2 125 11:34 ttyUSB2

补充:
后面添加:

echo  'KERNEL=="1-2.4", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60",ATTRS{serial}=="0001", MODE:="0777", GROUP:="dialout", SYMLINK+="stm32_car"' >/etc/udev/rules.d/stm32_car.rules
echo  'KERNEL=="1-2.1.1", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60",ATTRS{serial}=="0002", MODE:="0777", GROUP:="dialout", SYMLINK+="ls_lidar"' >/etc/udev/rules.d/ls_lidar.rules
echo  'KERNEL=="1-2.3", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60",ATTRS{serial}=="0003", MODE:="0777", GROUP:="dialout", SYMLINK+="imu_b9"' >/etc/udev/rules.d/imu_b9.rules
service udev reload
sleep 2
service udev restart

对应的检查:

$ ll /dev | grep bus/usb
lrwxrwxrwx   1 root root          15 94 15:15 imu_b9 -> bus/usb/001/005
lrwxrwxrwx   1 root root          15 94 15:15 ls_lidar -> bus/usb/001/007
lrwxrwxrwx   1 root root          15 94 15:15 stm32_car -> bus/usb/001/006

大功告成!!!

  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值