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'
}SerialPortFinder serialPortFinder = new SerialPortFinder();
ArrayList devices = serialPortFinder.getDevices();mSerialPortManager = new SerialPortManager();mSerialPortManager.setOnOpenSerialPortListener(new OnOpenSerialPortListener() {
@Override
public void onSuccess(File device) {
}
@Override
public void onFail(File device, Status status) {
}
});mSerialPortManager.setOnSerialPortDataListener(new OnSerialPortDataListener() {
@Override
public void onDataReceived(byte[] bytes) {
}
@Override
public void onDataSent(byte[] bytes) {
}
});boolean openSerialPort = mSerialPortManager.openSerialPort(device.getFile(), 115200);boolean sendBytes = mSerialPortManager.sendBytes(sendContentBytes);mSerialPortManager.closeSerialPort();PS:传输协议需自行封装
No open issues yet, or sync has not completed.