简体   繁体   English

具有多个串行端口的USB通信设备,可在所有平台上运行

[英]USB Communications device with multiple serial ports, working on all platforms

We have an embedded device that connects to the PC via USB, and it has multiple virtual serial ports (CDC-ACM). 我们有一个嵌入式设备通过USB连接到PC,它有多个虚拟串口(CDC-ACM)。

We have this working on Windows. 我们有这个在Windows上工作。 On the embedded device, we have multiple CDC-ACM interfaces. 在嵌入式设备上,我们有多个CDC-ACM接口。 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. USB描述符将其声明为复合设备(class = 0xEF,sub-class = 2,protocol = 1),并且每个虚拟串行端口都有一个“Interface Association Descriptor”。 On Windows, we use an INF file that installs usbser.sys for each CDC-ACM control interface (MI_00, MI_02, etc). 在Windows上,我们使用INF文件为每个CDC-ACM控制接口(MI_00,MI_02等)安装usbser.sys。

However, as we've found, this method doesn't seem to work for Mac. 但是,正如我们发现的,这种方法似乎不适用于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. 我发现我可以通过将其更改为“通信”类(类= 2,子类= 0,协议= 0)并删除IAD来使其适用于Mac和Linux。 (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. (对于Linux,使用Ubuntu进行测试,我发现这适用于Ubuntu Linux内核2.6.35-28或更新。使用早期内核,只有第一个串口工作。)但是,这种方法不适用于Windows。

What method can be used to make a USB device with multiple virtual serial ports, that works on Windows, Mac, and Linux? 可以使用什么方法制作具有多个虚拟串行端口的USB设备,适用于Windows,Mac和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. 我想我更喜欢尽可能使用CDC-ACM标准的解决方案,并尽可能避免使用自己编写驱动程序的选项。

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. 我可以想到的一种方式就是设备本身就是一个USB集线器,它附有多个独立的单串口设备。 This isn't pretty but very bulletproof. 这不是很漂亮,但非常防弹。

One solution that I've found, which I think could work (subject to further testing on Windows): 我发现的一个解决方案,我认为可以使用(需要在Windows上进行进一步测试):

Make the device enumerate in the way that works for the Mac: 使设备以适用于Mac的方式进行枚举:

  • Make it "Communications" class (class=2, sub-class=0, protocol=0), not composite device. 使其成为“通信”类(class = 2,sub-class = 0,protocol = 0),而不是复合设备。
  • Remove the IADs. 删除IAD。

The device should "just work" on Mac and recent Linux, in this configuration. 在此配置中,该设备应该在Mac和最近的Linux上“正常工作”。 (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.) (对于Linux,使用Ubuntu进行测试,我发现这适用于Ubuntu Linux内核2.6.35-28或更新。使用早期内核,只有第一个串口工作。)

Then, for Windows, modify the INF file for the device, to explicitly load the composite device driver usbccgp.sys . 然后,对于Windows,修改设备的INF文件,以显式加载复合设备驱动程序usbccgp.sys I'm a novice with Windows INF files, but here are the relevant snippets from what I could figure out so far: 我是Windows INF文件的新手,但这里是我到目前为止所知的相关片段:

[CCGPDriverInstall.NT]
Include=usb.inf
Needs=Composite.Dev.NT
AddReg=CCGPDriverInstall.AddReg

[CCGPDriverInstall.NT.Services]
Include=usb.inf
Needs=Composite.Dev.NT.Services

[CCGPDriverInstall.AddReg]
HKR,,EnumeratorClass, 0x00000001,02,00,00

... ...

[DeviceList]
%DESCRIPTION_DEVICE%=CCGPDriverInstall, USB\VID_FFFF&PID_0001
%DESCRIPTION_AT%=DriverInstall, USB\VID_FFFF&PID_0001&MI_00 
%DESCRIPTION_MENU%=DriverInstall, USB\VID_FFFF&PID_0001&MI_02 

[DeviceList.NTamd64] 
%DESCRIPTION_DEVICE%=CCGPDriverInstall, USB\VID_FFFF&PID_0001
%DESCRIPTION_AT%=DriverInstall, USB\VID_FFFF&PID_0001&MI_00 
%DESCRIPTION_MENU%=DriverInstall, USB\VID_FFFF&PID_0001&MI_02 

[DeviceList.NTx86...1]
%DESCRIPTION_DEVICE%=CCGPDriverInstall, USB\VID_FFFF&PID_0001
%DESCRIPTION_AT%=DriverInstall, USB\VID_FFFF&PID_0001&MI_00 
%DESCRIPTION_MENU%=DriverInstall, USB\VID_FFFF&PID_0001&MI_02 

With the INF file explicitly loading the usbccgp.sys driver, both USB serial ports worked for me on Windows XP SP3 32-bit. 使用INF文件显式加载usbccgp.sys驱动程序,两个USB串行端口在Windows XP SP3 32位上为我工作。

I have done only limited testing so far, so I'd be interested to hear how well this works, or not, for others. 到目前为止,我只进行了有限的测试,所以我很想知道其他人是否有效。

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). 由于Apple的驱动程序不支持复合CDC设备,我建议您以某种方式重新配置设备并使备用描述符显示为CDC,或者坚持使用复合并使用第三方驱动程序(我的公司为OS X制作CDC ACM驱动程序)这可能会支持你的设备)。

It may also be possible to force the issue with a codeless kext. 也可以用无代码kext强制解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM