简体   繁体   中英

Android of Things communication with USB peripherals

I started my adventure with AoT (I have basic toolkit). 1rst Idea that I try to implement is to communicate via USB with Card Reader (USB Card Reader HID Prox v3).

But I don't get it correctly.

This is "sample" code:

 usbRequest = new UsbRequest();
 usbConnection = mUsbManager.openDevice(device);
usbRequest.initialize(usbConnection, device.getInterface(0).getEndpoint(0));//communication from card scanner
//In handler:
  byte[] byteArray = new byte[16];
            int transfer = usbConnection.bulkTransfer(device.getInterface(0).getEndpoint(0), byteArray, 16, 300);

transfer result is = -1, did anyone has the same issue?

Assumption: Your USB device conforms to the USB CCID Device Class . If this is not true, you will need to provide the datasheet for your specific card reader.

  1. Before you can execute any communications with USB endpoints, your app has to claim the interface first. In other words, there should be a call to claimInterface() in your code before any requests are sent.

  2. Next, you are mixing two different forms of communication. Your app should EITHER use UsbRequest for asynchronous use OR bulkTransfer() for synchronous use. You don't need to initialize a UsbRequest if you are using bulkTransfer() instead.

  3. You should verify what the max packet size of your UsbEndpoint is. Bulk CCID endpoints can support up to 512 byte packets, so a fixed length of 16 bytes may not be enough to read a full packet response (assuming this transaction was on the Bulk IN endpoint). Match your array size with your endpoint's packet size.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM