Read and writer data via USB port on Android 3.1

孤街浪徒 提交于 2019-12-03 04:22:16

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!