在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,低延迟,高带宽。
- 大小: 63.3 KB
分享到:
相关推荐
Android 串口通信DEMO,包括JNI CPP代码,SO库等.rar,应大家要求把所需积分改了,全部开源,绝对保证能用。
Android串口通信(Android Studio) serial Port 简单的demo 好久之前整的
Android 串口通信权限问题Android 串口通信权限问题Android 串口通信权限问题Android 串口通信权限问题
Android串口通信:抱歉,学会它真的可以为所欲为,详细解释参考博客:https://blog.csdn.net/u010312949/article/details/80199018
Android串口通信代码,注释超详细。AndroidSerialPort能让你很快的学习串口知识。生了很多时间网上找资源自研究的过程。
串口通信:串口收发数据,将接收到的数据写入数据库
串口通信:串口调试检测,数据传输.源码提供给大家学习.
在Android串口通信:基本知识梳理的基础上,我结合我项目中使用串口的实例,进行总结; Android使用jni直接进行串口设备的读写网上已经有开源项目了,本文是基于网上的开源项目在实际项目中的使用做的调整和优化; ...
android 串口测试demo 代码简单 无bug 完美运行 android 串口测试demo 代码简单 无bug 完美运行 android 串口测试demo 代码简单 无bug 完美运行 android 串口测试demo 代码简单 无bug 完美运行 android 串口测试demo...
串口通信:大家最常用的串口精灵.这源码就是模仿的供大家学习用.
串口通信:单简易懂的通信控制源码.发送接收处理.
串口通信:饭卡远程控制系统,可时时的监控目前的卡信息.
串口通信:连接ODBC来发送读写数据表.学习很不错的源码.
android 标准串口通信 收发数据
可以修改奇偶校验位的Android 串口通信demo!!!!!!!!!!!!!!!!
串口通信:智能安防控制系统,通过不同的命令控制前端设备的运行状态.
Android串口通信库源码,包括原生层的实现和JAVA层的封装,方便大家在Android应用上开发串口通信功能。
1个Android Studio写的串口通信demo blog:http://blog.csdn.net/shenyuanqing/article/details/49070079
要从google网下载,费了点事,终于下载了,自己做个备份。2020年2月10日从谷歌官方下载的最新源码,源码里有代码和demo,供学习研究。
Android应用串口通信源码Demo Demo源代码是自己开发项目中使用的 可以使用放心下载