如何动态找到USB设备路径?

发布于 2025-01-22 15:11:30 字数 1997 浏览 1 评论 0原文

我有一个覆盆子Pi 4连接到SIM7600 WaveShare调制解调器。 SIM7600创建了4个虚拟USB端口。这些虚拟端口之一用于GP,另一个用于实际调制解调器。

不幸的是,有时GPS设备在 /dev /ttyusb1或 /dev /ttyusb2上,而调制解调器似乎在 /dev /ttyusb3或 /dev /dev /ttyusb4上。

使用GPSD-clients软件包,我需要更改文件/etc/default/gpsd并在此行中添加GPS设备:

# Device gpsd should collect to at boot time.
# They need to be read/writeable, either by user gpsd or the group dialout.
DEVICES="/device/path/to/gps"

我有一个小的bash脚本,可以从GPS设备快速读取,以便我可以获得纬度和经度。但是,有时在重新启动后无法使用,因为GPS虚拟端口已更改。

#!/bin/bash
gpspipe -w -n 10 | grep -m 1 lon

LSUSB命令仅对SIM7600调制解调器产生一个结果,并且所有(虚拟)USB端口都是使用相同的序列号创建的,因此很难区分虚拟端口 - 哪个是GPS或调制解调器?

有什么方法可以动态地找到GPS的设备路径?也许使用bash脚本或编写UDEV规则。

LSUSB的结果:

Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 006: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port / Mobile Action MA-8910P
Bus 001 Device 005: ID 1c4f:0002 SiGma Micro Keyboard TRACER Gamma Ivory

# this is the modem
Bus 001 Device 004: ID 1e0e:9001 Qualcomm / Option SimTech, Incorporated 

Bus 001 Device 003: ID 1c4f:0034 SiGma Micro XM102K Optical Wheel Mouse
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
/dev/input/event1 - SIGMACHIP_USB_Keyboard
/dev/input/event3 - SIGMACHIP_USB_Keyboard
/dev/input/event2 - SIGMACHIP_USB_Keyboard
/dev/input/mouse0 - SIGMACHIP_Usb_Mouse
/dev/input/event0 - SIGMACHIP_Usb_Mouse
/dev/ttyUSB0 - Prolific_Technology_Inc._USB-Serial_Controller_D

# these are the modem usb virtual ports
/dev/ttyUSB1 - SimTech__Incorporated_SimTech__Incorporated_0123456789ABCDEF
/dev/ttyUSB4 - SimTech__Incorporated_SimTech__Incorporated_0123456789ABCDEF
/dev/ttyUSB2 - SimTech__Incorporated_SimTech__Incorporated_0123456789ABCDEF
/dev/ttyUSB5 - SimTech__Incorporated_SimTech__Incorporated_0123456789ABCDEF
/dev/ttyUSB3 - SimTech__Incorporated_SimTech__Incorporated_0123456789ABCDEF

I have a Raspberry Pi 4 connected to a SIM7600 Waveshare modem. The SIM7600 creates 4 virtual USB ports. One of these virtual ports is used for GPS and another is used for the actual modem.

Unfortunately, sometimes the GPS device is either on /dev/ttyUSB1 or /dev/ttyUSB2 while the modem seems to be either on /dev/ttyUSB3 or /dev/ttyUSB4.

Using the gpsd-clients package, I need to alter the file /etc/default/gpsd and add in the GPS device in this line:

# Device gpsd should collect to at boot time.
# They need to be read/writeable, either by user gpsd or the group dialout.
DEVICES="/device/path/to/gps"

I have a small bash script that gets a quick reading from the GPS device so I can get the latitude and longitude. However, sometimes it won't work after a reboot because the GPS virtual port has changed.

#!/bin/bash
gpspipe -w -n 10 | grep -m 1 lon

The lsusb command only yields one result for the SIM7600 modem and all the (virtual) USB ports are created with the same serial number, making it hard to differentiate between the virtual ports - which one is GPS or the modem?

Is there a way I can dynamically find the device path for the GPS? Perhaps using a bash script or writing a udev rule.

Results from lsusb:

Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 006: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port / Mobile Action MA-8910P
Bus 001 Device 005: ID 1c4f:0002 SiGma Micro Keyboard TRACER Gamma Ivory

# this is the modem
Bus 001 Device 004: ID 1e0e:9001 Qualcomm / Option SimTech, Incorporated 

Bus 001 Device 003: ID 1c4f:0034 SiGma Micro XM102K Optical Wheel Mouse
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
/dev/input/event1 - SIGMACHIP_USB_Keyboard
/dev/input/event3 - SIGMACHIP_USB_Keyboard
/dev/input/event2 - SIGMACHIP_USB_Keyboard
/dev/input/mouse0 - SIGMACHIP_Usb_Mouse
/dev/input/event0 - SIGMACHIP_Usb_Mouse
/dev/ttyUSB0 - Prolific_Technology_Inc._USB-Serial_Controller_D

# these are the modem usb virtual ports
/dev/ttyUSB1 - SimTech__Incorporated_SimTech__Incorporated_0123456789ABCDEF
/dev/ttyUSB4 - SimTech__Incorporated_SimTech__Incorporated_0123456789ABCDEF
/dev/ttyUSB2 - SimTech__Incorporated_SimTech__Incorporated_0123456789ABCDEF
/dev/ttyUSB5 - SimTech__Incorporated_SimTech__Incorporated_0123456789ABCDEF
/dev/ttyUSB3 - SimTech__Incorporated_SimTech__Incorporated_0123456789ABCDEF

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文