Skip to content

Commit 26225ea

Browse files
committed
更新modbus4j依赖,可以配置是否打印log
1 parent 2e75b61 commit 26225ea

File tree

6 files changed

+30
-18
lines changed

6 files changed

+30
-18
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ allprojects {
2525
}
2626
2727
dependencies {
28-
implementation 'com.github.licheedev:Modbus4Android:0.21'
28+
implementation 'com.github.licheedev:Modbus4Android:0.3'
2929
}
3030
3131
```
@@ -89,6 +89,17 @@ ModbusManager.get().init(serialParam, new ModbusCallback<ModbusMaster>() {
8989
});
9090
```
9191

92+
93+
### 可选配置
94+
```java
95+
// 启用rtu的crc校验(默认就启用)
96+
ModbusConfig.setEnableRtuCrc(true);
97+
// 打印数据log(默认全禁用)
98+
// System.out: MessagingControl.send: 01030000000305cb
99+
// System.out: MessagingConnection.read: 010306000100020000bd75
100+
ModbusConfig.setEnableDataLog(true, true);
101+
```
102+
92103
### 功能码操作示例
93104
```java
94105
// 普通写法

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ dependencies {
2626
androidTestImplementation 'com.android.support.test:runner:1.0.2'
2727
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
2828

29-
// implementation project(':modbus4android')
30-
implementation 'com.github.licheedev:Modbus4Android:0.21'
29+
implementation project(':modbus4android')
30+
// implementation 'com.github.licheedev:Modbus4Android:0.21'
3131
// logplus
3232
implementation 'com.github.licheedev.SomeLibrary:myutils:0.02'
3333
// gson

app/src/main/java/com/licheedev/demo/App.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.app.Application;
44
import com.licheedev.demo.base.AdaptScreenUtils;
55
import com.licheedev.demo.base.PrefUtil;
6+
import com.serotonin.modbus4j.ModbusConfig;
67

78
public class App extends Application {
89

@@ -14,9 +15,23 @@ public void onCreate() {
1415
sInstance = this;
1516
AdaptScreenUtils.init(this);
1617
PrefUtil.init(this);
18+
19+
configModbus();
1720
}
1821

1922
public static App getInstance() {
2023
return sInstance;
2124
}
25+
26+
/**
27+
* 配置Modbus,可选
28+
*/
29+
private void configModbus() {
30+
// 启用rtu的crc校验(默认就启用)
31+
ModbusConfig.setEnableRtuCrc(true);
32+
// 打印数据log(默认全禁用)
33+
// System.out: MessagingControl.send: 01030000000305cb
34+
// System.out: MessagingConnection.read: 010306000100020000bd75
35+
ModbusConfig.setEnableDataLog(true, true);
36+
}
2237
}

modbus4android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ dependencies {
3333
// 串口
3434
api 'com.github.licheedev.Android-SerialPort-API:serialport:1.0.1'
3535
// modbus4j
36-
api 'com.github.licheedev:modbus4j:v3.0.5-alpha1'
36+
api 'com.github.licheedev:modbus4j:v3.0.6-alpha1'
3737
}
3838

3939
apply from: '../jitpack.gradle'

modbus4android/src/main/java/com/licheedev/modbus4android/AndroidSerialPortWrapper.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,6 @@ public int getBaudRate() {
8080
return mBaudRate;
8181
}
8282

83-
@Override
84-
public int getFlowControlIn() {
85-
return 0;
86-
}
87-
88-
@Override
89-
public int getFlowControlOut() {
90-
return 0;
91-
}
92-
9383
@Override
9484
public int getDataBits() {
9585
return 8; // 数据位 8

modbus4android/src/main/java/com/licheedev/modbus4android/ModbusObserver.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
import io.reactivex.Observer;
77
import io.reactivex.disposables.Disposable;
88

9-
/**
10-
* 就剩下onNext没实现的Observer
11-
*/
12-
139
public abstract class ModbusObserver<T extends ModbusResponse> implements Observer<T> {
1410
@Override
1511
public void onSubscribe(Disposable d) {

0 commit comments

Comments
 (0)