简体   繁体   English

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

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

I just recently learn Java and try to communicate to the device through USB port connection. 我刚刚学习Java并尝试通过USB端口连接与设备进行通信。 I've have used C# with OpenNETCF which allows me to send file and retrieve file on the device through USB port; 我已经使用C#和OpenNETCF,它允许我通过USB端口在设备上发送文件和检索文件; how can I achieve this with java? 我怎样才能用java实现这个目标?

I seearch on stackoverflow thread, How to communicate with a USB device under Windows and Java? 我看看stackoverflow线程, 如何在Windows和Java下与USB设备通信? , the comment made by christoffer is to hack the native code, but I don't quite which native code api that he referred to. ,christoffer的评论是破解本机代码,但我并不完全是他提到的本机代码api。 RAPI, maybe? RAPI,也许吧?

The only USB API I could find for Windows is here . 我能找到的唯一适用于Windows的USB API 就在这里 Seems as if it has limited functionality, but it might suit your needs. 似乎它的功能有限,但它可能适合您的需求。 A more complete UNIX API is also available. 还提供了更完整的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版。

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

我找到了这个页面,解释了如何在微控制器和Java应用程序之间进行通信: http//javausbapi.blogspot.com/

The native code API I referred to was the Windows DDK, ie the Driver Development Kit. 我提到的本机代码API是Windows DDK,即驱动程序开发工具包。 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. 现代版本似乎被称为Windows驱动程序工具包,因此google for Windows WDK :)应该有一些关于如何与USB设备通信的C示例,并且编写JNI包装器应该非常简单。

As a quick thought, you could use JNI, the Java Native Interface. 快速思考,您可以使用Java Native Interface JNI。 I've never used it myself though. 我自己从来没用过它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM