All Projects → AIlll → Androidserialport

AIlll / Androidserialport

Licence: apache-2.0
Android Serial Port , 基本的Android 串口通信库

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Androidserialport

Cserialport
The latest modified version of Remon Spekreijse's serial port class
Stars: ✭ 64 (-35.35%)
Mutual labels:  serialport, serial-ports
Node Serialport
Access serial ports with JavaScript. Linux, OSX and Windows. Welcome your robotic JavaScript overlords. Better yet, program them!
Stars: ✭ 5,015 (+4965.66%)
Mutual labels:  serialport, serial-ports
Rubyserial
FFI Ruby library for RS-232 serial port communication
Stars: ✭ 142 (+43.43%)
Mutual labels:  serialport, serial-ports
Cserialport
基于C++的轻量级开源跨平台串口类库Lightweight cross-platform serial port library based on C++
Stars: ✭ 296 (+198.99%)
Mutual labels:  serialport, serial-ports
serial.nim
A Nim library for accessing serial ports.
Stars: ✭ 59 (-40.4%)
Mutual labels:  serial-ports, serialport
Libserial
Serial Port Programming in C++
Stars: ✭ 201 (+103.03%)
Mutual labels:  serialport, serial-ports
Common
Yet another serial port debugger.
Stars: ✭ 245 (+147.47%)
Mutual labels:  serialport, serial-ports
RxSerialPort
基于Rxjava2.x的串口通信library
Stars: ✭ 11 (-88.89%)
Mutual labels:  serial-ports, serialport
Androidserialport
Android串口通信示例
Stars: ✭ 497 (+402.02%)
Mutual labels:  serialport, serial-ports
etherport-client
Client-side virtual serial port for Etherport. Used to implement firmata-compatible boards and relays.
Stars: ✭ 20 (-79.8%)
Mutual labels:  serial-ports, serialport
serialPort
Android通用的串口通信库
Stars: ✭ 39 (-60.61%)
Mutual labels:  serial-ports, serialport
serialport
PHP Serial Port
Stars: ✭ 42 (-57.58%)
Mutual labels:  serial-ports, serialport
Ninjaterm
A serial port terminal that's got your back.
Stars: ✭ 24 (-75.76%)
Mutual labels:  serialport, serial-ports
Marlin Config
Marlin firmware instant configurator
Stars: ✭ 327 (+230.3%)
Mutual labels:  serial-ports
Node Escpos
🖨️ ESC/POS Printer driver for node
Stars: ✭ 752 (+659.6%)
Mutual labels:  serialport
Node Modbus
Modbus TCP Client/Server implementation for Node.JS
Stars: ✭ 313 (+216.16%)
Mutual labels:  serial-ports
Android Serialport Api
Fork自Google开源的Android串口通信Demo,修改成Android Studio项目
Stars: ✭ 715 (+622.22%)
Mutual labels:  serialport
Blynk Library
Blynk library for embedded hardware. Works with Arduino, ESP8266, Raspberry Pi, Intel Edison/Galileo, LinkIt ONE, Particle Core/Photon, Energia, ARM mbed, etc.
Stars: ✭ 3,305 (+3238.38%)
Mutual labels:  serialport
pyrealtime
Realtime data processing and plotting pipelines in Python
Stars: ✭ 62 (-37.37%)
Mutual labels:  serialport
Sers
Serial port access for the Go programming language.
Stars: ✭ 30 (-69.7%)
Mutual labels:  serial-ports

AndroidSerialPort

Android 串口通信,基于谷歌官方android-serialport-api编译

download

使用说明

  1. 在Module下的 build.gradle 中添加
implementation 'com.aill:AndroidSerialPort:1.0.8'
  1. 打开串口
/**
 * @param 1 串口路径,根据你的设备不同,路径也不同
 * @param 2 波特率
 * @param 3 flags 给0就好
 */
SerialPort serialPort = new SerialPort(new File("/dev/ttyS1"), 9600, 0);
  1. 往串口中写入数据
//从串口对象中获取输出流
OutputStream outputStream = serialPort.getOutputStream();
//需要写入的数据
byte[] data = new byte[x];
data[0] = ...;
data[1] = ...;
data[x] = ...;
//写入数据
outputStream.write(data);
outputStream.flush();
  1. 读取串口数据

读取数据时很可能会遇到分包的情况,即不能一次性读取正确的完整的数据

解决办法:可以在读取到数据时,让读取数据的线程sleep一段时间,等待数据全部接收完,再一次性读取出来。这样应该可以避免大部分的分包情况

//从串口对象中获取输入流
InputStream inputStream = serialPort.getInputStream();
//使用循环读取数据,建议放到子线程去
while (true) {
    if (inputStream.available() > 0) {
        //当接收到数据时,sleep 500毫秒(sleep时间自己把握)
        Thread.sleep(500);
        //sleep过后,再读取数据,基本上都是完整的数据
        byte[] buffer = new byte[inputStream.available()];
        int size = inputStream.read(buffer);
    }
}

只接收一条数据的情况下,以上方法可以应对数据分包,数据量多的情况下需要考虑是否会因为sleep导致接收多条数据,可以根据通信协议核对包头包尾等参数。

  1. 修改设备su路径

打开串口时,会检测读写权限,当没有权限时,会尝试对其进行提权

//默认su路径是/system/bin/su,有些设备su路径是/system/xbin/su
//在new SerialPort();之前设置su路径
SerialPort.setSuPath("/system/xbin/su");

  • ByteUtil类:工具类,字符串转字节数组,字节数组转字符串
  • SerialFinder类:用于查找设备下所有串口路径
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].