• Stars
    star
    719
  • Rank 62,985 (Top 2 %)
  • Language
    Java
  • Created about 8 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Android串口通信示例

说明

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<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:传输协议需自行封装

More Repositories

1

OpenCVForAndroid

目标检测&目标追踪&人脸检测&人脸识别
Java
2,048
star
2

AndroidRocker

Android 摇杆
Java
276
star
3

AndroidWiFiManager

Android WiFi Manager
Java
126
star
4

NetworkMonitor

Android 全局网络变化监听
Kotlin
45
star
5

Android-CheckView

Android端手机验证码的生成
Java
38
star
6

WeChatHelper

WeChatHelper for androidx ,微信开放平台封装,包含微信分享、微信授权登录、微信支付
Kotlin
25
star
7

CombinedChartDemo

模拟自选股
Java
21
star
8

AndroidRadarScanView

Android Radar Scan 雷达扫描控件
Java
21
star
9

AndroidSoundManagerDemo

Android左右声道控制的示例程序
Java
17
star
10

AndroidBluetoothManager

Android Bluetooth Library
Java
17
star
11

PermissionsManager

Android 6.0 动态权限管理器
Kotlin
16
star
12

KqwOpenCVFeaturesDemo

图像边缘检测
Java
16
star
13

AndroidAssistiveTouch

模仿iphone AssistiveTouch
Java
13
star
14

AndroidUsbSerialDemo

Android USB 串口通信
Java
13
star
15

KqwOpenCVBlurDemo

使用OpenCV实现图片虚化处理
Java
9
star
16

CountDownTimerDemo

发送验证码倒计时
Java
9
star
17

QQHelper

QQHelper for androidx,QQ开放平台功能封装,包含QQ分享,QQ授权登录
Kotlin
9
star
18

AndroidVolumeManager

Android 音量控制
Java
7
star
19

KqwBluetoothDemo

Java
5
star
20

KqwBottomNavigation

安卓底部导航栏
Java
3
star
21

KqwHciDemo

灵云语音
Java
3
star
22

VolumeController

Java
2
star
23

RecyclerViewItemClickDemo

自定义高效支持点击监听的RecyclerView
Java
2
star
24

SelectorDemo

状态选择器示例Demo
Java
2
star
25

TuringSDK

Java
2
star
26

KqwHciTtsDemo

灵云语音
Java
1
star
27

KTools

常用工具梳理
Kotlin
1
star
28

ShapeView

Kotlin
1
star
29

FirstOpenCVDemo

OpenCV的部署
Java
1
star