Menu

LibusbJava.usb_get_busses() -- PROBLEM

Help
Nuno Lima
2008-02-06
2012-12-06
  • Nuno Lima

    Nuno Lima - 2008-02-06

    Hi.

    First of all I would like to congratulate all developers of this excelente project. Many thanks to you all.

    Now about my problem...

    I'm using LibusbJava.usb_get_busses() to get the tree of descriptor objects in the computer, but same times it fails to do it (in Linux - Ubuntu).

    Until now on windows (XP) I didn't detect the same failure.

    This is really important, because my program is constantly checking the existence of my usb device, and when it's not detected my program "thinks" the device is not there and it fails, shutting down the program.

    Here is my java method code that take care of checking for the device (serialnumber):

    public boolean detectUSBdevice(String SerialNumber) {
    // Code Autor: Nuno Lima - PT

        LibusbJava.usb_init();
        LibusbJava.usb_find_busses();
        LibusbJava.usb_find_devices();

        Usb_Bus bus = LibusbJava.usb_get_busses();

        while (bus != null) {
            Usb_Device dev = bus.getDevices();

            while (dev != null) {
                long handle = LibusbJava.usb_open(dev);
                if (handle == 0) {
                    dev = dev.getNext();
                    continue;
                }

                ch.ntb.usb.Usb_Device_Descriptor devDesc = dev.getDescriptor();

                String sn = ch.ntb.usb.LibusbJava.usb_get_string_simple(handle, devDesc.getISerialNumber());
                LibusbJava.usb_close(handle);

                if(SerialNumber.compareToIgnoreCase(sn) == 0){
                    return true;
                }

                dev = dev.getNext();
            }
            bus = bus.getNext();
        }
        return false;
    }

    Can any one help with a code solution our is this just a bug that is not corrected yet?

    Many thanks in advance.
    Nuno Lima

     
    • Nuno Lima

      Nuno Lima - 2008-02-07

      Hi again...

      I as working on this (my) problem an I detect that it is really a wrapper problem, but not about the LibusbJava.usb_get_busses().

      The bus object returns ok, but the information on it it's not the right one.

      How do I test it...

      1 - I power on my computer, that has instaled the "Ubuntu 7.10 Linux 2.6.22-14-generic" OS. (this is important because I find that it always fails the first time after a power on - It also fails on other situations)
      2 - I plug one "normal" flash disk (Alcor Mass Storage Device) on one of the usb ports.
      3 - Test with lsusb (linux command), testlibusb (libusb-0.1.12 test program) and with UsbView (ch.ntb.usb-0.5.6.jar)

      Responses:
      - lsusb (OK)
      Bus 002 Device 001: ID 0000:0000 
      Bus 001 Device 002: ID 058f:6331 Alcor Micro Corp.
      Bus 001 Device 001: ID 0000:0000

      - testlibusb (OK)
      Dev #1: Linux 2.6.22-14-generic ohci_hcd - OHCI Host Controller
      Dev #1: Linux 2.6.22-14-generic ohci_hcd - OHCI Host Controller
      Dev #2: Generic - Mass Storage Device

      - UsbView (OK)
      ...
      Usb_Bus 001
        Usb_Device 002
          Usb_Device_Descriptor idVendor: 0x58f, idProduct: 0x6331
              String descriptors
                 iManufacturer: Generic
                 iProduct: Mass Storage Device
                 iSerialNumber: 00147258001
      ...

      4 - Now, I plug one "Apple IPod Player" in another usb port.
      5 - Test it again with lsusb (linux command), testlibusb (libusb-0.1.12 test program) and with UsbView (ch.ntb.usb-0.5.6.jar) and...

      Responses:
      - lsusb (OK)
      Bus 002 Device 002: ID 05ac:1209 Apple Computer, Inc.
      Bus 002 Device 001: ID 0000:0000 
      Bus 001 Device 002: ID 058f:6331 Alcor Micro Corp.
      Bus 001 Device 001: ID 0000:0000

      - testlibusb (OK)
      Dev #1: Linux 2.6.22-14-generic ohci_hcd - OHCI Host Controller
      Dev #2: Apple - iPod
      Dev #1: Linux 2.6.22-14-generic ohci_hcd - OHCI Host Controller
      Dev #2: Generic - Mass Storage Device

      - UsbView (ERROR - BUG) <----------------------------------
      ...
      Usb_Bus 002
        Usb_Device 002
          Usb_Device_Descriptor idVendor: 0x5ac, idProduct: 0x1209
              String descriptors
                 iManufacturer: Apple
                 iProduct: iPod
                 iSerialNumber: 000A270015DF556B
      ...
      Usb_Bus 001
        Usb_Device 002
          Usb_Device_Descriptor idVendor: 0x58f, idProduct: 0x6331 <----------- ITS OK
              String descriptors
                 iManufacturer: Apple                <------------------------- ERROR
                 iProduct: iPod                      <------------------------- ERROR
                 iSerialNumber: 000A270015DF556B     <------------------------- ERROR
      ...

      My Conclusion:

      OS (Linux) and libusb detects ok the usb devices including the String descriptions, the JavalibusbWrapper detects ok but muddled the String descriptions. This for me is a real problem cause my program depends on the iSerialNumber.

      If is there one work around for this "BUG", please tell me. If not maybe the developers of this wrapper cold launch a patch or a new version with the correction.

      Many thanks in advance.
      Nuno Lima

       
    • andi

      andi - 2008-02-07

      Hi

      Could you please try and run the following class (ch.ntb.usb.test.TestLibUsbJava). It should give you the exact same output as the testlibusb program (which you have already mentioned above).

      You will find the Class in the test folder on the trunk (https://libusbjava.svn.sourceforge.net/svnroot/libusbjava/trunk/java/test/ch/ntb/usb/test/TestLibUsbJava.java). It's not included in the jar file.

      I'm not quite sure what the problem is, but maybe it's a bug in UsbView. I don't think it's a general problem because reading the string descriptors is straight forward (JNI C-call):

           int retVal = usb_get_string((usb_dev_handle *) dev_handle, index, langid, string, 256);
           if (retVal > 0)
               return env->NewStringUTF(string);

      So the only critical information which is passed to the method is the device handle which might be wrong in your case (maybe messed up by UsbView).

      Just post the results here or send it per e-mail.

       
    • andi

      andi - 2008-02-07

      I forgot to mention: use -v as program argument to output more information (as in the normal testlibusb program):

      java ch.ntb.usb.test.TestLibUsbJava -v

       
    • Nuno Lima

      Nuno Lima - 2008-02-08

      Hi, spandi.

      Thank you for your fast answer.

      I have done what you asked.
      (I don't have here the iPod Player now but with other flash drive the problem is the same, so I use another Mass Storage Device)
      Here is the result (after power on >> insert Alcor USB Flash Disk >> insert XPing USB Flash Disk):

      --> lsusb (linux command)
      Bus 002 Device 002: ID 064f:03f2 XPing-Systems SA
      Bus 002 Device 001: ID 0000:0000 
      Bus 001 Device 002: ID 058f:6331 Alcor Micro Corp.
      Bus 001 Device 001: ID 0000:0000 

      --> testlibusb (libusb)
      Dev #1: Linux 2.6.22-14-generic ohci_hcd - OHCI Host Controller
      Dev #2: XPING-SYSTEMS SA - Flash-Stick X
      Dev #1: Linux 2.6.22-14-generic ohci_hcd - OHCI Host Controller
      Dev #2: Generic - Mass Storage Device

      --> testlibusb -v (libusb, now verbose)
      Dev #2: XPING-SYSTEMS SA - Flash-Stick X
        - Serial Number: 0001038622
        wTotalLength:         32
        bNumInterfaces:       1
        bConfigurationValue:  1
        iConfiguration:       4
        bmAttributes:         80h
        MaxPower:             75
          bInterfaceNumber:   0
          bAlternateSetting:  0
          bNumEndpoints:      2
          bInterfaceClass:    8
          bInterfaceSubClass: 6
          bInterfaceProtocol: 80
          iInterface:         5
            bEndpointAddress: 82h
            bmAttributes:     02h
            wMaxPacketSize:   64
            bInterval:        0
            bRefresh:         0
            bSynchAddress:    0
            bEndpointAddress: 01h
            bmAttributes:     02h
            wMaxPacketSize:   64
            bInterval:        0
            bRefresh:         0
            bSynchAddress:    0
      Dev #1: Linux 2.6.22-14-generic ohci_hcd - OHCI Host Controller
        - Serial Number: 0000:00:03.0
        wTotalLength:         25
        bNumInterfaces:       1
        bConfigurationValue:  1
        iConfiguration:       0
        bmAttributes:         e0h
        MaxPower:             0
          bInterfaceNumber:   0
          bAlternateSetting:  0
          bNumEndpoints:      1
          bInterfaceClass:    9
          bInterfaceSubClass: 0
          bInterfaceProtocol: 0
          iInterface:         0
            bEndpointAddress: 81h
            bmAttributes:     03h
            wMaxPacketSize:   2
            bInterval:        255
            bRefresh:         0
            bSynchAddress:    0
      Dev #2: Generic - Mass Storage Device
        - Serial Number: 00147258001          <--------------- HERE IS OK (with libusb)
        wTotalLength:         32
        bNumInterfaces:       1
        bConfigurationValue:  1
        iConfiguration:       0
        bmAttributes:         80h
        MaxPower:             125
          bInterfaceNumber:   0
          bAlternateSetting:  0
          bNumEndpoints:      2
          bInterfaceClass:    8
          bInterfaceSubClass: 6
          bInterfaceProtocol: 80
          iInterface:         0
            bEndpointAddress: 01h
            bmAttributes:     02h
            wMaxPacketSize:   64
            bInterval:        0
            bRefresh:         0
            bSynchAddress:    0
            bEndpointAddress: 82h
            bmAttributes:     02h
            wMaxPacketSize:   64
            bInterval:        0
            bRefresh:         0
            bSynchAddress:    0
      Dev #1: Linux 2.6.22-14-generic ohci_hcd - OHCI Host Controller
        - Serial Number: 0000:00:02.0
        wTotalLength:         25
        bNumInterfaces:       1
        bConfigurationValue:  1
        iConfiguration:       0
        bmAttributes:         e0h
        MaxPower:             0
          bInterfaceNumber:   0
          bAlternateSetting:  0
          bNumEndpoints:      1
          bInterfaceClass:    9
          bInterfaceSubClass: 0
          bInterfaceProtocol: 0
          iInterface:         0
            bEndpointAddress: 81h
            bmAttributes:     03h
            wMaxPacketSize:   2
            bInterval:        255
            bRefresh:         0
            bSynchAddress:    0

      TestLibUsbJava (the class that you recomend)
      Dev #2: XPING-SYSTEMS SA - Flash-Stick X
      Dev #2: XPING-SYSTEMS SA - Flash-Stick X           <--------------- HERE IS THE BUG (with TestLibUsbJava)

      TestLibUsbJava.jar -v (the class that you recomend, now verbose)
      Dev #2: XPING-SYSTEMS SA - Flash-Stick X           <--------------- OK
        - Serial Number: 0001038622           <--------------- OK
        wTotalLength:         32
        bNumInterfaces:       1
        bConfigurationValue:  1
        iConfiguration:       4
        bmAttributes:         80h
        MaxPower:             75
          bInterfaceNumber:   0
          bAlternateSetting:  0
          bNumEndpoints:      2
          bInterfaceClass:    8
          bInterfaceSubClass: 6
          bInterfaceProtocol: 80
          iInterface:         5
            bEndpointAddress: 82h
            bmAttributes:     02h
            wMaxPacketSize:   64
            bInterval:        0
            bRefresh:         0
            bSynchAddress:    0
            bEndpointAddress: 01h
            bmAttributes:     02h
            wMaxPacketSize:   64
            bInterval:        0
            bRefresh:         0
            bSynchAddress:    0
      Dev #1: Linux 2.6.22-14-generic ohci_hcd - OHCI Host Controller
        - Serial Number: 0000:00:03.0
        wTotalLength:         25
        bNumInterfaces:       1
        bConfigurationValue:  1
        iConfiguration:       0
        bmAttributes:         e0h
        MaxPower:             0
          bInterfaceNumber:   0
          bAlternateSetting:  0
          bNumEndpoints:      1
          bInterfaceClass:    9
          bInterfaceSubClass: 0
          bInterfaceProtocol: 0
          iInterface:         0
            bEndpointAddress: 81h
            bmAttributes:     03h
            wMaxPacketSize:   2
            bInterval:        -1
            bRefresh:         0
            bSynchAddress:    0
      Dev #2: XPING-SYSTEMS SA - Flash-Stick X           <--------------- HERE IS THE BUG (with TestLibUsbJava -v)
        - Serial Number: 0001038622           <--------------- HERE IS THE BUG (with TestLibUsbJava -v)
        wTotalLength:         32
        bNumInterfaces:       1
        bConfigurationValue:  1
        iConfiguration:       0
        bmAttributes:         80h
        MaxPower:             125
          bInterfaceNumber:   0
          bAlternateSetting:  0
          bNumEndpoints:      2
          bInterfaceClass:    8
          bInterfaceSubClass: 6
          bInterfaceProtocol: 80
          iInterface:         0
            bEndpointAddress: 01h
            bmAttributes:     02h
            wMaxPacketSize:   64
            bInterval:        0
            bRefresh:         0
            bSynchAddress:    0
            bEndpointAddress: 82h
            bmAttributes:     02h
            wMaxPacketSize:   64
            bInterval:        0
            bRefresh:         0
            bSynchAddress:    0
      Dev #1: Linux 2.6.22-14-generic ohci_hcd - OHCI Host Controller
        - Serial Number: 0000:00:03.0           <--------------- BUG AGAIN (with TestLibUsbJava -v) - sould be 0000:00:02.0
        wTotalLength:         25
        bNumInterfaces:       1
        bConfigurationValue:  1
        iConfiguration:       0
        bmAttributes:         e0h
        MaxPower:             0
          bInterfaceNumber:   0
          bAlternateSetting:  0
          bNumEndpoints:      1
          bInterfaceClass:    9
          bInterfaceSubClass: 0
          bInterfaceProtocol: 0
          iInterface:         0
            bEndpointAddress: 81h
            bmAttributes:     03h
            wMaxPacketSize:   2
            bInterval:        -1         <---------- DIFERENT BUT NOT BUG (in libusb is -1, it's just a java thing)
            bRefresh:         0
            bSynchAddress:    0

      If I can do some thing more to help, please tell me. I really would like to solve this problem.

      Many thanks.
      Nuno Lima

       
    • andi

      andi - 2008-03-10

      As information for others. This problem is solved in release 20080218 https://sourceforge.net/project/showfiles.php?group_id=188245.

       

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.