dongyixiu3110 2018-11-27 00:24
浏览 374

如何使用golang的gousb通过VID:PID将活动的USB设备映射到其操作系统串行端口名称/路径?

I've developed a custom USB comms device that has a unique VID:PID. When using lsusb I can of course see this VID:PID.

When connected, this device is controlled by my golang software tools. These tools use standard open/read/write calls with OS paths such as /dev/tty.usbmodem14421 (mac) or /dev/ttyS0 (linux) or COM13 (win).

But it's a horrendous task for a "normal" using any of these OS's to figure out what port was dynamically assigned when they plug it in. I'd very much like to make this easier.

I can see in google/gousb that I can enumerate devices to look for my VID:PID, or can even use OpenDeviceWithVidPid() to see if it's there.

And of course I can enumerate OS serial ports devices on each OS if necessary.

However, perhaps because of my lack of depth in USB features/terminology, I can't seem to find a way to answer the question "If OpenDeviceWithVidPid returns a (non-nil) device, how may I map this to its /dev/* or COM* serial port path?"

My utils need to run on all of Win, MacOS, and Linux, so if there's a platform-independent way of doing this it would be ideal.

Guidance appreciated; thanks very much.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Stata 面板数据模型选择
    • ¥20 idea运行测试代码报错问题
    • ¥15 网络监控:网络故障告警通知
    • ¥15 django项目运行报编码错误
    • ¥15 请问这个是什么意思?
    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services
    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用