Windows和Java下如何与USB设备通信?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/544507/
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 to communicate with a USB device under Windows and Java?
提问by Gili
I'd like to communicate with a USB device under Windows and Java but I can't find a good library to do so. I don't want the user to have to install any extra hardware or device drivers to make this work. That is, I want to be able to interact with USB just like other Windows applications do.
我想在 Windows 和 Java 下与 USB 设备通信,但我找不到一个好的库来这样做。我不希望用户必须安装任何额外的硬件或设备驱动程序来完成这项工作。也就是说,我希望能够像其他 Windows 应用程序一样与 USB 交互。
I am familiar with jUSB and JSR 80 but both seem to be dead projects (at least for Windows).
我熟悉 jUSB 和 JSR 80,但两者似乎都是死项目(至少对于 Windows)。
采纳答案by Joonas Pulakka
I did quite a bit of research on this some time ago, and the unfortunate fact was that all the useful free USB+Windows+Java projects were dead. There is commercial and expensive (price $39.99 is not per developer, but per copy of your software sold!) JCommUSBlibrary which probably works, although I have no experience of it; we had to build our own custom C wrappers to the USB drivers and communicate with them through JNI.
前段时间我对此进行了相当多的研究,不幸的是,所有有用的免费USB+Windows+Java项目都已死。有商业的和昂贵的(价格 39.99 美元不是每个开发人员,而是每个销售的软件副本!)JCommUSB库可能有效,尽管我没有经验;我们必须为 USB 驱动程序构建我们自己的自定义 C 包装器,并通过 JNI 与它们通信。
回答by Toybuilder
libusb-win32 requires you to install their generic driver, which then makes a USB device available to you. I'm not sure that it's possible to do driver-less access of an USB device unless the device belongs to one of several standard classes (storage and HID, in particular).
libusb-win32 要求您安装他们的通用驱动程序,然后您就可以使用 USB 设备。我不确定是否可以对 USB 设备进行无驱动程序访问,除非该设备属于几个标准类之一(特别是存储和 HID)。
There is a Java wrapper for libusb-win32which might work for you. I haven't used it myself, though.
libusb-win32有一个Java 包装器,它可能适合您。不过我自己没用过。
回答by Christoffer
The fastest and easiest way is to hack some native code :) I wrote a small wrapper for HID devices that enabled my Java applications to read data from CalComp digitizers, so it's definitely doable and not too hard. The bad thing is that my work is still proprietary code owned by my former employer, so for legal reasons I can't release that as open-source -- yet.
最快和最简单的方法是破解一些本机代码 :) 我为 HID 设备编写了一个小包装器,它使我的 Java 应用程序能够从 CalComp 数字化仪读取数据,因此它绝对可行且不太难。不好的是,我的工作仍然是我的前雇主拥有的专有代码,因此出于法律原因,我还不能将其作为开源发布。
The good thing is that you can get a flying start with the HID example code from the Microsoft DDK :)
好消息是,您可以使用 Microsoft DDK 中的 HID 示例代码快速开始 :)
回答by Paul
Communication between Windows and a USB device by java. http://javausbapi.blogspot.com/2010/05/java-usb-api.html
Windows 和 USB 设备之间通过 java 进行通信。 http://javausbapi.blogspot.com/2010/05/java-usb-api.html
An example is conducted for a Freescale microcontroller
以飞思卡尔微控制器为例