如何使用 Java 通过 USB 端口与设备通信?

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

How can I use Java to communicate to device through USB port?

javausbmobile-devices

提问by Bopha

I just recently learn Java and try to communicate to the device through USB port connection. I've have used C# with OpenNETCF which allows me to send file and retrieve file on the device through USB port; how can I achieve this with java?

我最近刚刚学习 Java 并尝试通过 USB 端口连接与设备进行通信。我已经将 C# 与 OpenNETCF 一起使用,它允许我通过 USB 端口在设备上发送文件和检索文件;我怎样才能用java实现这个?

I seearch on stackoverflow thread, How to communicate with a USB device under Windows and Java?, the comment made by christoffer is to hack the native code, but I don't quite which native code api that he referred to. RAPI, maybe?

我在 stackoverflow 线程上看到了,如何在 Windows 和 Java 下与 USB 设备通信?,christoffer的评论是hack native code,但是我不太清楚他指的是哪个native code api。RAPI,也许?

回答by Eric Petroelje

The only USB API I could find for Windows is here. Seems as if it has limited functionality, but it might suit your needs. A more complete UNIX APIis also available.

我能找到的唯一适用于 Windows 的 USB API在这里。似乎它的功能有限,但它可能适合您的需求。还可以使用更完整的UNIX API

ETA: Found a link to the official Java USB implementation, but looks like the windows version is still in alpha.

ETA:找到了官方Java USB 实现的链接,但看起来 windows 版本仍处于 alpha 阶段。

回答by Christoffer

The native code API I referred to was the Windows DDK, i.e. the Driver Development Kit. The modern version seem to be called Windows Driver Kit, so google for Windows WDK :) There should be a few C samples on how to communicate with USB devices, and it should be pretty straightforward to write a JNI wrapper from those.

我提到的原生代码 API 是 Windows DDK,即驱动程序开发工具包。现代版本似乎被称为 Windows Driver Kit,所以 google for Windows WDK :) 应该有一些关于如何与 USB 设备通信的 C 示例,并且从这些中编写 JNI 包装器应该非常简单。

回答by Humphrey Bogart

As a quick thought, you could use JNI, the Java Native Interface. I've never used it myself though.

作为一个快速的想法,您可以使用 JNI,即 Java 本机接口。不过我自己从来没有用过。

回答by rocky

I found this page that explains how to perform a communication between a microcontroller and a java application: http://javausbapi.blogspot.com/

我发现这个页面解释了如何在微控制器和 java 应用程序之间执行通信:http: //javausbapi.blogspot.com/

回答by Cristiano Ghersi

The Best way I found to communicate with USB is through RxTx library.

我发现与 USB 通信的最佳方式是通过 RxTx 库。

You can find an example of the usage here: http://www.snip2code.com/Snippet/1044/Java--read-from-USB-using-RXTX-library

您可以在此处找到用法示例:http: //www.snip2code.com/Snippet/1044/Java--read-from-USB-using-RXTX-library