如何在java中访问USB端口 [英] How to access USB ports in java

查看:864
本文介绍了如何在java中访问USB端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个访问usb端口的java应用程序来读取和写入通过usb连接的设备。我面临的问题是我不知道在java中使用什么来做这样的事情。我在网上搜索了一下名为 JUSB 的东西,但所有的帖子看起来都很旧了。

I'm trying to write a java application that accesses the usb ports to read from and write to a device connected through usb. The problem I face is that I don't know what exactly to use in java to do such a thing. I searched online and found something called JUSB but all the posts seem fairly old.

目前我正在使用 RXTX 库但我有时会遇到一些同步错误。当我使用C#做相同的操作时,它需要的代码要少得多,而且我不会遇到任何相同的同步错误。

Currently I'm using the RXTX libraries but I sometimes run into some sync error. When I use C# to do the equivalent it requires far less code and I don't face any of the same sync error.

我的问题是,我可以用来访问usb端口的最新版JRE内置了什么那个和等效的C#代码一样容易吗?

My question is, is there anything built into the latest version of the JRE I can use to access the usb ports (that is just as easy as the equivalent C# code)?

推荐答案

在Java中没有任何东西等同于C#的USB支持。 jUSB和Java-USB都严重过时,可能无法用于任何严肃的应用程序开发。

There is nothing equivalent to C#'s USB support in Java. Both jUSB and Java-USB are severely out-of-date and likely unusable for any serious application development.

如果你想实现一个跨平台的USB应用程序,真的你最好的办法是编写一个抽象的 JNI 界面,该界面与Linux,Mac和Windows本机库进行对话。你必须自己写。我会看一下 LibUSB 来处理Mac和Linux。正如您所见,Windows非常简单。我刚刚完成了为期一年的项目,不幸的是,这是唯一一个严肃的跨平台解决方案。如果您不必在Windows上实现并且您的需求有限,那么您可能会使用其中一个较旧的Java库(jUSB或Java-USB)。需要在Win32 / Win64上部署的任何内容都需要本机组件。

If you want to implement a cross-platform USB application, really your best bet is to write an abstract JNI interface that talks to Linux, Mac and Windows native libraries that you'll have to write yourself. I'd look at LibUSB to handle Mac and Linux. Windows, as you've seen, is pretty straightforward. I just came off a year-long project that did just this, and unfortunately this is the only serious cross-platform solution. If you don't have to implement on Windows and your needs are limited, you may get by with one of the older Java libs (jUSB or Java-USB). Anything that needs to deploy on Win32/Win64 will need a native component.

这篇关于如何在java中访问USB端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆