ubuntu中绑定(同一类型设备)USB串口名称

ubuntu中绑定(同一类型设备)USB串口名称

参考:
ubuntu中绑定USB串口的方法,包括同一型号的USB串口
关于在ubuntu上绑定串口(针对多个相同设ID的串口设备)
ubuntu中绑定USB端口/串口名称,包括同一类型USB设备。
话不多说,直接上操作流程。

操作步骤:

1 查看接入设备名称(及ID)

通过插拔前后,使用lsusb查看接入设备名称,如我这里的Silicon Labs Cp210x UART Bridge
idVendor=10c4,idProduct=ea60
在这里插入图片描述

2 查看设备kernel和id (针对同时使用多个同一类型(id)设备)

使用dmesg | grep usb命令,找到刚查看的设备kernel和id。
如我这里:kernel=1-2.4;idVendor=10c4,idProduct=ea60在这里插入图片描述
需注意事项:值得注意的是:这里的KERNEL=="1-2.4"是指对应到的硬件设备端口,如果重新插拔到其他端口位置,则设置的规则会无效,即不会绑定成功。如果不会同时使用多个同一类型(id)设备),最好不要使用此种方法。

3 绑定设备

在/etc/udev/rules.d文件夹下新建规则文件xxxx.rules(xxxx为自定义命名)

cd /etc/udev/rules.d
sudo gedit xxxx.rules

在文件中添加以下字段后保存:
一般情况(不会同时使用多个同一类型(id)设备):

KERNEL=="ttyUSB*",ATTRS{idVendor}=="10c4",ATTRS{idProduct}=="ea60", MODE:="0777",SYMLINK+="lds1"

特殊情况(会同时使用同一类型(id)设备,通过kernel值区分连接端口位置,针对一般情况下重新插拔后ttyUSB*可能会随着接入顺序改变)

KERNEL=="1-2.4",ATTRS{idVendor}=="10c4",ATTRS{idProduct}=="ea60", MODE:="0777",SYMLINK+="lds1"

其中SYMLINK+="lds1"即为要绑后使用的名称。
note:你也可以通过设置多个规则文件,给予同一个USB端口(同一类型设备)不同的绑定名称,方便在不同的工程中使用,对应到相应的设备。

你也可以使用终端直接输入:

echo  'KERNELS=="ttyUSB*", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", MODE:="0777", SYMLINK+="lds1"' >/etc/udev/rules.d/xxxx.rules

即在目录下生成xxxx.rules文件,并添加'KERNELS=="ttyUSB*", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", MODE:="0777", SYMLINK+="lds1"' 内容。

4 重新加载 dev 规则

使用以下命令重新加载dev规则

sudo udevadm control --reload-rules && udevadm trigger

5 查看绑定状态

将USB端口重新插拔(如果你操作时一直连着的话),使用sudo ls -l /dev | grep xxx查看是否绑定成功(xxx为绑定的新名称)。
一般绑定:
在这里插入图片描述
特殊绑定:
在这里插入图片描述
多个名称绑定:
在这里插入图片描述

end Note:

可以在同一个.rules文件中添加多个绑定哟,适用同一主机接入多个不同设备。

  • 1
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
This bundle contains a modified CP210x driver for the 4.10.0 kernel (Ubuntu 17.04). It contains: - Support for the CP2102N NOTE: This driver is an example of how to perform GPIO operations within the CP210x driver since the driver on kernel.org does not support GPIO at this time. This driver has only been written and tested on the Linux 3.13.0 kernel on Ubuntu 14.04. This driver is a modified version of the existing driver in the Linux 3.13.0 kernel, which is maintained at kernel.org. It is recommened to use the driver there that matches your specific kernel version: www.kernel.org Build instrutions: Ubuntu: 1. make ( your cp210x driver ) 2. cp cp210x.ko to /lib/modules//kernel/drivers/usb/serial 3. insmod /lib/modules/<kernel-version/kernel/drivers/usb/serial/usbserial.ko 4. insmod cp210x.ko RedHat: 1. yum update kernel* //need to update the kernel first otherwise your header won't match 2. yum install kernel-devel kernel-headers //get the devel and header packages. 3. reboot //your build link should be fixed after your system come back 4. make ( your cp210x driver ) // should be able to build successfully at this point 5. cp cp210x.ko to /lib/modules//kernel/drivers/usb/serial 6a. insmod /lib/modules/<kernel-version/kernel/drivers/usb/serial/usbserial.ko 6. insmod cp210x.ko 7. sudo chmod 666 /dev/ttyUSB0 8. sudo chmod 666 /dev/ttyUSB1 GPIO example: This shows how to use the two IOCTLs to set GPIO state. Build instructions: 1. g++ cp210x_gpio_example.c -o cp210x_gpio_example 2. ./cp210x_gpio_example

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值