Programming USB system with the JSR-80 API


The normal procedure for accessing a USB device with the JSR-80 API is as follows:
  1. Bootstrap by getting the appropriate UsbServices from the UsbHostManager.
  2. Access the root hub through the UsbServices. The root hub is considered as a UsbHub in the application.
  3. Obtain a list of the UsbDevices that are connected to the root hub. Traverse through all the lower-level hubs to find the appropriate UsbDevice.
  4. Interact with the UsbDevice directly with a control message (UsbControlIrp), or claim a UsbInterface from the appropriate UsbConfiguration of the UsbDevice and perform I/O with theUsbEndpoint available on the UsbInterface.
  5. If a UsbEndpoint is used to perform I/O, open the UsbPipe associated with it. Both upstream data (from the USB device to the host computer) and downstream data (from the host computer to the USB device) can be submitted either synchronously or asynchronously through the UsbPipe.
  6. Close the UsbPipe and release the appropriate UsbInterface when the application no longer needs access to the UsbDevice.  

Obtaining the content of the USB system with the JSR-80 API



// Comment
import javax.usb.*;
import java.util.List;
 
public class TraverseUSB
{
        public static void main(String argv[])
        {
          try
          {
              // Access the system USB services, and access to the root 
              // hub. Then traverse through the root hub.
              UsbServices services = UsbHostManager.getUsbServices();
              UsbHub rootHub = services.getRootUsbHub();
              traverse(rootHub);
          } catch (Exception e) {}
        }
 
        public static void traverse(UsbDevice device)
        {
          if (device.isUsbHub())
          {   
             // This is a USB Hub, traverse through the hub.
             List attachedDevices = 
                 ((UsbHub) device).getAttachedUsbDevices();
             for (int i=0; i<attachedDevices.size(); i++)
             {
               traverse((UsbDevice) attachedDevices.get(i));
             }
          }
          else
          {
             // This is a USB function, not a hub.
             // Do something.
          }
        }
}


1 comments:

Rizkinya Rizki said...

hii..

i have tried the code using
1. Netbeans IDE 7.1.2 on my windows 7 64 bit and my Kubuntu 64 bit.
2. i have added JSR-80 API.jar and jUSB API.jar on my library
3. both of system connected to USB to serial device and USB flash drive.
4. when i run this code, i just get notification like this "BUILD SUCCESSFUL (total time: 1 second) ".
5. in my mind JSR80 and jUSB can running on windows based and linux based.

could you explain me why...?

thankyou

Post a Comment

Related Posts Plugin for WordPress, Blogger...