android+ubs+串口调试,GitHub - dmdaguan/Android-SerialPort: 『Android Lib』 Android平台上的usb串口调试库,支持串口号、波特率、数...

Android-SerialPort

此项目移植于谷歌官方串口库android-serialport-api,但该项目仅支持串口名称及波特率,所以在项目的基础上添加支持数据位、数据位、停止位、流控等配置。

68747470733a2f2f6a69747061636b2e696f2f762f463152654b696e672f416e64726f69642d53657269616c506f72742e737667

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d417061636865253230322e302d626c75652e737667

下载

b689418020732e1cc707e72e0cde59a1.png

format,png

引入

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.5.1'

}

使用

1. 查询串口列表

SerialPortHelper#getAllDevices();

// 查询串口设备地址列表

SerialPortHelper#getAllDeicesPath();

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

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

支持发送、接收数据

License

Copyright 2019 F1ReKing.

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

Stargazers over time

68747470733a2f2f7374617263686172742e63632f463152654b696e672f416e64726f69642d53657269616c506f72742e737667

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值