Skip to content

Commit

Permalink
客户端可能使用多个串口,因此不可使用单例
Browse files Browse the repository at this point in the history
  • Loading branch information
sunxudong committed Apr 26, 2020
1 parent 6c71774 commit 87a4e6e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
4 changes: 2 additions & 2 deletions serial/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
versionCode 7
versionName "1.2.3"
versionCode 8
versionName "1.2.4"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* @Date: 2020/4/26 10:34
*/
public class SafeThread {
private final static SafeThread INSTANCE = new SafeThread();

private Thread thread;
private int interval;
Expand All @@ -23,12 +22,6 @@ public class SafeThread {

private OnThreadHandleListener listener;

private SafeThread() {
}

public static SafeThread getInstance() {
return INSTANCE;
}

public void initConfig(int interval, OnThreadHandleListener listener) {
this.interval = interval;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class SerialPort implements SafeThread.OnThreadHandleListener{
private SafetyByteBuffer serialData = new SafetyByteBuffer();

private int interval;
private SafeThread safeThread;

/**
* 构建 创建客户端
Expand All @@ -56,7 +57,8 @@ public SerialPort(String path, int baudRate, int flags, int interval,
inputStream = serialPort.getInputStream();
outputStream = serialPort.getOutputStream();

SafeThread.getInstance().initConfig(interval,this);
safeThread = new SafeThread();
safeThread.initConfig(interval,this);

}

Expand Down

0 comments on commit 87a4e6e

Please sign in to comment.