Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access USB ports in java [closed]

Tags:

java

usb

rxtx

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.

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.

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)?

like image 927
Petezah Avatar asked Jan 23 '10 00:01

Petezah


People also ask

How do I view all USB ports?

Use the Device Manager to determine if your computer has USB 1.1, 2.0, or 3.0 ports: Open the Device Manager. In the "Device Manager" window, click the + (plus sign) next to Universal Serial Bus controllers. You will see a list of the USB ports installed on your computer.


2 Answers

Been using usb4java for a year on cross platfom (Linux and Windows) and it works great.

See:

http://usb4java.org/

They are very active and have a very good javax USB front.

like image 172
jboisvert Avatar answered Oct 14 '22 00:10

jboisvert


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.

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.

like image 43
Dave Sims Avatar answered Oct 13 '22 22:10

Dave Sims