如何使自定义 USB 设备在 Windows 中显示为 COM 端口?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7166052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I make a custom USB device show up in Windows as a COM Port?
提问by CodePoet
I have developed a USB device that communicates with linux over a simple but proprietary interface and some custom Linux drivers. My goal is to port this to Windows without writing windows drivers. What I would like to do is find an open source or inbuilt class driver for windows that would look like a COM port in Windows. Then I would tailor the embedded software to match what ever protocol and descriptors the virtual COM port expects to see.
我开发了一个 USB 设备,它通过一个简单但专有的接口和一些自定义的 Linux 驱动程序与 linux 通信。我的目标是在不编写 Windows 驱动程序的情况下将其移植到 Windows。我想做的是为 Windows 找到一个开源或内置的类驱动程序,它看起来像 Windows 中的 COM 端口。然后我将定制嵌入式软件以匹配虚拟 COM 端口期望看到的协议和描述符。
The idea would be that I could plug my device in to a Windows machine and a relatively high speed COM port would appear with out me having to develop Windows drivers for it.
我的想法是,我可以将我的设备插入 Windows 机器,并且会出现一个相对高速的 COM 端口,而我不必为它开发 Windows 驱动程序。
I have been looking at the USB CDC (Communications Device Class) documentation and it looks promising, but I don't know which sub interface would be best to use so that it would show up as a COM port.
我一直在查看 USB CDC(通信设备类)文档,它看起来很有希望,但我不知道最好使用哪个子接口,以便它显示为 COM 端口。
Has anyone here done any work like this before or could provide some insight? Specifically:
这里有没有人以前做过这样的工作或可以提供一些见解?具体来说:
- Are there virtual COM drivers "built in" to windows or would I need a 3rd party driver.
- Which CDC sub class should I use for simple RS232 emulation (No need for modem AT commands, etc)
- Is there a better option to do what I am trying to do.
- 是否有“内置”到 Windows 的虚拟 COM 驱动程序,或者我需要一个 3rd 方驱动程序。
- 我应该使用哪个 CDC 子类来进行简单的 RS232 仿真(不需要调制解调器 AT 命令等)
- 有没有更好的选择来做我想做的事情。
Thanks
谢谢
采纳答案by David Grayson
There is a USB-to-serial driver built in to Windows that will do what you want. It is called usbser.sys:
Windows 内置了一个 USB 转串口驱动程序,可以满足您的需求。它被称为 usbser.sys:
http://support.microsoft.com/kb/837637
http://support.microsoft.com/kb/837637
You will have to write an INF file and distribute that to your users, but that will not be too hard because it is only a few kilobytes of text and you can find examples online.
您必须编写一个 INF 文件并将其分发给您的用户,但这不会太难,因为它只有几千字节的文本,您可以在线找到示例。
I'm not aware of any great documentation for this driver by Microsoft, so my advice would be to find some other device that uses it, such as Pololu Wixel, and copy what they did.
我不知道微软有关于这个驱动程序的任何很好的文档,所以我的建议是找到一些其他使用它的设备,比如Pololu Wixel,并复制他们所做的。
Here are the device descriptors we used and the special control tranfers we had to implement: https://github.com/pololu/wixel-sdk/blob/master/libraries/src/usb_cdc_acm/usb_cdc_acm.c
以下是我们使用的设备描述符和我们必须实现的特殊控制传输:https: //github.com/pololu/wixel-sdk/blob/master/libraries/src/usb_cdc_acm/usb_cdc_acm.c
You can see our INF file, wixel_serial.inf, by downloading the software and looking in the drivers folder: http://www.pololu.com/docs/0J46/3.a(There are other files in there that are not necessary for you.)
您可以通过下载软件并查看驱动程序文件夹来查看我们的 INF 文件 wixel_serial.inf:http: //www.pololu.com/docs/0J46/3.a(其中还有其他不需要的文件为你。)
You can also look at the Arduino Uno because they use the same driver.
您还可以查看 Arduino Uno,因为它们使用相同的驱动程序。
Whatever you do, please don't use our USB Vendor ID in your product! You need to get your own.
无论您做什么,请不要在您的产品中使用我们的 USB 供应商 ID!你需要得到你自己的。
Update:In Windows 10, you don't need an INF file anymore because of the new usbser.inf driver that comes with Windows.
更新:在 Windows 10 中,由于 Windows 附带的新 usbser.inf 驱动程序,您不再需要 INF 文件。
回答by Jeff
If you are using a UART you can easily interface it to a FTDI USB chip like http://www.ftdichip.com/Products/ICs/FT232R.htmor a Prolific like http://www.prolific.com.tw/eng/products.asp?id=59
如果您使用的是 UART,您可以轻松地将其连接到 FTDI USB 芯片(如http://www.ftdichip.com/Products/ICs/FT232R.htm或 Prolific(如http://www.prolific.com.tw/) eng/products.asp?id=59
For development, prototype and testing I have half dozen of these laying around http://www.pololu.com/catalog/product/391
对于开发、原型和测试,我在http://www.pololu.com/catalog/product/391周围放置了六个
I connect it directly to the UART pins on AVR and 8051 micros.
我将它直接连接到 AVR 和 8051 micros 上的 UART 引脚。