Android 3.1+ USB as virtual COM port

androidserial-portusb

I have a third party usb device, that when plugged into a Windows machine, is recognized as a serial device and assigned to the COM 4 port. I can communicate with the device just like I would with a device connected via a serial port. For instance, I can write "abc" serially to the device via the USB connection.

I have been searching for a way to do a similar thing in Android. If I try the Usb Host method, and use a UsbManager to open the UsbDevice, I can get one interface, with 2 endpoints. I have tried sending control messages using the method in UsbDeviceConnection, but the method returns -1 for everything (though I don't know what I should use for the parameters of that method).

Is there a way to get an OutputStream that I can write to that will send bytes to the USB device? Right now I am looking at recompiling the kernel to include a virtual COM port driver and write some native code to be able to do this.

Thanks!

Edit: I am using the FTDI serial to USB converter circuit. Is this compatible with Android?

Best Answer

If linux kernel in your device supports FTDI, you can access this device as normal COM port. It will be named something like /dev/ttyUSB0.

If your kernel does not supports this type of devices, you can write your own driver using UsbHost interfaces. Check kernel's FTDI driver source code for guide.