- Set the descriptors in the firmware:
- Generate INF with WinJavaInf.exe
- Programming the microcontroller and connect.
- Install Driver.
- Create New Java Project in Eclipse
- Copy "usbJava.jar in folder project and Add to Build Path.
- Create new Class:
public class UsbJava {
public static void main(String[] args) {
String szPath = "";
try{
szPath = USBDevice.getAttachedDevicePath(0);
System.out.println("Device Path of Device at index 0 = "+ szPath);
USBDevice myUSB = new USBDevice(szPath);
System.out.println("connected?"+myUSB.deviceIsConnected());
}catch (Exception e) {
e.printStackTrace();
}
}
}
USBDevice class sentence for simple read-write :
writePipeBulkInterrupt(int IntIndex,int EndpointIndex, byte[] bufferData,int iArrayOffset,int iNumBytes)
readPipeBulkInterrupt(int IntIndex, int EndpointIndex, byte[] bufferData,int iArrayOffset,int iNumBytes)
Warning: Endpoint number is not equal to EndpointIndex
readPipeBulkInterrupt(int IntIndex, int EndpointIndex, byte[] bufferData,int iArrayOffset,int iNumBytes)
Warning: Endpoint number is not equal to EndpointIndex
Hello,
ReplyDeleteWhen i try to run your script it gives me this error:
run:
com.lucasF.JCommUSB_2_0.USBException: The operation completed successfully.
at com.lucasF.JCommUSB_2_0.USBDevice.getDevicePathNat(Native Method)
at com.lucasF.JCommUSB_2_0.USBDevice.getAttachedDevicePath(USBDevice.java:197)
at test.UsbJava.main(UsbJava.java:11)
BUILD SUCCESSFUL (total time: 1 second)
Can you give me an email at scobee@keptprivate.com with a solution ?
regards
When I ran your script in netbeans i get this error
ReplyDeleterun:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lucasAndresForni_Win32 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1734)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at com.lucasF.JCommUSB_2_0.USBDevice.(USBDevice.java:45)
at usb_comm.Main.main(Main.java:20)
Java Result: 1
hi:
ReplyDeletethe solution the error you describe is to copy the file lucasAndresForni_Win32.dll to the System32 folder
regards
Hi
ReplyDeleteI am not a java pro but I am involved in a project where I need to read/send data from a device interfaced via USB.Does your api help me? If yes then can you plz help upto the step where the device would be ready to read and accept data from my program. I am little confused when I open your folder because there are hell of the folders considering that I am not java pro.
Thanks in Advance
Hi
ReplyDeleteSomehow I have managed to run the program but Now I am getting these errors.I have also copied "lucasAndresForni_Win32.dll" to system32 flder.
run:
java.lang.NoClassDefFoundError: javaapplication4/Main
Caused by: java.lang.ClassNotFoundException: javaapplication4.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: javaapplication4.Main. Program will exit.
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
Plz help me in this.
Hi Muhammad:
ReplyDeleteaccess to any device. You must create the driver with the program WinJavaInf.exe
Copy "lucasAndresForni_Win32.dll" to system32 folder.
Hi
ReplyDeleteI'm unable to create the Driver for the device. I found the two necessary ID's (VID:06A3, PID:0464, it's a joystick), but when i try to save the INF file, i get an error "the file "C:\Users\Bene\AppData\Local\Temp\lucasAndresForni_Win32.dll" already exists".
i tried different compatibily modes (i'm running windows 7), i already copied the file "lucasAndresForni_Win32.dl" to system32 folder, nothing changes...
Thanks for your help.
greez
Same problem here...
Deletesame problem with me. i'm using windows 7 - 64 bit
Deletedownload the latest version of driver has solved that problem ( https://sourceforge.net/projects/javausbapiforwi/ )
ReplyDeleteBut this problem remain with latest software too Please help..
DeleteHi LucasF,
ReplyDeleteMy purpose is to read weight from a USB Weighing scale in browser through applet. I found this API and tried. As a first step of testing Right now I have connected USB mouse and put in VID and PID in the file Usb_Descriptor.c Now created the dll file lucasAndresForni_Win32.dll created using WinJavaInf.exe and put in system32 dir.
When I run the demo program given by you, I get following error:
====================
When I run the program I get following error:
com.lucasF.JCommUSB_2_0.USBException: The operation completed successfully.
at com.lucasF.JCommUSB_2_0.USBDevice.getDevicePathNat(Native Method)
at com.lucasF.JCommUSB_2_0.USBDevice.getAttachedDevicePath(USBDevice.jav
a:197)
at UsbJava.main(UsbJava.java:10)
======================
Am I missing something. At the moment should I expect from the program when I run it to return some information related to device patch and connection status?
Any pointer will be greatly appreciated.
Is there any more information out there about how to setup the device to use this USBDevise class? I'm finding the information very sketchy, especially for someone like me who is not familiar with how device drivers work?
ReplyDeleteI get the same error as above "The operation completed successfully". A call to USBDevice.getNumAttachedDevices() returns 0, which seems to tell me that there are no devices loaded?
It should uninstall the previous drivers and create the new drivers and then install.
ReplyDeleteI can not find another way to do it.
if anyone knows would appreciate your help.
Is the file lucasAndresForni_Win32.dll free distributable and has any license agreement.
ReplyDeleteRegards
Xavier
Hi.
ReplyDeleteI'm trying to use this API to reprogram Freescale and Renesas' MCUs.
Can you explain the methods writePipeBulkInterrupt and readPipeBulkInterrupt?
In my case I have binary files that I want to write in the device. How can I do that?
In my case the API works, I've created the drivers for the USB programmer and I get a "true" when I try to connect.
thank you for sharing this great and useful post. i'll soon write a blog and i would love to include your ideas with a link back to you. Hope it would be okey. Thanks!
ReplyDeleteWill your .dll work on a 64-bit system?
ReplyDeleteHello I tried to run WinJavaInf.exe without success. I download the version 2010-07-19. What did i miss?
ReplyDeletethanks in advance
Silvina
I have the same problem as Bene and downloading the latest version of your package for creating the driver didn't help.
ReplyDelete:( it would be nice you fix it!
regards,
Luis.
Hello, i have try your code, and all function correctly but when i execute thi code:
ReplyDeleteimport com.lucasF.JCommUSB_2_0.USBDevice;
public class UsbJava {
public static void main(String[] args) {
String szPath = "";
try{
szPath = USBDevice.getAttachedDevicePath(0);
System.out.println("Device Path of Device at index 0 = "+ szPath);
USBDevice myUSB = new USBDevice(szPath);
//System.out.println(myUSB.readPipeBulkInterrupt(1, 2, baData, iArrayOffset, iNumBytes));
byte[] bytesIn = new byte[64];
myUSB.readPipeBulkInterrupt(0, 1, bytesIn, 0, 64);
System.out.println("connected?"+myUSB.deviceIsConnected());
}catch (Exception e) {
e.printStackTrace();
}
}
}
the console prin this message:
com.lucasF.JCommUSB_2_0.USBException: Accesso alla rete negato.
at com.lucasF.JCommUSB_2_0.USBDevice.readPipeBulkInterruptNat(Native Method)
at com.lucasF.JCommUSB_2_0.USBDevice.readPipeBulkInterrupt(USBDevice.java:570)
at UsbJava.main(UsbJava.java:17)
Device Path of Device at index 0 = \\?\usb#vid_04fc&pid_0232#5&29121321&0&2#{5a44bde9-d92c-4a97-b2b8-63ba19e74635}
can you help me?
Hello there, Is there any example on the read function?
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI'm unable to create the Driver for the device.I try to save the INF file, i get an error "the file "C:\Users\Bene\AppData\Local\Temp\lucasAndresForni_Win32.dll" already exists".
ReplyDeletei tried different compatibily modes (i'm running windows 7 64Bits).
Thanks for your help.
Hi Lucas,
ReplyDeleteThanks for a wonderful API, nice work!!
I was able to run your project successfully in eclipse on windows 7, But the program terminates with following error message in console,
com.lucasF.JCommUSB_2_0.USBException: The operation completed successfully.
Does it requires some other version of OS? Please help with probable cause of error and resolution for same
Thanks!!
Hey... This is a wonderful post... Do you have a dll which supports 64 bit?
ReplyDeleteI am getting this error when I try to execute a program like you wrote using your jar and dll:
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Windows\System32\lucasAndresForni_Win32.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform
Do you have a solution for this? Please let me know.
Pretty nice post. I simply stumbled upon your weblog and needed.To say that I even have actually treasured surfboarding around your diary posts.
ReplyDeleteAfter all i will be subscribing on your feed and that i am hoping you write once more soon!
restore deleted email
it doesn't work in 64-bit.. is there any workaround??
ReplyDeletehiii...
ReplyDeletei'm trying with Windows xp 32 bit doesn't work, also with windows 7 64 bit. can you explain me why....
tq
Thanks.
ReplyDeletemmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmany thanks
ReplyDeleteYes.
DeleteDownload Java in http://java.joydownload.com/
ReplyDeleteReally New York City, like a number of metropolitan areas. I live to get advice from consultant, I think this barely works for anything! So they get a low score and a better grade, okay.
ReplyDeleteCurso java