如何为 Windows 平台的 USB 设备编写驱动程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/161273/
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 do I program a driver for a USB device for windows platform?
提问by atomicharri
I am looking for a device that reads wiring voltages via a USB interface and returns the data. How would I go about programming something to interpret this data and what language would I use?
edit:
If it helps, this project is to develop a digital tachometre for older engines that don't support a comprehensive ODB2 data port. Therefore, it will read voltages on a DC circuit and have an accurate graphical interface. I have absolutely no idea where to start with all this but am determined to make it work! it's for windows.
我正在寻找一种通过 USB 接口读取接线电压并返回数据的设备。我将如何编写一些程序来解释这些数据以及我将使用什么语言?
编辑:如果有帮助,这个项目是为不支持综合 ODB2 数据端口的旧引擎开发数字转速计。因此,它将读取直流电路上的电压并具有准确的图形界面。我完全不知道从哪里开始这一切,但我决心让它发挥作用!它用于窗户。
回答by Jon Cage
Cheat and use libusb. I did this for a project I've been working on for a while and wrote a C++/wxWidgetsapp to handle the data.
作弊并使用libusb。我为一个我已经工作了一段时间的项目做了这个,并编写了一个C++/ wxWidgets应用程序来处理数据。
I've been thinking recently of re-writing the app on the PC in wxPythonthough as it's much faster for GUI development.
我最近一直在考虑用wxPython在 PC 上重写应用程序,因为它对于 GUI 开发来说要快得多。
How you want to display / log the data? There are a lot of options available. You can do some pretty cool stuff (easily) with the OpenGL capabilities of wxWidgetswhether it's 2D or 3D data representation.
您希望如何显示/记录数据?有很多选择。无论是 2D 还是 3D 数据表示,您都可以使用wxWidgets 的 OpenGL 功能(轻松地)做一些非常酷的事情。
回答by Andrew Edgecombe
If you can I would suggest using a library like libusb, as kris and Jon Cage have suggested.
如果可以,我建议您使用 libusb 之类的库,正如 kris 和 Jon Cage 所建议的那样。
If libusb isn't going to suit your needs and you're developing for Windows you should have a look at the software that Jungoprovides. Again, this moves the usb software into user space rather than requiring Windows kernel development. (edit 3: Ilya points out in the comment that Jungo is also available for Linux)
如果 libusb 不能满足您的需求并且您正在为 Windows 开发,那么您应该查看Jungo提供的软件。同样,这将 USB 软件移动到用户空间,而不是需要 Windows 内核开发。(编辑 3:Ilya 在评论中指出 Jungo 也可用于 Linux)
If you must do some kernel development (either Windows or Linux) then C is pretty well the only option you have. Investigate thisbook by Rubini for linux development. For windows driver development I can recommend thisbook by Oney. But I'd investigate the libusb option in preference to the driver development in both cases.
如果您必须进行一些内核开发(Windows 或 Linux),那么 C 是您拥有的唯一选择。研究Rubini 的这本书,了解 Linux 开发。对于 Windows 驱动程序开发,我可以推荐Oney 的这本书。但是在这两种情况下,我会优先研究 libusb 选项而不是驱动程序开发。
Btw. If all you are interested in is being able to measure voltages on a usb device (and writing the code isn't important) there are many products out there that will do that for you. Take a look at some of the offerings from National Instruments. These will deal with the hard work of usb and the data acquisition and give you a nice programming interface to use in your application.
顺便提一句。如果您感兴趣的只是能够测量 USB 设备上的电压(并且编写代码并不重要),那么有很多产品可以为您做到这一点。看看National Instruments 的一些产品。这些将处理 USB 和数据采集的繁重工作,并为您提供一个很好的编程接口以在您的应用程序中使用。
(edit 2) There are also some usb-serial chips (eg. these) that can be interfaced directly to an embedded processor usig only a uart. Typically these come with drivers.
(编辑 2)还有一些 USB 串行芯片(例如这些)可以直接连接到嵌入式处理器,仅使用 uart。通常这些带有驱动程序。
回答by kris
回答by Dave Van den Eynde
Since you're still looking for a device that converts voltages into information, I suggest you take a look at devices that implement a USB-HID (Human Interface Device) interface, such as those found here.
由于您仍在寻找将电压转换为信息的设备,我建议您查看实现 USB-HID(人机接口设备)接口的设备,例如此处找到的设备。
They have the benefit of not requiring any device driver development to be made, or drivers to be installed. They are as plug and play as a mouse, keyboard or flash drive. The interface is pretty generic, and most manufacturers also provide the necessary libraries to read the information from the device, be notified when a device is plugged in/out, discover devices, and so on.
它们的优点是不需要进行任何设备驱动程序开发或安装驱动程序。它们与鼠标、键盘或闪存驱动器一样即插即用。该界面非常通用,大多数制造商还提供了必要的库来从设备读取信息、在设备插入/拔出时收到通知、发现设备等。
In addition, have a look at this articlethat explains how to use a HID device in C#, for example.
此外,请查看这篇文章,例如解释如何在 C# 中使用 HID 设备。
Dave
戴夫
回答by Kevin ORourke
Your easiest option is probably to buy some kind of off-the-shelf data acquisition device. Lots of companies make that kind of thing, but they're sometimes frighteningly expensive:
您最简单的选择可能是购买某种现成的数据采集设备。很多公司都在做这种事情,但有时它们的成本高得吓人:
You could also build your own from a kit, although I can't find any links for you just now.
您也可以从一个工具包中构建自己的工具包,尽管我现在找不到任何链接。
If you want something more custom you could use an EZ-USBor a PIC. They provide USB drivers (for Windows, at least) that allow you to interact with the device without writing drivers.
如果您想要更自定义的东西,您可以使用EZ-USB或PIC。它们提供 USB 驱动程序(至少适用于 Windows),允许您在不编写驱动程序的情况下与设备交互。
With most of these you have a fairly wide choice of programming languages, I've written software to communicate with EZ-USB devices from Visual Basic 6 in the past.
对于其中的大多数,您可以选择相当广泛的编程语言,我过去曾编写过与 Visual Basic 6 中的 EZ-USB 设备进行通信的软件。
回答by jeremy
Most microcontrollers have built in ADC, and a ton of these also have a built in usb subsystem. Cypress, PIC, AVR come to mind. Whenever I am doing USB work for my own projects, I use pyusband wxPython. They make it damn easy to get the job done, although there is quite a harsh initial learning curve.
大多数微控制器都内置了 ADC,其中很多还内置了 USB 子系统。想到了赛普拉斯、PIC、AVR。每当我为自己的项目进行 USB 工作时,我都会使用pyusb和wxPython。它们使完成工作变得非常容易,尽管初始学习曲线非常苛刻。
Shameless self plug aside, I wrote a small python driver with pyusb for a USB-LCD device. You can check out my source code here.
撇开无耻的自插不说,我用pyusb 为USB-LCD 设备编写了一个小型python 驱动程序。你可以在这里查看我的源代码。
回答by IgorM
I'm, personally, using Microchip PICs - they have AD/DA converters, USB ports, free drivers and boot loaders - and all this for under $4. After you plug in such a device you're getting one extra COM port - the rest is trivial.
我个人使用 Microchip PIC——它们有 AD/DA 转换器、USB 端口、免费驱动程序和引导加载程序——所有这些都低于 4 美元。插入这样的设备后,您将获得一个额外的 COM 端口 - 其余的都是微不足道的。
回答by plinth
You don't say what platform you're looking at. If you're targeting Windows, USB Revealedis an awesome reference.
你没有说你在看什么平台。如果您的目标是 Windows,USB Revealed是一个很棒的参考。
回答by darda
回答by Windows programmer
Seems to me that if you want to read wiring voltages then you need an A/D converter. Are you making your own A/D converter? If so, you've got some nice firmware programming to do on the device side, more than the host-side driver that you're asking about here. Otherwise you're going to buy an A/D converter, and you should just use the driver that the vendor supplies with it.
在我看来,如果您想读取接线电压,那么您需要一个 A/D 转换器。您是否正在制作自己的 A/D 转换器?如果是这样,那么您需要在设备端进行一些不错的固件编程,而不是您在这里询问的主机端驱动程序。否则,您将购买一个 A/D 转换器,您应该只使用供应商随附的驱动程序。