Communicating with a USB device in Android
Http://gssdaily.com/forum/viewtopic.php? F = 17 & t = 96084
By
Jack» Sat Sep 29,201 2 pm
Communicating with a USB device in Android
Communication with a USB device can be either synchronous or asynchronous. in either case, You shoshould 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 USB interface and USB endpoint of the device that you want to communicate on and send requests on this endpoint with a USB deviceconnection.
-
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,201 0 pm