프로젝트
GitHub에서 보기
kongqw/AndroidSerialPort
소개
Android 시리얼 포트 통신 예제
기타 프로젝트측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- -1
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Original说明
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<Device> 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) {
}
});
打开串口
- 参数1:串口
- 参数2:波特率
- 返回:串口打开是否成功
boolean openSerialPort = mSerialPortManager.openSerialPort(device.getFile(), 115200);
发送数据
- 参数:发送数据 byte[]
- 返回:发送是否成功
boolean sendBytes = mSerialPortManager.sendBytes(sendContentBytes);
关闭串口
mSerialPortManager.closeSerialPort();
PS:传输协议需自行封装
관련 프로젝트 살펴보기
불러오는 중…