Interface USB to Java program

Author
Munther
Starting Member
  • Total Posts : 89
  • Reward points : 0
  • Joined: 2007/11/25 13:33:23
  • Location: Michigan, USA
  • Status: offline
2010/12/29 15:05:30 (permalink)
0

Interface USB to Java program

Hello guys,
I have Pic32 Ethernet Starter Kit, and I need to develop a jave program(instead of C++) that can
be functioning exactly like: GenericHIDSimpleDemo.exe, the reason of using Java, because that's gonna
be a part of the project, any help will be highly appreciated.
 
thanks,
 
Munther
   
 
#1

17 Replies Related Threads

    Munther
    Starting Member
    • Total Posts : 89
    • Reward points : 0
    • Joined: 2007/11/25 13:33:23
    • Location: Michigan, USA
    • Status: offline
    Re:Interface USB to Java program 2010/12/30 07:21:40 (permalink)
    0
    I know that's not a java forum, but I just wanna ask if it is possible to send and receive I/O commands on USB bus between the Pic32 Starter Kit and a java program, or not!
    Any similar example to "USB Device - HID - Custom", or "USB Device - WinUSB" using java instead of Microsoft VC++ would be great.
    thanks,

    Munther.
    post edited by Munther - 2010/12/30 07:27:44
    #2
    Ian.M
    Super Member
    • Total Posts : 13033
    • Reward points : 0
    • Joined: 2009/07/23 07:02:40
    • Location: UK
    • Status: offline
    Re:Interface USB to Java program 2010/12/30 07:33:17 (permalink)
    0
    JFGI: 'java HID'. Remember, Microchip have done it in MPLAB X which is based on the NetBeans IDE which is 100% Java!
    post edited by Ian.M - 2010/12/30 07:38:21
    #3
    Munther
    Starting Member
    • Total Posts : 89
    • Reward points : 0
    • Joined: 2007/11/25 13:33:23
    • Location: Michigan, USA
    • Status: offline
    Re:Interface USB to Java program 2010/12/30 07:39:40 (permalink)
    0
    thanks Ian, I'll check it out.  
    #4
    Munther
    Starting Member
    • Total Posts : 89
    • Reward points : 0
    • Joined: 2007/11/25 13:33:23
    • Location: Michigan, USA
    • Status: offline
    Re:Interface USB to Java program 2010/12/30 08:18:59 (permalink)
    0
    Ian,
    when I opened up the link, I got a google search page including these links:
    jusb.sourceforge.net/apidoc/usb/linux/HID.html
    www.atmel.com/dyn/resources/prod_documents/doc7645.pdf
    which one has been done by Microchip, would you explain more about JFGI.

    Thanks.
    #5
    Ian.M
    Super Member
    • Total Posts : 13033
    • Reward points : 0
    • Joined: 2009/07/23 07:02:40
    • Location: UK
    • Status: offline
    Re:Interface USB to Java program 2010/12/30 08:40:54 (permalink)
    0
    JFGI is also more politely referred to as 'Google is your friend'. 

    If you check out the links on the first page of results, you will see that the alternatives are pay some company a lot of money FOR EACH INSTALLATION to use their Java HID library,  write a Java wrapper to go round a native WINDOWS interface library (probably written in C), or move to Linux.  The open source Java HID stuff is apparently all abandoned and 'dead' on the windows platform.  

    I pointed out MPLAB X as proof that it IS possible as several of the Microchip development programmers/debuggers use a HID interface.  AFAIK the source has NOT been released so how good are you at reverse engineering?  If the answer as for most of us is 'Not Very', you should just concentrate on how to call a DLL based on the C++ example from Java.  Again its a JFGI: 'call DLL from java', but this time I wont insult your intelligence and waste my time by making that a link.

    P.S. If you just open links without any idea where you are going, sooner or later you will end up with your computer root-kitted by a hacker and get kicked off the net for DDOSing  the US government (see Wikileaks).  It should have been blindingly obvious that link led to a google search that matched the single quoted words.

    post edited by Ian.M - 2010/12/30 08:45:49
    #6
    Munther
    Starting Member
    • Total Posts : 89
    • Reward points : 0
    • Joined: 2007/11/25 13:33:23
    • Location: Michigan, USA
    • Status: offline
    Re:Interface USB to Java program 2010/12/30 10:04:25 (permalink)
    0
    Ian,
    I apologize that I posted my reply quickly, and thanks for the useful information.
    Ian.M
    but this time I wont insult your intelligence and waste my time by making that a link.

    I am still learning from my mistakes, but I think there is a better way to advise and help others.
    Thanks again,
    Munther.
     
    #7
    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    Re:Interface USB to Java program 2010/12/30 10:09:58 (permalink)
    0
    Microchip HID class.dll is a DotNet one.
    I believe it's hard to wrap this DLL for Java, unless you are working on J#

    Try another HID DLL.
    Doesn't this one sound good wink

    "USB PC Drivers Based on Generic HID Class" from Atmel
    http://www.atmel.com/dyn/..._documents/doc7645.pdf

    3.2 JAVA demo
    The JAVA demo allows the user to see how to integrate the AtUsbHid.dll in a JAVA project. The interface between the AtUsbHid.dll and the JAVA is done through the package AtUsbHidJni.jar.

    http://www.atmel.com/dyn/...usb_hid_2008-11-19.zip


    USB and HID are the standard. Of course, Atmel DLL works for PIC HID device, too.

    Tsuneo
    #8
    jtemples
    Super Member
    • Total Posts : 10116
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re:Interface USB to Java program 2010/12/30 10:11:09 (permalink)
    0
    libusb 1.0 + JNA + JNAerator.  It's pretty simple and you don't have to write any native code or mess with JNI.
    #9
    xiaofan
    Super Member
    • Total Posts : 6247
    • Reward points : 0
    • Joined: 2005/04/14 07:05:25
    • Location: Singapore
    • Status: offline
    Re:Interface USB to Java program 2010/12/30 19:09:58 (permalink)
    0
    You can probably try this one.
    http://www.microchip.com/forums/tm.aspx?m=278617

    It is the Java port of the generic HID program from Jan Axelson's "The HID Page".
    http://www.lvr.com/hidpage.htm

      USB_Links and libusb
    #10
    Ian.M
    Super Member
    • Total Posts : 13033
    • Reward points : 0
    • Joined: 2009/07/23 07:02:40
    • Location: UK
    • Status: offline
    Re:Interface USB to Java program 2010/12/30 21:26:34 (permalink)
    0
    COOL!  At least LibUSB is in active development for Win32 and code ported from Jan's site at least shouldn't have any vendor specific 'improvements'. wink 

    @Munther, Sorry I was slightly abrasive last time. Next time I'll TRY to remember to tell you GIYF: ..... I also probably shouldn't have lectured you about links from strangers, but I meant well, so PLEASE keep your browser status bar turned on and be alert!
     
    #11
    Munther
    Starting Member
    • Total Posts : 89
    • Reward points : 0
    • Joined: 2007/11/25 13:33:23
    • Location: Michigan, USA
    • Status: offline
    Re:Interface USB to Java program 2010/12/31 15:35:00 (permalink)
    0
    thanks guys,
    Tsuneo, I spent yesterday working on Generic HID Class from Atmel, there was a connection between the kit and the VC++ demo,  actually that was a good sign, but when I tried to interface the kit to the java demo, the connection was getting lost, however I haven't finished the troubleshooting yet.
    Jtemples and Xiaofan, I didn't have a chance to work on LibUSB or check out the links, but for sure I will provide you with the feed back soon, thanks.
     Ian, never mind, I'll keep my browser status bar turned on, thanks.
    #12
    Munther
    Starting Member
    • Total Posts : 89
    • Reward points : 0
    • Joined: 2007/11/25 13:33:23
    • Location: Michigan, USA
    • Status: offline
    Re:Interface USB to Java program 2011/01/05 10:38:37 (permalink)
    0
    Hello guys,
    get back to you with the result, I did itgrin, the java demo now can send out the toggle command and receive the button switch status on the USB bus.
    Tsuneo, your suggestion was so so awesome, but it took me a while to understand, modify, compile, and run the demo. The PDF file that came with the package doesn’t have enough details about compiling and running the java demos, and if you use the Javac command in their format, you will end up having some errors, so I decided to write down my own notes, you can download the notes and the modified source code from the attached file:

    After you unzip the file, you can read the "Important Readme.doc", in this file I explained step by step how to run and interface the java demo(AtUsbHidGui) to the Generic HID firmware provided by Microchip.
    Finally, I would like to thank everybody for their suggestions.

    Enjoy HID Java. wink

    Munther 
    post edited by Munther - 2011/01/05 11:43:51
    #13
    bahatay
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2011/07/18 07:22:10
    • Location: 0
    • Status: offline
    Re:Interface USB to Java program 2011/07/18 07:46:40 (permalink)
    0
    I appreciate your program, it works fine.

    I am trying to use your code but I have only one problem while compiling.

    // Create usbDevice object
        AtUsbHidJni usbDevice = new AtUsbHidJni();

    The compiler does not recognize AtUsbHidJni type objects, and
    I cant find any piece of code that uses the AtUsbHidJni.dl. There would be a header file but thats not included in the zip. Since you made it without then I am missing a point.

    I just copied all files in src folder and deleted import com.packages line, since its difficult to import an existing project to java.

     
    #14
    bahatay
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2011/07/18 07:22:10
    • Location: 0
    • Status: offline
    Re:Interface USB to Java program 2011/07/18 07:56:10 (permalink)
    0
    Actually header file was included in the zip. I think the problem is related to this header file. In every document about native library it says run command javah -jni, however there is no javah in my Jre6.
    #15
    Munther
    Starting Member
    • Total Posts : 89
    • Reward points : 0
    • Joined: 2007/11/25 13:33:23
    • Location: Michigan, USA
    • Status: offline
    Re:Interface USB to Java program 2011/08/07 14:11:46 (permalink)
    0
    Bahatay,
    you must keep import com.atmel.atusbhidjni.AtUsbHidJni; even if you delete the com folder. if you unzip the AtUsbHidJni.jar, you will figure out what I am talking about.

    Although javah.exe is available with jdk6 on this path C:\Program Files\Java\jdk1.6.0_23\bin\javah.exe , you don't need it to compile the project.

    Three things you have to modify in case you moved the src files to JNICodeForHIDDLL\src folder

    1. The first line of your java src files should be package src;
    2. Edit the contents of buildProject.bat, and replace them with the following :
    mkdir src
    javac src\*.java -classpath AtUsbHidJni.jar -d ./src/
    jar -cvfm AtUsbHidGui.jar com/AtUsbHidGui.MF -C src src
    Pause
    3. Go to com\AtUsbHidGui.MF -> right click -> choose edit or open with notepad
    Replace the Main-Class line with:
    Main-Class: src.AtUsbHidGui

    Now you should be ready to go.

    Regards,

    Munther
    #16
    Angelos
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2010/05/05 16:28:31
    • Location: 0
    • Status: offline
    Re:Interface USB to Java program 2013/11/25 07:19:52 (permalink)
    0
    Munther,
    thank you for creating the examples. I edit them and I had communication with my PIC24 based project within a few minutes.
     
    I noticed that when the GUI starts  a console window also opens and shows "Load DLL" and "DLL Load". I could not find these into the source code and I suspect they may be part of the AtUsbHidJni.jar  Is there any way to stop these messages being displayed? Basically I don't want the console window to appear at all.
     
    Regards,
    Angelos
    #17
    Angelos
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2010/05/05 16:28:31
    • Location: 0
    • Status: offline
    Re:Interface USB to Java program 2013/11/26 13:16:15 (permalink)
    0
    I found how to hide the console/cmd window... just use javaw.exe instead of java.exe to launch the GUI demo. And don't launch it with BAT file; use a Windows shortcut instead.
    #18
    Jump to:
    © 2017 APG vNext Commercial Version 4.5