title: Reading data from USB Port
body: <p>currently I am working on a project for university where i have to create a program which controls the humidity in a terrarium. 
  On this purpose i've got an hygrometer. </p>
  
  <p>First of all the program has to import the raw data from the hygrometer, but i have no idea how it works. 
  The documentation says there is an USB interface for it, but i can only find the way how to parse the raw data.
  I also wrote an Email to the company which sells this hygrometer. They said theres an external software which imports and handle with this data. However I am not allowed to use external softwares. 
  Therefore I am forced to read the raw data directly from the USB Port. I tried to work with usb4java but i was only able to find all connected usb devices. 
  I have no idea how to go on. Please help me 
  <a href="https://i.stack.imgur.com/ck1PC.png" rel="nofollow noreferrer">documentation</a>
  <a href="https://i.stack.imgur.com/KKtlf.png" rel="nofollow noreferrer">documentation</a></p>
  
  <p>Code below</p>
  
  <pre><code>public class DumpDevices
  {
  /**
   * Dumps the specified USB device to stdout.
   * 
   * @param device
   *            The USB device to dump. 
   */
  
  
  private static void dumpDevice(final UsbDevice device)
  {
      // Dump information about the device itself
      System.out.println(device);
      final UsbPort port = device.getParentUsbPort();
      if (port != null)
      {
          System.out.println("Connected to port: " + port.getPortNumber());
          System.out.println("Parent: " + port.getUsbHub());
      }
  
      // Dump device descriptor
      System.out.println(device.getUsbDeviceDescriptor());
  
      // Process all configurations
      for (UsbConfiguration configuration: (List&lt;UsbConfiguration&gt;) device
          .getUsbConfigurations())
      {
          // Dump configuration descriptor
          System.out.println(configuration.getUsbConfigurationDescriptor());
  
          // Process all interfaces
          for (UsbInterface iface: (List&lt;UsbInterface&gt;) configuration
              .getUsbInterfaces())
          {
              // Dump the interface descriptor
              System.out.println(iface.getUsbInterfaceDescriptor());
  
              // Process all endpoints
              for (UsbEndpoint endpoint: (List&lt;UsbEndpoint&gt;) iface
                  .getUsbEndpoints())
              {
                  // Dump the endpoint descriptor
                  System.out.println(endpoint.getUsbEndpointDescriptor());
              }
          }
      }
  
      System.out.println();
  
      // Dump child devices if device is a hub
      if (device.isUsbHub())
      {
          final UsbHub hub = (UsbHub) device;
          for (UsbDevice child: (List&lt;UsbDevice&gt;) hub.getAttachedUsbDevices())
          {
              dumpDevice(child);
          }
          System.out.println(hub);
      }
  }
  
  
  /**
   * Main method.
   * 
   * @param args
   *            Command-line arguments (Ignored)
   * @throws UsbException
   *             When an USB error was reported which wasn't handled by this
   *             program itself.
   */
  public static void main(final String[] args) throws UsbException
  {
      // Get the USB services and dump information about them
      final UsbServices services = UsbHostManager.getUsbServices();
      System.out.println("USB Service Implementation: "
          + services.getImpDescription());
      System.out.println("Implementation version: "
          + services.getImpVersion());
      System.out.println("Service API version: " + services.getApiVersion());
      System.out.println();
  
      // Dump the root USB hub
      dumpDevice(services.getRootUsbHub());
  }
  </code></pre>