如何为 Windows 实现 USB 设备驱动程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1562891/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:17:17  来源:igfitidea点击:

How to implement a USB device driver for Windows?

cwindowsembeddeddriver

提问by Velho Kerho

How should I approach implementing a USB device driver for Windows? How should I take into account different versions of windows e.g: - Windows XP - Windows Vista - Windows 7

我应该如何为 Windows 实现 USB 设备驱动程序?我应该如何考虑不同版本的 Windows,例如: - Windows XP - Windows Vista - Windows 7

Is there open source solutions which could be used as a starting point? I'm a total newbie to windows driver development.

是否有可以用作起点的开源解决方案?我是 Windows 驱动程序开发的新手。

We have an embedded device with USB device port and we would like to have as low latency communication from the application level to the device as possible without sacrificing the data throughput. The actual data transferred is ADC/DAC data. Basically there is a lot of data which we need to transfer to a Windows machine as fast as possible.

我们有一个带有 USB 设备端口的嵌入式设备,我们希望在不牺牲数据吞吐量的情况下,从应用程序级别到设备的通信延迟尽可能低。实际传输的数据是 ADC/DAC 数据。基本上有很多数据需要尽快传输到 Windows 机器上。

回答by Dr. Watson

We need more information about the device to point you in the right direction, but here are a few steps to get you started:

我们需要有关该设备的更多信息来为您指明正确的方向,但这里有几个步骤可以帮助您入门:

  • register with Microsoft Connect so you can download the Windows Driver Kit
  • register with osr-onlineas you'll find great articles, plenty of information, and a newsgroup dediciated just to Windows drivers -- this place is a goldmine
  • buy Developing Drivers with WDF, which will help you make sense of driver development on Windows and give you a good foundation to read articles from OSR and Microsoft
  • Hope that you can use UMDF (user-mode drivers) as you can use C++ and just write COM code. If you're doing anything with USB that requires kernel-space....you've got a lot of reading and learning to do for the next year!
  • 注册 Microsoft Connect,以便您可以下载 Windows 驱动程序工具包
  • osr-online注册,因为您会发现很棒的文章、大量信息和专门针对 Windows 驱动程序的新闻组——这个地方是一个金矿
  • 购买使用 WDF 开发驱动程序,这将帮助您了解 Windows 上的驱动程序开发,并为您阅读 OSR 和 Microsoft 的文章打下良好的基础
  • 希望您可以像使用 C++ 一样使用 UMDF(用户模式驱动程序),只需编写 COM 代码。如果您正在使用 USB 做任何需要内核空间的事情……那么明年您有很多阅读和学习要做!

To answer your question on versions, the Driver Kit has tools that will help you manage creating different drivers. If you write a good driver, it should run on all three OS with no problems, and the differences will just be in the config area (not the binary)

为了回答您关于版本的问题,驱动程序工具包有一些工具可以帮助您管理创建不同的驱动程序。如果你编写了一个好的驱动程序,它应该可以在所有三个操作系统上运行都没有问题,差异只会在配置区域(而不是二进制文件)

Basically, it depends on how complex your device is. What type of driver are you trying to write? File system? MP3 player? Camera? Modem?

基本上,这取决于您的设备有多复杂。你想写什么类型的驱动程序?文件系统?MP3播放器?相机?调制解调器?

If you end up having to write a kernel mode driver, let me know and I can point you to some good articles and what not.

如果您最终不得不编写内核模式驱动程序,请告诉我,我可以为您指出一些好文章,什么不是。

I should also add that for around US $5,000, you can buy a license for WinDriver, a tool that takes all of the hard stuff out of driver development. You can use C++ or C# user-mode code to communicate with their driver that is custom generated for your device. This is the way to go if you have a tight deadline.

我还应该补充一点,您可以花大约 5,000 美元购买WinDriver的许可证,该工具可以消除驱动程序开发中的所有困难。您可以使用 C++ 或 C# 用户模式代码与为您的设备自定义生成的驱动程序进行通信。如果您的截止日期很紧,这就是要走的路。

回答by avra

You can take a look at windows variant of libusb*here*. There are wrappers for many programming languages on official libusb site and on the web.

您可以在此处查看libusb* 的windows 变体*。在官方 libusb 站点和网络上有许多编程语言的包装器。

回答by Keith Adler

回答by MSalters

If you have some form of control over the device side, have it implement an interface for which Windows already provides drivers. E.g. the USB HID class (literally Human Input Device, but neither the Human nor the Input is mandatory) already has Windows drivers, and there is a reasonable Win32 API on top. You're not going to get data rates anywhere near 480 Mbps, though.

如果你对设备端有某种形式的控制,让它实现一个 Windows 已经为其提供驱动程序的接口。例如,USB HID 类(字面意思是人工输入设备,但人工和输入都不是强制性的)已经有 Windows 驱动程序,并且有一个合理的 Win32 API。不过,您不会获得接近 480 Mbps 的数据速率。