android-serialport-api

Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
allprojects { repositories {... maven { url'https://jitpack.io' } }}Step 2. Add the dependency
dependencies { compile'com.github.kongqw:AndroidSerialPort:1.0.1'}SerialPortFinderserialPortFinder =newSerialPortFinder();ArrayList<Device>devices =serialPortFinder.getDevices();
mSerialPortManager =newSerialPortManager();
mSerialPortManager.setOnOpenSerialPortListener(newOnOpenSerialPortListener() {@OverridepublicvoidonSuccess(Filedevice) { }@OverridepublicvoidonFail(Filedevice,Statusstatus) { }});mSerialPortManager.setOnSerialPortDataListener(newOnSerialPortDataListener() {@OverridepublicvoidonDataReceived(byte[]bytes) { }@OverridepublicvoidonDataSent(byte[]bytes) { }});booleanopenSerialPort =mSerialPortManager.openSerialPort(device.getFile(),115200);
booleansendBytes =mSerialPortManager.sendBytes(sendContentBytes);
mSerialPortManager.closeSerialPort();
PS:传输协议需自行封装