Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getActiveUsbConfiguration returns null #21

Open
hamzeen opened this issue Mar 22, 2024 · 0 comments
Open

getActiveUsbConfiguration returns null #21

hamzeen opened this issue Mar 22, 2024 · 0 comments

Comments

@hamzeen
Copy link

hamzeen commented Mar 22, 2024

The Issue:

Sporadically we run into an issue where usbDevice.getActiveUsbConfiguration(); returns null.
The code was run on a virtual machine. Mostly, this issue occurs when the program is started on a PC without hardware & then the session is switched to a PC with the hardware.

tried the following:

  • list the usb devices using hub.getAttachedUsbDevices()
  • If the usb interface is still claimed, then release the usb interface
  • finally:
      private UsbConfiguration getUsbConfiguration() {
        UsbConfiguration config = null;

        if (usbDevice == null) {
          LOGGER.warn("The usbDevice is null!");
          return null;
        }

        synchronized (usbDevice) {
          config = usbDevice.getActiveUsbConfiguration();
          if (config != null) {
            return config;
          }

          List<UsbConfiguration> configs = getUsbDevice().getUsbConfigurations();
          if (!configs.isEmpty()) {
            for (UsbConfiguration temp : configs) {
              LOGGER.debug("UsbConfiguration:: {} \tis active: {} \tdevice: {}", 
                 temp.toString(), temp.isActive(), temp.getUsbDevice());
            }
            config = configs.get(0);
          }
          return config;
        }
      }

This is what we observe, when the above code runs following the issue:

  • in the first step, we see the device we need to communicate.

  • once we are in the last step to get a USB Configuration:

    1. getActiveUsbConfiguration() also returns null.
    2. Further down, when we loop through getUsbConfigurations() we can get hold of a UsbConfiguration. However, when we try to claim the usbInterface again, we end up with the following exception:
       java.util.concurrent.CompletionException: javax.usb.UsbNotActiveException: Pipe is not active.

I have 2 questions:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant