在Android开发中,如果涉及到与外设硬件、新设备的通信,往往需要通过串口来完成。这儿梳理总结一下Android串口的一些知识。
我就直接引用Google开源项目中的资料:
https://code.google.com/p/android-serialport-api/wiki/android_to_rs232_guideline?tm=6
引用
Here is a page describing the different ways you could use to connect an Android device to an RS232 peripheral.



Android串口通信:基本知识梳理_第1张图片


引用
Solution 1
pros
No need for external API, the Android SDK provides the class BluetoothSocket
No need for hardware modifications
hardware flow control is supported
cons
Bluetooth consume battery
high latency
low bandwidth
API
Android SDK


参考地址(要fanqiang):
BluetoothSocket:http://developer.android.com/reference/android/bluetooth/BluetoothSocket.html
Android SDK:http://developer.android.com/guide/topics/connectivity/bluetooth.html

引用
Solution 2
pros
USB to RS232 adapters are cheap and easy to find
no hardware modification needed
no external battery needed
low latency
high bandwidth
cons
your Android device needs an USB host connector (most tablets have one, but phones usually don't)
your may need to root your device in order to change /dev/ttyUSB0 file permission, and to load a kernel module.
API
android-serialport-api


引用
Solution 3
pros
The cheapest solution
cons
hardware adapter must be built (http://www.instructables.com/id/Android-G1-Serial-Cable)
very few Android devices compatibles
hardware flow control is not supported (only RX/TX, no RTS/CTS signals)
API
android-serialport-api


引用
Solution 4
pros
compatible with any Android device with an USB slave connector, i.e. 99.9% of the Android devices.
no need to root your phone
low latency
high bandwidth
you may use other GPIOs of the microcontroller at the same time
cons
API
https://github.com/ytai/ioio/wiki/UART


大概意思如下:
引用
上图中用与Android与串口设备通信的方案有四种:
第一种是直接用SDK的BluetoothSocket类来进行蓝牙通信,外部设备再用蓝牙转串口进行控制。这种方式有较高延时,蓝牙模块需要供电,低带宽。
第二种是使用USB转RS232方式(使用内核驱动和使用Android驱动两种方式),这种方式不需要硬件改动,不需要另外的供电,延时很小且有较高带宽。但是Android设备需要硬件上支持USB Host接口(一般Android平板支持,Android手机一般是没有的),另外可能需要root以改变/dev/ttyUSB0文件权限来加载一个内核模块。开发需要使用android_serialport_api。
第三种是最容易的方案,直接使用串口进行连接,但是这种方式兼容性不好,只有少数设备支持,而且串口不支持流控制(由Android提供的USB Host API决定的)。使用时也用android_serialport_api。
第四种是将Android作为USB从机,外部设备作为USB主机与之通信,这种方式几乎与所有Android设备兼容(一般都有USB从口),无需root,低延迟,高带宽。

更多相关文章

  1. Android O(8.0)创建桌面快捷方式
  2. Android - 设备的DeviceId
  3. Android的三种网络通信方式
  4. android存取数据方式:文件、SharedPreferences
  5. Android解析XML文件的三种方式
  6. android5中数据存储方式详解
  7. 通过ua检测浏览页面的设备是phone还是tablet
  8. Android 4.0 SDK的离线方式安装
  9. android 4种存储方式

随机推荐

  1. 开源镜像站-Android镜像
  2. Rockchip查看Android SDK版本
  3. Android(安卓)PreferenceScreen和CheckBo
  4. Android之Json解析
  5. android 自定义menu背景
  6. 判断android应用程序是否已安装
  7. android 动态设置圆角背景(来自http://www
  8. android获取屏幕的尺寸,宽度和高度
  9. 8.Swift openURL
  10. 柱状图以及饼图进行数据统计