最近在做人脸识别闸机,人脸识别认证成功后通过android端打开闸机,需要用到串口通信。
这里说一下串口通信实现的步骤及自己踩过的一些坑。
如图,其实所用到的还是谷歌2013年的代码库serialport-api,so库也都是谷歌原库
将下载好的库文件copy到你项目中如图所示的位置即可。
需要特别提出的是,SerialPort、SerialPortFinder必须放在android_serialport_api包下,你需要新建一个包。
下载地址:GitHub-android-serialport-api
现在说说遇到的坑,
public SerialPort(File device, int baudrate, int flags,Context context) throws SecurityException, IOException {
/* Check access permission */
if (!device.canRead() || !device.canWrite()) {
try {
/* Missing read/write permission, trying to chmod the file */
Process su;
su = Runtime.getRuntime().exec("/system/bin/su");
Stri