Skip to content

laose307/SerialPortUtil-master

Folders and files

NameName
Last commit message
Last commit date

Latest commit

8f9d095 · Feb 24, 2021

History

9 Commits
Feb 24, 2021
Feb 24, 2021
Jul 17, 2020
Feb 24, 2021
Jul 22, 2020
Jul 17, 2020
Jul 17, 2020
Jul 17, 2020
Jul 17, 2020
Jul 17, 2020
Jul 18, 2020
Jul 17, 2020

Repository files navigation

Android串口通信简单封装,可以用于和连接串口的硬件通信或者进行硬件调试

集成方法:

//Add the dependency
dependencies {
	         implementation 'com.laose:serialport:0.0.4'
	}

调用方法

读取文件权限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

获取所有串口地址

String[] devicesPath = new SerialPortFinder().getDevicesPaths();

打开串口,设置读取返回数据超时时间

    serialPortService = new SerialPortBuilder()
                            .setTimeOut(0L)
                            .setShakeFliter(false)
                            .setBaudrate(baud)
                            .setDevicePath(tty)
                            .setSerialPortListening(new SerialPortListening() {
                                @Override
                                public void onReceiveData(byte[] receiveData) {

                                    }
                                }
                            }).createService();
                    serialPortService.isOutputLog(true);

发送指令

//发送byte数组数据
serialPortService.sendData(new byte[2]);

//发送16进制的字符串
 serialPortService.sendDataHex("55AA0101010002");


//发送ascll的字符串
 serialPortService.sendDataAscll("");


打开或者关闭日志,默认关闭
```java
serialPortService.isOutputLog(true);

//关闭串口

serialPortService.close();

About

android串口交互demo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages