Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Host API communicating with a device
    primarykey
    data
    text
    <p>I need to communicate with a USB communicate device using android host API</p> <p>This is the information of the device I'm working with. </p> <p>lsusb -v -d PID:VID</p> <p>Bus 003 Device 007: ID PIDVID VOTI </p> <p>Device Descriptor:</p> <pre><code>bLength 18 bDescriptorType 1 bcdUSB 1.01 bDeviceClass 2 Communications bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 8 idVendor PID VOTI idProduct VID bcdDevice 1.00 iManufacturer 1 iProduct 2 iSerial 0 bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 67 bNumInterfaces 2 bConfigurationValue 1 iConfiguration 0 bmAttributes 0x80 (Bus Powered) MaxPower 100mA </code></pre> <p>Interface Descriptor:</p> <pre><code> bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 1 bInterfaceClass 2 Communications bInterfaceSubClass 2 Abstract (modem) bInterfaceProtocol 1 AT-commands (v.25ter) iInterface 0 CDC Header: bcdCDC 1.10 CDC ACM: bmCapabilities 0x02 line coding and serial state CDC Union: bMasterInterface 0 bSlaveInterface 1 CDC Call Management: bmCapabilities 0x03 call management use DataInterface bDataInterface 1 </code></pre> <p>Endpoint Descriptor:</p> <pre><code> bLength 7 bDescriptorType 5 bEndpointAddress 0x83 EP 3 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0008 1x 8 bytes bInterval 100 </code></pre> <p>Interface Descriptor:</p> <pre><code> bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 0 bNumEndpoints 2 bInterfaceClass 10 CDC Data bInterfaceSubClass 0 Unused bInterfaceProtocol 0 iInterface 0 </code></pre> <p>Endpoint Descriptor:</p> <pre><code> bLength 7 bDescriptorType 5 bEndpointAddress 0x01 EP 1 OUT bmAttributes 2 Transfer Type Bulk Synch Type None Usage Type Data wMaxPacketSize 0x0006 1x 6 bytes bInterval 0 </code></pre> <p>Endpoint Descriptor:</p> <pre><code> bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 2 Transfer Type Bulk Synch Type None Usage Type Data wMaxPacketSize 0x0008 1x 8 bytes bInterval 0 </code></pre> <p>Now I can discover the device and obtain permission to communicate with the device. But when I try to communicate with the device using bulkTransfer() function, it always return -1.</p> <p>Here is the code</p> <pre><code>UsbDeviceConnection conn = mUsbManager.openDevice(mDevice); conn.controlTransfer(33, 34, 0, 0, null, 0, 0); byte[] buffer = new byte[]{ (byte) 0x80,0x25, 0x00, 0x00, 0x00, 0x00, 0x08 }; conn.controlTransfer(33, 32, 0, 0, buffer , 7, 0); //8N1, 9600 baud conn.bulkTransfer(epOUT, new byte[]{msData}, 1, 0); UsbEndpoint epIN = null; UsbEndpoint epOUT = null; UsbInterface usbIf = mDevice.getInterface(1); for (int i = 0; i &lt; usbIf.getEndpointCount(); i++) { if (usbIf.getEndpoint(i).getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) { if (usbIf.getEndpoint(i).getDirection() == UsbConstants.USB_DIR_IN) epIN = usbIf.getEndpoint(i); else epOUT = usbIf.getEndpoint(i); } } for (;;) {// this is the main loop for transferring synchronized (sSendLock) {//ok there should be a OUT queue try { sSendLock.wait(); } catch (InterruptedException e) { if (mStop) { mConnectionHandler.onUsbStopped(); return; } e.printStackTrace(); } } conn.bulkTransfer(epOUT, new byte[] { mData }, 1, 0); if (mStop) { mConnectionHandler.onUsbStopped(); return; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload