I've written an app to connect an USB Device that have 1 Interfaces
with 2 connected Endpoints:
i have android 3.1 USB Host tab device and i have external device
scanner in which FDTI FT232BM chip
and It is a USB device that emulates a RS232 interface it appears as a
RS232 port to talk to the
Atmel AT90LS8535 processor.
when i connect device to tab successfully action get device attached.
Open UsbDeviceConnection is suuccess. get endpoint and when receive
data
every time buffer or byte geting zero values in bytes. i have try two
way
to fetch receive data from external device but both way i getting
response
zero value in buffer / bytes.
Please any one suggest me any step missing me or how to get data from
my external USB device ?
here i paste code of both way are seprate thread and try to receive
data but not got.
First Way :
byte [] buffer = new byte[4096];
read =
deviceConnection.bulkTransfer(deviceInterface.getEndpoint(0), buffer,
4096, 10000);
if(read > 2)
{
total += read - 2;
for(int i = 2; i < read; i++) {
String value = Byte.toString(buffer[i]);
Log.e("","i : " +i+" value : "+value);
}
}
Second Way :
UsbRequest request = null;
ByteBuffer buffer1 = ByteBuffer.allocate(4096);
request = new UsbRequest();
request.initialize(deviceConnection,
deviceInterface.getEndpoint(0));
buffer1.order(ByteOrder.BIG_ENDIAN);
request.queue(buffer1, 4096);
if (deviceConnection.requestWait() == request)
{
Log.e("","Get Data : "+
extractString(buffer1,0,4095));
}
private static String extractString(ByteBuffer buffer, int offset, int
length) {
byte[] bytes = new byte[length];
for (int i = 0; i < length; i++) {
bytes[i] = buffer.get(offset++);
}
return new String(bytes);
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en