I am trying to write an android app to read and write data from android tablet to our embedded device. The tablet and embedded device are connected via usb to serial converter. Is it possible to read data from the embedded device into our android tablet? Any sample code that I can take a look at?
-
Have you seen [this](http://developer.android.com/guide/topics/usb/accessory.html) or [this](http://developer.android.com/guide/topics/usb/host.html) documentation? – Jack Apr 26 '12 at 20:09
-
Yes, Jack, I read the later one. I started a new question, please take a look. Thanks! – dan May 01 '12 at 16:08
2 Answers
I suggest using the ported usb-for-android lib, which has the PL2303 driver already implemented: https://code.google.com/r/felixhaedicke-usb-serial-for-android
I've used it successfully.

- 15,728
- 7
- 61
- 91
As a serial converter is a USB device, the android tablet has to act as a USB host. This feature is available since Android 3.1. The API documentation is available on the android developer page and includes code examples.
To actually communicate with the converter you will have to find out a bit more about it's internals: There are many different devices on the market, some using USB HID, others are using USB CDC device class or do not even comply to any class. The linux lsusb command might be helpful to get the device/interface descriptors.
On a typical CDC device you will have to interact with two bulk endpoints and probably use some interface related requests to setup the baudrate, etc. See the Communication Device Class specification on USB implementers forum.
If your device has only one IN and one OUT bulk endpoint (beside the control endpoint) you might try to use the UsbDeviceConnection.bulkTransfer() method on the OUT endpoint to write some bytes to the serial line. There is a good chance this will just work, however for a clean implementation you should stick to the class specification.

- 1,068
- 6
- 22
-
Hi, Alexander Thanks for the info. My connection is the tablet is connected with a usb/serial cable, whose one end is a usb port and the other end is a serial port. The serial port is connected with another serial cable which connects with the other embedded device. One thing I do not quite understand for the USB Host mode is I need to specify the vendro id, product id, class, subclass. How can I know those information? Connect usb/serial cable with a linux machine and find it out? THanks!!! – dan Apr 27 '12 at 15:41
-
Hi Bill, yes right linux or mac is handy here. There might be tools under Windows as well, but in linux it is really straight forward. You could use a linux live CD/USB Stick boot version. Then run lsusb in a shell with your converter attached to the PC. It should appear in the output of the command. Mine looks like: `Bus 004 Device 002: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port` – Alexander Apr 28 '12 at 14:15
-
The numbers after ID are the _vendor_ : _product_ IDs of your device. Then run `lsusb -v -d 067b:2303` to get the full device descriptor. There you can read about the class and subclass. As you do not seem quite familiar with USB I suggest to read a bit about the whole USB concept. Maybe [here](http://www.beyondlogic.org/usbnutshell/usb1.shtml). This will help you to get your goal. – Alexander Apr 28 '12 at 14:27
-
I started a new follow up question, please take a look at that because for some reason, it could not add comment just now... Thanks! – dan May 01 '12 at 16:06