开发者

USB Host Mode on XOOM - problems with communicating with a CP2102 Virtual Com port device

开发者 https://www.devze.com 2023-03-14 00:21 出处:网络
I am trying to write an Android app using the USB host mode on a Motorola Xoom with Android version 3.1 (build HMJ37) using the new Android host USB APIs to communicate over USB with a device that use

I am trying to write an Android app using the USB host mode on a Motorola Xoom with Android version 3.1 (build HMJ37) using the new Android host USB APIs to communicate over USB with a device that uses a Silicon Labs CP2102 Virtual COM Port Interface (USB to serial bridge). I have been using the AdbTest application example from the Android developer's site as a guideline.

I have been having trouble reading characters sent in on the UART side of the CP2102. Single byte bulk transfers work fine, but not if I ask for more than 1 byte of data. I know the d开发者_JS百科ata is there because I can send a GET_COMM_STATUS command using USBDeviceConnection.controlTransfer() and see that there are characters in the InQueue buffer on the CP2102. However, when I request more than one byte from the In Endpoint either by using USBRequest.queue() (asynchronous) or the SBDeviceConnection.bulkTransfer() (synchronous) functions, the buffer that is returned contains invalid characters.

Here's what does work:

  1. intent fires upon insertion and deletion of USB device
  2. application starts, finds USB device, connections, interfaces, endpoints, and claims interface
  3. can configure the CP2102 by sending USBDeviceConnection.controlTransfer() commands
  4. Characters are successfully transmitted out the UART side of the CP2102 by sending data to the Out Endpoint using USBRequest.queue().
  5. Single characters (separated by time delays) coming in the UART side of the CP2102 are successfully read from the bulk transfer In Endpoint using either the synchronous or asynchronous commands.

Problems arise when I try to send characters in a streak. However, I am only sending data at 9600 baud on the UART side and am not sending so many characters that I fill up the buffer on the CP2102.

I am using the Xoom as the power source for the device. I get the same behavior on two different XOOMs. I'm using the Motorola Camera Connection Kit for MOTOROLA XOOM as my USB host cable.

Can anyone give me guidelines on how to make this work? Or is the Honeycomb 3.1 USB host API on the XOOM not yet really stable?


make sure that you examine the returned bytes count, so you will not consume more data from the buffer than the actual returned data. also check if more than one thread are accessing the buffer which may corrupt the returned data if access to buffer is not synchronized properly.

0

精彩评论

暂无评论...
验证码 换一张
取 消