在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.






引用
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系统中运行jar文件
  2. Qt on Android(安卓)Episode 3(翻译)
  3. Android(安卓)- 设备的DeviceId
  4. 自定义progressbar 的思路
  5. Android(安卓)Binder------ServiceManager启动分析
  6. Android(安卓)中文API (69) —— BluetoothAdapter[蓝牙]
  7. (Android(安卓)Studio 3.0)Android(安卓)Profiler内存泄漏检查
  8. 转- ADB(Android(安卓)Debug Bridge)技术实现
  9. 命令行创建虚拟环境

随机推荐

  1. android 模拟器和电脑服务器端用socket通
  2. android view框架总结
  3. android电源管理资料整理
  4. android launchmode(四种启动模式)应用场
  5. Android(安卓)笔记 03
  6. 手机的软件形态
  7. Android实现长按录音松开保存、播放及根
  8. Android中的各种单位
  9. Android(安卓)是Google开发的基于Linux平
  10. 将Eclipse的工程转移到Android(安卓)Stud