具有多个串行端口的 USB 通信设备,适用于所有平台
我们有一个通过 USB 连接到 PC 的嵌入式设备,它有多个虚拟串行端口 (CDC-ACM)。
我们可以在 Windows 上使用此功能。在嵌入式设备上,我们有多个CDC-ACM接口。 USB 描述符将其声明为复合设备(类 = 0xEF,子类 = 2,协议 = 1),并且每个虚拟串行端口都有一个“接口关联描述符”。在 Windows 上,我们使用 INF 文件为每个 CDC-ACM 控制接口(MI_00、MI_02 等)安装 usbser.sys。
然而,正如我们发现的,这种方法似乎不适用于 Mac。我发现通过将其更改为“通信”类(类 = 2,子类 = 0,协议 = 0)并删除 IAD,我可以让它在 Mac 和 Linux 上工作。 (对于 Linux,使用 Ubuntu 进行测试,我发现这适用于 Ubuntu Linux 内核 2.6.35-28 或更高版本。对于早期内核,只有第一个串行端口可以工作。)但是,这种方法不适用于 Windows。
有什么方法可以制作一个具有多个虚拟串口的USB设备,可以在Windows、Mac和Linux上运行?我认为我更喜欢尽可能使用 CDC-ACM 标准的解决方案,并尽可能避免编写自己的驱动程序选项。
We have an embedded device that connects to the PC via USB, and it has multiple virtual serial ports (CDC-ACM).
We have this working on Windows. On the embedded device, we have multiple CDC-ACM interfaces. The USB descriptors declare it as a composite device (class=0xEF, sub-class=2, protocol=1), and it has an "Interface Association Descriptor" for each virtual serial port. On Windows, we use an INF file that installs usbser.sys for each CDC-ACM control interface (MI_00, MI_02, etc).
However, as we've found, this method doesn't seem to work for Mac. I've found that I can get it to work for the Mac and Linux, by changing it to a "Communications" class (class=2, sub-class=0, protocol=0), and removing the IADs. (For Linux, testing with Ubuntu, I found that this worked with the Ubuntu Linux kernel 2.6.35-28 or newer. With earlier kernels, only the first serial port worked.) But then, this method doesn't work for Windows.
What method can be used to make a USB device with multiple virtual serial ports, that works on Windows, Mac, and Linux? I think I'd prefer a solution that uses the CDC-ACM standard as much as possible, and avoids the write-your-own-drivers option as much as possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我能立即想到的一种方法是,该设备将自己呈现为一个 USB 集线器,并连接有多个单独的单串行端口设备。这并不漂亮,但非常防弹。
The one way I can think of off top of my head would be the device presents itself as an USB hub with multiple separate single-serial-port devices attached to it. This isn't pretty but very bulletproof.
由于 Apple 的驱动程序不支持复合 CDC 设备,我建议要么以某种方式重新配置您的设备并使备用描述符成为纯 CDC,要么坚持使用复合并使用第三方驱动程序(我的公司制作 CDC ACM 适用于 OS X 的驱动程序,可能会支持您的设备)。
也可以使用无代码 kext 来强制解决此问题。
As Apple's drivers don't support composite CDC devices, I'd suggest either making your device reconfigure somehow and making your alternate descriptors plain CDC, or sticking with the composite and using a third party driver (my company makes CDC ACM drivers for OS X which will probably support your device).
It may also be possible to force the issue with a codeless kext.
我找到了一种解决方案,我认为该解决方案可行(需要在 Windows 上进行进一步测试):
使设备以适用于 Mac 的方式进行枚举:
在此配置下,设备应该在 Mac 和最新的 Linux 上“正常工作”。 (对于 Linux,使用 Ubuntu 进行测试,我发现这适用于 Ubuntu Linux 内核 2.6.35-28 或更高版本。对于早期内核,只有第一个串行端口可以工作。)
然后,对于 Windows,修改设备的 INF 文件,显式加载复合设备驱动程序
usbccgp.sys
。我是 Windows INF 文件方面的新手,但以下是我迄今为止所能想到的相关片段:...
INF 文件显式加载
usbccgp.sys
驱动程序,无论是 USB 串行还是ports 在 Windows XP SP3 32 位上对我有用。到目前为止,我只做了有限的测试,所以我很想知道这对其他人来说效果如何。
One solution that I've found, which I think could work (subject to further testing on Windows):
Make the device enumerate in the way that works for the Mac:
The device should "just work" on Mac and recent Linux, in this configuration. (For Linux, testing with Ubuntu, I found that this worked with the Ubuntu Linux kernel 2.6.35-28 or newer. With earlier kernels, only the first serial port worked.)
Then, for Windows, modify the INF file for the device, to explicitly load the composite device driver
usbccgp.sys
. I'm a novice with Windows INF files, but here are the relevant snippets from what I could figure out so far:...
With the INF file explicitly loading the
usbccgp.sys
driver, both USB serial ports worked for me on Windows XP SP3 32-bit.I have done only limited testing so far, so I'd be interested to hear how well this works, or not, for others.