Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java and USB

 
eddy johns
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I need to read a USB device from my java code. Is there any good solution at all?

I looked at jsr80. I installed the jsr80.jar and the jsr80_ri.jar, and I'm trying to run the generic code you find on the net:



I keep getting the following error:




Any ideas?

Thanks,
Eddy
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class com.ibm.jusb.os.windows.WindowsUsbServices was not found

Is that class in the classpath?
 
eddy johns
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf,

Following your reply I checked my jsr80-windows.jar and it turns out the WindowsUsbServices is in com.mcreations.usb.windows. So I changed my properties file and now I get this error:




I looked on the net and it seems like many people get similar errors with jsr80 and no one was able to go through and get this to work. But I may be missing something. Hopefully I'm missing something.. Any suggestions?

Thanks,
Eddy
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If all you did for installation was to add the 2 jar files to your classpath, then yes - something is bound to be missing. Any low-level I/O library will require a native library. You should be able to get that somewhere around here: http://sourceforge.net/apps/trac/libusb-win32/wiki
 
eddy johns
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I looked there and got to http://sourceforge.net/projects/libusb-win32/files/ but the package there doesn't include LibusbJava.dll... Ulf, have you been able to make this work?

Thanks,
(The Desperate) Eddy
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No; I've never used it. Maybe it's better to get it all in one place anyway; http://javax-usb.cvs.sourceforge.net/viewvc/javax-usb/javax-usb-libusb/lib/ looks promising
 
eddy johns
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf, after much crap of moving dll's around -- using the code from link you gave in the previous message -- it's working for me. The last step was to change the name of usbJava.dll to LibusbJava.dll and install it in C:\Windows\system32. I figured it out only once the runtime complained it can't read from LibusbJava.dll.

http://libusbjava.sourceforge.net/wp/ has the best explanation on how to install all the elements. Once they're installed, http://www.cafeaulait.org/books/javaio2/ioexamples/23/index.html has great examples on how to use the API.

Thanks again,
Eddy
 
Amol Bhanushali
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
eddy johns wrote:Thanks Ulf, after much crap of moving dll's around -- using the code from link you gave in the previous message -- it's working for me. The last step was to change the name of usbJava.dll to LibusbJava.dll and install it in C:\Windows\system32. I figured it out only once the runtime complained it can't read from LibusbJava.dll.

http://libusbjava.sourceforge.net/wp/ has the best explanation on how to install all the elements. Once they're installed, http://www.cafeaulait.org/books/javaio2/ioexamples/23/index.html has great examples on how to use the API.

Thanks again,
Eddy




Hi eddy johns can you give me the sample code for the file transfer i am stuck in that from so many days.. i would be very much thankfull to you.
 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Amol!

Eddy hasn't been active on the Ranch for quite a while, so I don't think he'll be able to give you any sample codes.
 
Amol Bhanushali
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Welcome to the Ranch, Amol!

Eddy hasn't been active on the Ranch for quite a while, so I don't think he'll be able to give you any sample codes.



Hi Rob Spoor,

can you help me on the same topic it is very urgent!!
 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please EaseUp. There's no such thing as urgent around here. And no, I cannot help you, as I haven't worked with the combination of Java and USB before.
 
Amol Bhanushali
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Please EaseUp. There's no such thing as urgent around here. And no, I cannot help you, as I haven't worked with the combination of Java and USB before.



Sorry Rob Spoor,

But I am searching this for almost last 1 week and i have downloaded all the library which eddy johns mentioned. and run the code also. Talked with many of my freind, but suddenly today i found my path to the solution on this blog so i thought it might help me to give us right direction for further procedure. we dont want the complete code as we will manage to do so but as we are new to this and there is less help available specially for java with USB so i thought let us try to put some effort here and get the right path to walk on. this is also from past history that we have found many small things working for us from this blog specially for java collections.

hope i satisfied to your comment. as some time communication barrier creates lots diffrence in understanding each ohter.
thanks for the reply. i still hope will get the answers from this blog.
thank you once again
 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no problem at all with your request. You have a valid problem, and asking for sample code or directions is just fine. If I could have provided any I would have gladly given it to you.

I also understand that you may need an answer as soon as possible, but the FAQ entry that the EaseUp words link to explains why we prefer that you simply don't mention that.
 
Steve Thomas
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
eddy johns wrote:Thanks Ulf, after much crap of moving dll's around -- using the code from link you gave in the previous message -- it's working for me. The last step was to change the name of usbJava.dll to LibusbJava.dll and install it in C:\Windows\system32. I figured it out only once the runtime complained it can't read from LibusbJava.dll.

http://libusbjava.sourceforge.net/wp/ has the best explanation on how to install all the elements. Once they're installed, http://www.cafeaulait.org/books/javaio2/ioexamples/23/index.html has great examples on how to use the API.

Thanks again,
Eddy


I don't know if you're still interested but I just spent ages on the same quest as you. Finally I found the location of the highly sought after LibusbJava.dll right under my nose:-
http://sourceforge.net/projects/libusbjava/files/libusbjava-snapshots/20080218/

why don't people just label things a bit better?

I have only just found this comment about renaming the usbJava.dll file (although I havn't tried it) but if it worksit would have save me a pile of trouble too.


 
Muhammed Mahmood
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to detect my fingerprint scanner in java.So I am using this javax.usb api .I am trying to detect the devices attached to usb as:
public static void main(String[] args) throws UsbException {
try{
UsbServices services = UsbHostManager.getUsbServices();
UsbHub root = services.getRootUsbHub();
listDevices(root);
}catch(Exception e){System.out.println("");e.printStackTrace();}

}

public static void listDevices(UsbHub hub) {
List devices = hub.getAttachedUsbDevices();
Iterator iterator = devices.iterator();
while (iterator.hasNext()) {
UsbDevice device = (UsbDevice) iterator.next();
System.out.println(device);
if (device.isUsbHub()) {
listDevices((UsbHub) device);
}
}
}

but I am getting this error:

javax.usb.UsbException: An Exception occurred during instantiation of the UsbServices implementation javax.usb.UsbServices : javax.usb.UsbServices
at javax.usb.UsbHostManager.createUsbServices(UsbHostManager.java:82)
at javax.usb.UsbHostManager.getUsbServices(UsbHostManager.java:35)
at UsbReader.main(UsbReader.java:10)
This was when i was not using the com.ibm.jusb.os.windows.WindowsUsbServices class, instead i had initialized the javax.usb.services=javax.usb.UsbServices.

Now when I am using the com.ibm.jusb.os.windows.WindowsUsbServices with libusb.dll attached i am gettin this error:
Exception net.sf.libusb.LibusbJNI.usb_init()V at net.sf.libusb.LibusbJNI.usb_init

please help me what to do.Is there any 64bit libusb.dll file?
 
Winston Gutkowski
Bartender
Pie
Posts: 10527
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Muhammed Mahmood wrote:Now when I am using the com.ibm.jusb.os.windows.WindowsUsbServices with libusb.dll attached i am gettin this error:
Exception net.sf.libusb.LibusbJNI.usb_init()V at net.sf.libusb.LibusbJNI.usb_init

please help me what to do.Is there any 64bit libusb.dll file?

No idea. However, a simple Google of your error gave me this page, so you might want to try it with a few other portions.

Also: Your catch block is redundant, because all it's doing is exactly what the program would do if you left the try...catch out altogether.

This sounds like a very specialized requirement, so if I/we find a better forum for it, we might move your thread there.

HIH

Winston
 
Jacob Othello
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I found myself with a similar problem than the original poster, but under Linux.
Is it relevant to post here, as I found this thread while googling, or should I start another one?

I'll explain here and move if necessary.
I think I installed everything possible: javax.usb, javax.usb.ri, javax.usb.ri.linux, rxtx, usb4java (don't know what this one is used for yet).
Here's the program :


And here's the error I get.
Exception in thread "main" javax.usb.UsbException: The UsbServices implementation class com.ibm.jusb.os.linux.LinuxUsbServices was not found : com.ibm.jusb.os.linux.LinuxUsbServices
at javax.usb.UsbHostManager.createUsbServices(Unknown Source)
at javax.usb.UsbHostManager.getUsbServices(Unknown Source)
at usb.USBHighLevel.main(USBHighLevel.java:15)
Is it a problem with my properties file? or the .so? or the .jar? or the code?
I'm no pro at Eclipse neither at Linux so I may have done a stupid mistake, I mostly followed the instructions stated on the Readme files.
 
Jacob Othello
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I made it work. It was because I had the javax.usb.properties in both jdk/lib and jdk/jre/lib, I just had to delete the /jre/lib one
 
Animesh Nath
Greenhorn
Posts: 11
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:
class com.ibm.jusb.os.windows.WindowsUsbServices was not found

Is that class in the classpath?


I understand it is silly

CAn anyone tell me whats a classpath ?
 
Jacob Othello
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is the different .jar files where your Java application will get its classes, so you can import them.

Eclipse can modify the classpath easily and differently for each project.
I recommend you place all files in a directory you created, dedicated to your Java projects. Then, divide into sub-folders for each different project, it will be simpler.
Once you added all the .jar you'll need in that directory, in Eclipse, right-click on your project, select properties and move to the "Java Build Path" tab.
Here, select "Add JARs" or "Add External JARs" depending on where you put the directory (in your workspace or not), and select the wanted JARs.
This should allow you to import the classes in the .jar in the project's file.

It is also possible to change the classpath by setting environment variables, but I don't know the details about this method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic