在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(安卓)架构解析及驱动 键盘篇
  2. 通过ijetty获取android设备的截图
  3. Android(安卓)Camera2 之 CameraDevice 详解
  4. mac电脑开发android找不到设备
  5. android系统中运行jar文件
  6. Android串口通信:基本知识梳理
  7. android kernel和标准linux kernel的区别
  8. Android(安卓)内核与标准Linux内核的区别
  9. android linux kernel和standard linux kernel的区别

随机推荐

  1. 单线程模型中Message、Handler、Message
  2. Android 自定义View
  3. 手机敲命令利器---Android Terminal
  4. 《Android深度探索(卷1):HAL与驱动开发》新
  5. android里ksoap2调用WebService
  6. java/android下的并发编程
  7. 播放器适配经验总结——Android
  8. Android内核开发:学会分析系统的启动log
  9. eclipse中关联源码
  10. 杂乱之android的字体相关类Typeface