Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

AndroidSerialPort

> 编程语言
Open source

Android串口通信示例

737 stars0 likes0 views
WebsiteGitHub

About

说明

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:

gradle
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency

gradle
dependencies {
        compile 'com.github.kongqw:AndroidSerialPort:1.0.1'
}

查看串口

java
SerialPortFinder serialPortFinder = new SerialPortFinder();
ArrayList devices = serialPortFinder.getDevices();

打开串口

初始化

java
mSerialPortManager = new SerialPortManager();

添加打开串口监听

java
mSerialPortManager.setOnOpenSerialPortListener(new OnOpenSerialPortListener() {
    @Override
    public void onSuccess(File device) {
        
    }

    @Override
    public void onFail(File device, Status status) {

    }
});

添加数据通信监听

java
mSerialPortManager.setOnSerialPortDataListener(new OnSerialPortDataListener() {
    @Override
    public void onDataReceived(byte[] bytes) {
        
    }

    @Override
    public void onDataSent(byte[] bytes) {

    }
});

打开串口

  • 参数1:串口
  • 参数2:波特率
  • 返回:串口打开是否成功
java
boolean openSerialPort = mSerialPortManager.openSerialPort(device.getFile(), 115200);

发送数据

  • 参数:发送数据 byte[]
  • 返回:发送是否成功
java
boolean sendBytes = mSerialPortManager.sendBytes(sendContentBytes);

关闭串口

java
mSerialPortManager.closeSerialPort();

PS:传输协议需自行封装

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Javaserial-communicationserial-portserial-portsserialport

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言