• Stars
    star
    1,096
  • Rank 42,298 (Top 0.9 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated about 2 years ago

Reviews

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

Repository Details

Fork自Google开源的Android串口通信Demo,修改成Android Studio项目

Android-SerialPort-API

Fork自Google开源的Android串口通信Demo,修改成Android Studio项目

This lib is a fork of the Android serial port communication Demo open sourced by Google.

Installation & Usage

Gradle

添加依赖:

Add the dependency:

allprojects {
    repositories {
        ...
        jcenter()
        mavenCentral() // since 2.1.3
    }
}

dependencies {
        implementation 'com.licheedev:android-serialport:2.1.3'
}

Import

import android.serialport.SerialPort;

su path

In order to read/write to a serial port in Android you'll need su binary installed on device (this can be done by rooting the device). Usually Android devices that has the ability to communicate with serial ports have su installed on the default path "/system/bin/su". To change this use:

// su默认路径为 "/system/bin/su"
// The default path of su is "/system/bin/su"
// 可通过此方法修改
// If the path is different then change it using this
SerialPort.setSuPath("/system/xbin/su");

Usage

// 默认8N1(8数据位、无校验位、1停止位)
// Default 8N1 (8 data bits, no parity bit, 1 stop bit)
SerialPort serialPort = new SerialPort(path, baudrate);

// 可选配置数据位、校验位、停止位 - 7E2(7数据位、偶校验、2停止位)
// or with builder (with optional configurations) - 7E2 (7 data bits, even parity, 2 stop bits)
SerialPort serialPort = SerialPort 
    .newBuilder(path, baudrate)
// 校验位;0:无校验位(NONE,默认);1:奇校验位(ODD);2:偶校验位(EVEN)
// Check bit; 0: no check bit (NONE, default); 1: odd check bit (ODD); 2: even check bit (EVEN)
//    .parity(2) 
// 数据位,默认8;可选值为5~8
// Data bit, default 8; optional value is 5~8
//    .dataBits(7) 
// 停止位,默认1;1:1位停止位;2:2位停止位
// Stop bit, default 1; 1:1 stop bit; 2: 2 stop bit
//    .stopBits(2) 
    .build();
    
// read/write to serial port - needs to be in different thread!
InputStream in = serialPort.getInputStream();
OutputStream out = serialPort.getOutputStream();

// close
serialPort.tryClose();

实现方式参考

Implementation reference

  1. Check sample project
  2. https://juejin.im/post/5c010a19e51d456ac27b40fc

More Repositories

1

Android-SerialPort-Tool

Android串口调试助手
Java
602
star
2

Modbus4Android

基于modbus4j的Modbus的Android实现,添加对Android串口(RTU)的支持
Java
221
star
3

SerialWorker

Android串口库的进一步封装,简化线程方面的管理。你只需要关注如何实现硬件协议。
Java
79
star
4

CommonSize

Android通用屏幕适配方案
Java
53
star
5

Custom-Glide-ModelLoader-Demo

自定义Glide ModelLoader,直接通过特定类型的数据源来加载图片
Java
49
star
6

SmallestWidthDimens

Android SmallestWidth屏幕适配方案
Java
18
star
7

AdaptScreen

屏幕适配工具,增加了适配较长/较短边功能。修改自 https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/README-CN.md#adaptscreen-%E7%9B%B8%E5%85%B3---adaptscreenutilsjava---demo
Java
16
star
8

BlurViewDemo

实现高斯模糊控件
Java
12
star
9

Android_Studio_Useful_Keymap_on_Win_and_macOS

Andorid Studio常用快捷键(Windows macOS双平台对比)
9
star
10

FindSerialPortTool

找出哪个串口能用
Kotlin
7
star
11

MessageSend

一个聊天输入框。
Java
3
star
12

Handle-IM-APP-IME-Demo

处理即时通信应用,底部“功能区”与“软键盘”的展示逻辑
Java
3
star
13

IME-Quick-Setting

状态栏增加一个快速切换输入法的开关
Java
1
star
14

Glide-Issue

Java
1
star
15

hexo-theme-lightgreen

Personal Hexo Theme
CSS
1
star
16

MyOkhttpLoggingInterceptor

自定义Okhttp日志拦截器
Kotlin
1
star
17

alfred-env-workflow

Alfred 3 Workflow——加载环境变量并运行mac应用,解决mac上直接运行app,出现找不到环境变量,找不到文件或命令的问题。
1
star
18

LiveDataExtension

基于LiveData的一些扩展类。解决LiveData数据倒灌,提供类似onSuccss、onFailure等多状态异步回调方法。
Kotlin
1
star
19

licheetec.com

老博客地址,新地址为 http://www.licheedev.com
1
star
20

licheedev.github.io

我的博客
HTML
1
star
21

RM2100-Padavan-build

Padavan 自动编译
1
star