Communicating with a USB device in Android
http://gssdaily.com/forum/viewtopic.php?f=17&t=96084
by
jack » Sat Sep 29, 2012 10:18 pm
Communicating with a USB device in Android
Communication with a USB device can be either synchronous or asynchronous. In either case, you should create a new thread on which to carry out all data transmissions, so you don't block the UI thread. To properly set up communication with a device, you need
to obtain the appropriate UsbInterface and UsbEndpoint of the device that you want to communicate on and send requests on this endpoint with a UsbDeviceConnection.
-
Code:
Select all
-
rivate Byte[] bytes
private static int TIMEOUT = 0;
private boolean forceClaim = true;...
UsbInterface intf = device.getInterface(0);
UsbEndpoint endpoint = intf.getEndpoint(0);
UsbDeviceConnection connection = mUsbManager.openDevice(device);
connection.claimInterface(intf, forceClaim);
connection.bulkTransfer(endpoint, bytes, bytes.length, TIMEOUT); //do in another thread
-
jack
-
-
Posts: 425
-
Joined: Tue Nov 30, 2010 10:29 pm