Zurück zum Ranking

licheedev/Android-SerialPort-API

Javacode.google.com/archive/p/android-serialport-api/

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

androidserialport
Sterne-Wachstum
Sterne
1.5k
Forks
415
Wochenwachstum
Issues
26
5001k
Juni 2017Juni 2020Juli 2023Juli 2026
ArtefakteMavengit clone https://github.com/licheedev/Android-SerialPort-API.git
README

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 {
        // 传统4KB内存页面版本
        implementation 'com.licheedev:android-serialport:2.1.4'
        // 适配16KB页面版本,https://developer.android.google.cn/guide/practices/page-sizes?hl=zh-cn
        implementation 'com.licheedev:android-serialport:2.1.5'
}

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
Ähnliche Repositories
flutter/flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond

DartBSD 3-Clause "New" or "Revised" Licensemobileandroid
flutter.dev
177.9k30.7k
Genymobile/scrcpy

Display and control your Android device

CApache License 2.0androidc
146.1k13.5k
react/react-native

A framework for building native applications using React

C++MIT Licenseandroidapp-framework
reactnative.dev
126.2k25.2k
facebook/react-native

A framework for building native applications using React

C++MIT Licenseandroidapp-framework
reactnative.dev
120.9k24.5k
rustdesk/rustdesk

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

Rustcrates.ioGNU Affero General Public License v3.0remote-controlremote-desktop
rustdesk.com
118.6k18.1k
justjavac/free-programming-books-zh_CN

:books: 免费的计算机编程类中文书籍,欢迎投稿

GNU General Public License v3.0pythonjavascript
weibo.com/justjavac
117.7k28.2k
Hack-with-Github/Awesome-Hacking

A collection of various awesome lists for hackers, pentesters and security researchers

Creative Commons Zero v1.0 Universalhackingsecurity
116.6k10.5k
tldr-pages/tldr

Collaborative cheatsheets for console commands 📚.

MarkdownOthershellman-page
tldr.sh
63.2k5.3k
Solido/awesome-flutter

An awesome list that curates the best Flutter libraries, tools, tutorials, articles and more.

Dartflutterawesome-list
60.7k6.9k
2dust/v2rayNG

A V2Ray client for Android, support Xray core and v2fly core

KotlinGNU General Public License v3.0androidproxy
v2rayng.2dust.link
59.9k7.8k
termux/termux-app

Termux - a terminal emulator application for Android OS extendible by variety of packages.

JavaMavenOtherandroidterminal
f-droid.org/en/packages/com.termux
57.9k7k
wasabeef/awesome-android-ui

A curated list of awesome Android UI/UX libraries

MIT Licenseandroidawesome
56.9k10.3k