Menu

Libusb Java with Libusb-win32 filter driver

Help
Erik
2018-01-05
2018-01-15
  • Erik

    Erik - 2018-01-05

    Hello

    I'm trying to make a small app for X-Plane (flight simulator) to control the LEDs and a small display on the Logitech/Saitek X52 Pro Joystick.

    I'm thinking i lines of:

    [X-Plane] -> [My java app] -> [Libusb Java] -> [Libusb-win32 filter driver] -> [Logitech/Saitek driver] -> [Joystick]

    The reason I need the filter driver approach is that the Logitech/Saitek driver needs to be installed to make the Joystick still act as a joystick. (I tried with a more recent version of Libusb but the drivers needed stoped the Joystick working)

    First question: Am I on the right track at all?

    Further more, I have installed libusb-win32-bin-1.2.6.0.zip and managed to install the filter driver. No errors reported.

    I have installed Libusb Java (LibusbJava-1_1_64bit.zip) according to the instructions here and I have tried a small program based on the snippet from "First steps". I get as far as:

    usbDev.open();
    

    and there I get

    java -cp .;lib\*;bin\ se.companion.usb.X52USB
    Search Device:
    Opening device.
    Exception in thread "main" java.lang.NoClassDefFoundError: ch/ntb/inf/libusbJava/exceptions/LibusbException
            at ch.ntb.inf.libusb.Libusb.open(Native Method)
            at ch.ntb.inf.libusb.Device.open(Device.java:194)
            at se.companion.usb.X52USB.main(X52USB.java:54)
    Caused by: java.lang.ClassNotFoundException: ch.ntb.inf.libusbJava.exceptions.LibusbException
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            ... 3 more
    

    Second question: What's going on with the exception? I don't se the package path "ch/ntb/inf/libusbJava..." in the LibusbJava.jar:

    jar tf lib\LibusbJava.jar
    META-INF/
    META-INF/MANIFEST.MF
    ch/ntb/inf/libusb/ConfigurationDescriptor.class
    ch/ntb/inf/libusb/Context.class
    ch/ntb/inf/libusb/Descriptor.class
    ch/ntb/inf/libusb/DescriptorType.class
    ch/ntb/inf/libusb/Device.class
    ch/ntb/inf/libusb/DeviceDescriptor.class
    ch/ntb/inf/libusb/EndpointDescriptor.class
    ch/ntb/inf/libusb/exceptions/AccessDeniedException.class
    ch/ntb/inf/libusb/exceptions/DeviceListNotValidException.class
    ch/ntb/inf/libusb/exceptions/EntityNotFoundException.class
    ch/ntb/inf/libusb/exceptions/InvalidParameterException.class
    ch/ntb/inf/libusb/exceptions/JavaIllegalDeviceHandleException.class
    ch/ntb/inf/libusb/exceptions/JavaReferencesNotLoadedException.class
    ch/ntb/inf/libusb/exceptions/JavaWrongEnvironmentException.class
    ch/ntb/inf/libusb/exceptions/LibusbException.class
    ch/ntb/inf/libusb/exceptions/LibusbIOException.class
    ch/ntb/inf/libusb/exceptions/NoDeviceException.class
    ch/ntb/inf/libusb/exceptions/NoMemoryException.class
    ch/ntb/inf/libusb/exceptions/NotSupportedException.class
    ch/ntb/inf/libusb/exceptions/OtherException.class
    ch/ntb/inf/libusb/exceptions/OverflowException.class
    ch/ntb/inf/libusb/exceptions/PipeException.class
    ch/ntb/inf/libusb/exceptions/ResourceBusyException.class
    ch/ntb/inf/libusb/exceptions/SysCallInterruptedException.class
    ch/ntb/inf/libusb/exceptions/TimeoutException.class
    ch/ntb/inf/libusb/exceptions/WrongContextException.class
    ch/ntb/inf/libusb/Interface.class
    ch/ntb/inf/libusb/InterfaceDescriptor.class
    ch/ntb/inf/libusb/Libusb.class
    ch/ntb/inf/libusb/LibusbJava.class
    ch/ntb/inf/libusb/Speed.class
    ch/ntb/inf/libusb/test/AT90USB1287Test.class
    ch/ntb/inf/libusb/test/ByteBufferTest.class
    ch/ntb/inf/libusb/test/LibusbJavaListTest.class
    ch/ntb/inf/libusb/test/LibusbJavaTest.class
    ch/ntb/inf/libusb/test/UseTestLibusbJava.class
    ch/ntb/inf/libusb/TransferType.class
    

    Any help or pointers would be much appreciated, thanks!
    /Erik

    The complete program I'm trying to run:

    package se.companion.usb;
    
    import ch.ntb.inf.libusb.*;
    import ch.ntb.inf.libusb.exceptions.*;
    import ch.ntb.inf.libusb.test.*;
    
    public class X52USB {
        public static void main(String[] args){
            Context useCtx = null;                           
            Device usbDev = null;
            try {
                    useCtx = new Context();                                                  /* 1 */
            } catch (LibusbException e) {
                    System.out.println("Init failed:");
                e.printStackTrace();
            }
    
            System.out.println("Search Device:");
            try {
                usbDev = Device.search(useCtx, 0x06a3, 0x0762);                           /* 2 */
    
            } catch (LibusbException e) {
                System.out.println("Error occured: search");
                e.printStackTrace();
            }
    
            if(usbDev == null) return;
    
            try {
                System.out.println("Opening device.");
                usbDev.open();                                                           /* 4 */
                System.out.println("Claim interface.");
                usbDev.claimInterface(0);                                                /* 5 */
                byte[] data = {(byte)0x40, (byte)0x80, (byte)0x12, (byte)0x16};
                int res = usbDev.bulkTransfer(2, data, data.length, 0);                  /* 6 */
                if(res == data.length){
                        System.out.println("Bulk tranfer 1 successful.");
                }
                else{
                    System.out.println("Bulk transfer 1 failed.");
                }
                usbDev.reset();
                res = 0;
                res = usbDev.bulkTransfer(2, data, data.length, 0);                      /* 6 */
                if(res == data.length){
                    System.out.println("Bulk tranfer 2 successful.");
                }
                else{
                    System.out.println("Bulk transfer 2 failed.");
                }
                usbDev.releaseInterface(0);                                              /* 7 */
                usbDev.close();                                                          /* 8 */
                System.out.println("Device closed.");
            } catch (LibusbException e) {
                System.out.println("Error occured: transfer");
                e.printStackTrace();
            }
        }
    
    }
    
     
    • Urs Graf

      Urs Graf - 2018-01-15

      Sorry Erik to have you wait for such a long time. We are under some pressure in a urgent project and did not have time for a more detailed analysis. However, some of our students last week successfully installed you driver package, which among other things include the LibUsbJava. May I ask you to try http://wiki.ntb.ch/infoportal/software/ntb_windows_driver_package/start

      Hope it works
      Urs

      Von: Erik [mailto:erik_hjerten@users.sf.net]
      Gesendet: Freitag, 5. Januar 2018 21:22
      An: [libusbjava:discussion]
      Betreff: [libusbjava:discussion] Libusb Java with Libusb-win32 filter driver

      Hello

      I'm trying to make a small app for X-Plane (flight simulator) to control the LEDs and a small display on the Logitech/Saitek X52 Pro Joystick.

      I'm thinking i lines of:

      [X-Plane] -> [My java app] -> [Libusb Java] -> [Libusb-win32 filter driver] -> [Logitech/Saitek driver] -> [Joystick]

      The reason I need the filter driver approach is that the Logitech/Saitek driver needs to be installed to make the Joystick still act as a joystick. (I tried with a more recent version of Libusb but the drivers needed stoped the Joystick working)

      First question: Am I on the right track at all?

      Further more, I have installed libusb-win32-bin-1.2.6.0.zip and managed to install the filter driver. No errors reported.

      I have installed Libusb Java (LibusbJava-1_1_64bit.zip) according to the instructions here and I have tried a small program based on the snippet from "First steps". I get as far as:

      usbDev.open();

      and there I get

      java -cp .;lib*;bin\ se.companion.usb.X52USB

      Search Device:

      Opening device.

      Exception in thread "main" java.lang.NoClassDefFoundError: ch/ntb/inf/libusbJava/exceptions/LibusbException

          at ch.ntb.inf.libusb.Libusb.open(Native Method)
      
          at ch.ntb.inf.libusb.Device.open(Device.java:194)
      
          at se.companion.usb.X52USB.main(X52USB.java:54)
      

      Caused by: java.lang.ClassNotFoundException: ch.ntb.inf.libusbJava.exceptions.LibusbException

          at java.net.URLClassLoader.findClass(Unknown Source)
      
          at java.lang.ClassLoader.loadClass(Unknown Source)
      
          at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      
          at java.lang.ClassLoader.loadClass(Unknown Source)
      
          ... 3 more
      

      Second question: What's going on with the exception? I don't se the package path "ch/ntb/inf/libusbJava..." in the LibusbJava.jar:

      jar tf lib\LibusbJava.jar

      META-INF/

      META-INF/MANIFEST.MF

      ch/ntb/inf/libusb/ConfigurationDescriptor.class

      ch/ntb/inf/libusb/Context.class

      ch/ntb/inf/libusb/Descriptor.class

      ch/ntb/inf/libusb/DescriptorType.class

      ch/ntb/inf/libusb/Device.class

      ch/ntb/inf/libusb/DeviceDescriptor.class

      ch/ntb/inf/libusb/EndpointDescriptor.class

      ch/ntb/inf/libusb/exceptions/AccessDeniedException.class

      ch/ntb/inf/libusb/exceptions/DeviceListNotValidException.class

      ch/ntb/inf/libusb/exceptions/EntityNotFoundException.class

      ch/ntb/inf/libusb/exceptions/InvalidParameterException.class

      ch/ntb/inf/libusb/exceptions/JavaIllegalDeviceHandleException.class

      ch/ntb/inf/libusb/exceptions/JavaReferencesNotLoadedException.class

      ch/ntb/inf/libusb/exceptions/JavaWrongEnvironmentException.class

      ch/ntb/inf/libusb/exceptions/LibusbException.class

      ch/ntb/inf/libusb/exceptions/LibusbIOException.class

      ch/ntb/inf/libusb/exceptions/NoDeviceException.class

      ch/ntb/inf/libusb/exceptions/NoMemoryException.class

      ch/ntb/inf/libusb/exceptions/NotSupportedException.class

      ch/ntb/inf/libusb/exceptions/OtherException.class

      ch/ntb/inf/libusb/exceptions/OverflowException.class

      ch/ntb/inf/libusb/exceptions/PipeException.class

      ch/ntb/inf/libusb/exceptions/ResourceBusyException.class

      ch/ntb/inf/libusb/exceptions/SysCallInterruptedException.class

      ch/ntb/inf/libusb/exceptions/TimeoutException.class

      ch/ntb/inf/libusb/exceptions/WrongContextException.class

      ch/ntb/inf/libusb/Interface.class

      ch/ntb/inf/libusb/InterfaceDescriptor.class

      ch/ntb/inf/libusb/Libusb.class

      ch/ntb/inf/libusb/LibusbJava.class

      ch/ntb/inf/libusb/Speed.class

      ch/ntb/inf/libusb/test/AT90USB1287Test.class

      ch/ntb/inf/libusb/test/ByteBufferTest.class

      ch/ntb/inf/libusb/test/LibusbJavaListTest.class

      ch/ntb/inf/libusb/test/LibusbJavaTest.class

      ch/ntb/inf/libusb/test/UseTestLibusbJava.class

      ch/ntb/inf/libusb/TransferType.class

      Any help or pointers would be much appreciated, thanks!
      /Erik

      The complete program I'm trying to run:

      package se.companion.usb;

      import ch.ntb.inf.libusb.*;

      import ch.ntb.inf.libusb.exceptions.*;

      import ch.ntb.inf.libusb.test.*;

      public class X52USB {

      public static void main(String[] args){
      
          Context useCtx = null;
      
          Device usbDev = null;
      
          try {
      
                  useCtx = new Context();                                                  /* 1 */
      
          } catch (LibusbException e) {
      
                  System.out.println("Init failed:");
      
              e.printStackTrace();
      
          }
      
          System.out.println("Search Device:");
      
          try {
      
              usbDev = Device.search(useCtx, 0x06a3, 0x0762);                           /* 2 */
      
          } catch (LibusbException e) {
      
              System.out.println("Error occured: search");
      
              e.printStackTrace();
      
          }
      
          if(usbDev == null) return;
      
          try {
      
              System.out.println("Opening device.");
      
              usbDev.open();                                                           /* 4 */
      
              System.out.println("Claim interface.");
      
              usbDev.claimInterface(0);                                                /* 5 */
      
              byte[] data = {(byte)0x40, (byte)0x80, (byte)0x12, (byte)0x16};
      
              int res = usbDev.bulkTransfer(2, data, data.length, 0);                  /* 6 */
      
              if(res == data.length){
      
                      System.out.println("Bulk tranfer 1 successful.");
      
              }
      
              else{
      
                  System.out.println("Bulk transfer 1 failed.");
      
              }
      
              usbDev.reset();
      
              res = 0;
      
              res = usbDev.bulkTransfer(2, data, data.length, 0);                      /* 6 */
      
              if(res == data.length){
      
                  System.out.println("Bulk tranfer 2 successful.");
      
              }
      
              else{
      
                  System.out.println("Bulk transfer 2 failed.");
      
              }
      
              usbDev.releaseInterface(0);                                              /* 7 */
      
              usbDev.close();                                                          /* 8 */
      
              System.out.println("Device closed.");
      
          } catch (LibusbException e) {
      
              System.out.println("Error occured: transfer");
      
              e.printStackTrace();
      
          }
      
      }
      

      }


      Libusb Java with Libusb-win32 filter driverhttps://sourceforge.net/p/libusbjava/discussion/660151/thread/3eafb68b/?limit=25#e184


      Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/libusbjava/discussion/660151/

      To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.