Coder Social home page Coder Social logo

androlua / android-serialport Goto Github PK

View Code? Open in Web Editor NEW

This project forked from geekbugs/android-serialport

0.0 1.0 0.0 153 KB

Android SerialPort Lib(Android平台上的串口调试库,支持串口号、波特率、数据位、校验位、停止位、流控等设置)

Home Page: https://code.google.com/archive/p/android-serialport-api/

Java 69.14% CMake 4.16% C 26.70%

android-serialport's Introduction

Android-SerialPort

此项目移植于谷歌官方串口库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 {
        implementation 'com.github.F1ReKing:Android-SerialPort:1.1'
}

使用

1. 查询串口列表

SerialPortFinder#getDrivers();

2. 配置串口参数

SerialPortHelper#Builder(String port, int baudRate).build(); //支持配置串口号,波特率(默认值115200)
setStopBits(int stopBits); // 支持设置停止位 默认值为2
setDataBits(int dataBits); // 支持设置数据位 默认值为8
setParity(int parity); // 支持设置检验位 默认值为0
setFlowCon(int flowCon); // 支持设置流控 默认值为0
setFlags(int flags); // 支持设置标志 默认值为0,O_RDWR  读写方式打开

3. 打开串口

SerialPortHelper#open();

4. 关闭串口

SerialPortHelper#close();

4. 发送数据

SerialPortHelper#sendBytes(byte[] bytes); // 支持发送byte[]
SerialPortHelper#sendHex(String hex); // 支持发送Hex
SerialPortHelper#sendTxt(String txt); // 支持发送ASCII码

5. 接收数据

public interface ISerialPortDataListener {
	// 接收数据回调
    void onDataReceived(byte[] bytes);
   	// 发送数据回调
    void onDataSend(byte[] bytes);
}

6. 回调

//  串口打开状态监听
void setIOpenSerialPortListener(IOpenSerialPortListener IOpenSerialPortListener);

// 串口消息监听
void setISerialPortDataListener(ISerialPortDataListener ISerialPortDataListener);

版本更新记录

1.1

  • 优化api
  • 支持设置可选参数,并配置默认值

1.0

  • 基础功能、支持设置串口号、波特率、数据位、校验位、停止位、流控等配置
  • 支持发送、接收数据

android-serialport's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.