1

Before answering, please read all of this so you don't miss any details.

I have been looking on the internet for days, and trying to look through the javadocs, but I cannot find the answer anywhere.

How can I get connected devices through USB by using the java API. I do not want to use any libraries as they aren't reliable enough for the purpose I am using it for.

How do USB java libraries do it, what Java API does it use to connect to USB devices?

I know it may be complicated to actually work with it, but it will still be very useful.

I did seen the use of File.getRoots(), but it just gives storage, like C:/, H:/, etc. I want to be able to communicate with any USB device, like mouses, keyboards, custom hardware, etc.

Also include examples of code as well. It helps a lot in understanding it better. Make sure to also get to the point, it helps by saving time.

Update: I still have no clue on how to start.

Update 2: I found something with javax.usb, is it part of the java api, when I do say java api, I mean stuff that is already with java and where you don't need to download anything but the JRE. I am not sure as if it was, I would think someone would of mentioned something about it here. Going to try to find more into it. I can't find anything on the official java-14 docs, so guessing not.

Update 3: Haven't found an answer yet. Everything is redirecting to usb4java, which has not been updated in a couple years, 3 years in fact. Which is actually one of the main reasons I don't want to use any external library as it might get abandoned and will cause some issues with my code in the future. Hopefully someone can help soon, I desperately need an answer and the internet is no help and everything seems to redirect to libraries, which again, I don't want.

Update 4: Still on the hunt for an answer, still haven't found anything useful.

Update 5: I am seeing that I have tons of uses to do this, but don't know how to do it from scratch.

Update 6: Still on the hunt for an answer. I have been looking hard but found nothing. Looking through the USB4JAVA library code has been proven to not help much. But, I am going to keep looking, hopefully I find something soon. Found something though, it's libusb, a C program that USB4JAVA uses. Even though I won't use Java libraries, I might just use C libraries for Java, if that makes sense.

  • https://stackoverflow.com/questions/9744186/working-with-external-hardware-components-in-java – Abishek Stephen Apr 22 '21 at 20:09
  • @Abishek Stephen I like how the question is put, but there isn't an answer that isn't direct. I like answers that gets to the point. I now inserted the details into my question. – Jonathan J. Pecany Apr 22 '21 at 21:17
  • I don't think you can do this from a java application without native code or libraries containing native code. `javax.usb` is a standard API implemented by the [usb4java library](http://usb4java.org/quickstart/javax-usb.html) (there may be other implementations). However, you should not be too feared of libraries. Try it out. – dan1st May 31 '21 at 21:32
  • @dan1st So how do those libraries do it? – Jonathan J. Pecany May 31 '21 at 21:40
  • They include a native (non-java) implementation. This implementation uses the OS libraries. Native code can be executed using JNI/JNA. – dan1st May 31 '21 at 21:41
  • You can look at [the source code of usb4java](https://github.com/usb4java/usb4java/tree/master/src/main/assembly) for details. – dan1st May 31 '21 at 21:44
  • @dan1st Okay, thanks. – Jonathan J. Pecany Jun 01 '21 at 00:01

0 Answers0