Skip to content

Commit e49e45c

Browse files
authored
Merge pull request #33 from eyalyoli/master
translate to english
2 parents f66b632 + 1bf8950 commit e49e45c

File tree

1 file changed

+47
-14
lines changed

1 file changed

+47
-14
lines changed

README.md

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,71 @@
11
# Android-SerialPort-API
2+
[Fork](https://code.google.com/archive/p/android-serialport-api/)自Google开源的Android串口通信Demo,修改成Android Studio项目
23

3-
**Gradle 引用**
4+
This lib is a [fork](https://code.google.com/archive/p/android-serialport-api/) of the Android serial port communication Demo open sourced by Google.
45

5-
添加依赖
6+
## Installation & Usage
7+
**Gradle**
8+
9+
添加依赖:
10+
11+
Add the dependency:
612

713
```
814
dependencies {
915
implementation 'com.licheedev:android-serialport:2.1.2'
1016
}
1117
```
1218

13-
**修改`su`路径**
19+
**Import**
20+
21+
```java
22+
import android.serialport.SerialPort;
23+
```
24+
25+
**`su` path**
26+
27+
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:
1428

1529
```java
1630
// su默认路径为 "/system/bin/su"
31+
// The default path of su is "/system/bin/su"
1732
// 可通过此方法修改
33+
// If the path is different then change it using this
1834
SerialPort.setSuPath("/system/xbin/su");
1935
```
2036

21-
**可选配置数据位、校验位、停止位**
22-
23-
实现方式参考
24-
> https://juejin.im/post/5c010a19e51d456ac27b40fc
37+
**Usage**
2538

2639
```java
27-
2840
// 默认8N1(8数据位、无校验位、1停止位)
41+
// Default 8N1 (8 data bits, no parity bit, 1 stop bit)
2942
SerialPort serialPort = new SerialPort(path, baudrate);
3043

31-
// 7E2(7数据位、偶校验、2停止位)
32-
SerialPort serialPort = SerialPort //
33-
.newBuilder(path, baudrate) // 串口地址地址,波特率
34-
.parity(2) // 校验位;0:无校验位(NONE,默认);1:奇校验位(ODD);2:偶校验位(EVEN)
35-
.dataBits(7) // 数据位,默认8;可选值为5~8
36-
.stopBits(2) // 停止位,默认1;1:1位停止位;2:2位停止位
44+
// 可选配置数据位、校验位、停止位 - 7E2(7数据位、偶校验、2停止位)
45+
// or with builder (with optional configurations) - 7E2 (7 data bits, even parity, 2 stop bits)
46+
SerialPort serialPort = SerialPort
47+
.newBuilder(path, baudrate)
48+
// 校验位;0:无校验位(NONE,默认);1:奇校验位(ODD);2:偶校验位(EVEN)
49+
// Check bit; 0: no check bit (NONE, default); 1: odd check bit (ODD); 2: even check bit (EVEN)
50+
// .parity(2)
51+
// 数据位,默认8;可选值为5~8
52+
// Data bit, default 8; optional value is 5~8
53+
// .dataBits(7)
54+
// 停止位,默认1;1:1位停止位;2:2位停止位
55+
// Stop bit, default 1; 1:1 stop bit; 2: 2 stop bit
56+
// .stopBits(2)
3757
.build();
58+
59+
// read/write to serial port - needs to be in different thread!
60+
InputStream in = serialPort.getInputStream();
61+
OutputStream out = serialPort.getOutputStream();
62+
63+
// close
64+
serialPort.tryClose();
3865
```
66+
67+
实现方式参考
68+
69+
Implementation reference
70+
1. Check [sample project](https://github.com/licheedev/Android-SerialPort-API/tree/master/sample)
71+
2. https://juejin.im/post/5c010a19e51d456ac27b40fc

0 commit comments

Comments
 (0)