Using Android to Communicate with a USB HID Device

前端 未结 3 842
长情又很酷
长情又很酷 2020-12-08 08:19

I am new to USB and to Android so please forgive me if I don\'t explain myself clearly.

I have a USB HID device that I can communicate with in Windows. I am trying

3条回答
  •  生来不讨喜
    2020-12-08 09:17

    You can get a full list of the details of interfaces and endpoint by using the following:

    UsbManager mManager = (UsbManager) getSystemService(Context.USB_SERVICE);
    HashMap deviceList = mManager.getDeviceList();
    Iterator deviceIterator = deviceList.values().iterator();
    
    while (deviceIterator.hasNext())
        {
            UsbDevice device = deviceIterator.next();
            Log.i(TAG,"Model: " + device.getDeviceName());
            Log.i(TAG,"ID: " + device.getDeviceId());
            Log.i(TAG,"Class: " + device.getDeviceClass());
            Log.i(TAG,"Protocol: " + device.getDeviceProtocol());
            Log.i(TAG,"Vendor ID " + device.getVendorId());
            Log.i(TAG,"Product ID: " + device.getProductId());
            Log.i(TAG,"Interface count: " + device.getInterfaceCount());
            Log.i(TAG,"---------------------------------------");
       // Get interface details
            for (int index = 0; index < device.getInterfaceCount(); index++)
            {
            UsbInterface mUsbInterface = device.getInterface(index);
            Log.i(TAG,"  *****     *****");
            Log.i(TAG,"  Interface index: " + index);
            Log.i(TAG,"  Interface ID: " + mUsbInterface.getId());
            Log.i(TAG,"  Inteface class: " + mUsbInterface.getInterfaceClass());
            Log.i(TAG,"  Interface protocol: " + mUsbInterface.getInterfaceProtocol());
            Log.i(TAG,"  Endpoint count: " + mUsbInterface.getEndpointCount());
        // Get endpoint details 
                for (int epi = 0; epi < mUsbInterface.getEndpointCount(); epi++)
            {
                UsbEndpoint mEndpoint = mUsbInterface.getEndpoint(epi);
                Log.i(TAG,"    ++++   ++++   ++++");
                Log.i(TAG,"    Endpoint index: " + epi);
                Log.i(TAG,"    Attributes: " + mEndpoint.getAttributes());
                Log.i(TAG,"    Direction: " + mEndpoint.getDirection());
                Log.i(TAG,"    Number: " + mEndpoint.getEndpointNumber());
                Log.i(TAG,"    Interval: " + mEndpoint.getInterval());
                Log.i(TAG,"    Packet size: " + mEndpoint.getMaxPacketSize());
                Log.i(TAG,"    Type: " + mEndpoint.getType());
            }
            }
        }
        Log.i(TAG," No more devices connected.");
    }
    

提交回复
热议问题