瀏覽代碼

现场改动12

调味吧台(白底)
fyf 1 年之前
父節點
當前提交
5778d4d3d2
共有 2 個文件被更改,包括 12 次插入13 次删除
  1. +1
    -1
      app/src/main/java/com/example/bpa/MainActivity.java
  2. +11
    -12
      app/src/main/java/com/example/bpa/helper/ModbusTcpServer.java

+ 1
- 1
app/src/main/java/com/example/bpa/MainActivity.java 查看文件

@@ -163,7 +163,7 @@ public class MainActivity extends FragmentActivity implements View.OnClickListen
}
}
}).start();
//ModbusTcpServer.get().ReconnectModbus();
ModbusTcpServer.get().ReconnectModbus();
//MQTT数据监听
OrderServer.Get().MqttInit();
//消息中心


+ 11
- 12
app/src/main/java/com/example/bpa/helper/ModbusTcpServer.java 查看文件

@@ -4,6 +4,7 @@ package com.example.bpa.helper;
import android.util.Log;

import com.example.bpa.Model.IReadCallBack;
import com.example.bpa.Model.IThread;
import com.example.bpa.Model.IWriteCallBack;
import com.example.bpa.config.ConfigName;
import com.example.bpa.service.BusinessServer;
@@ -252,25 +253,23 @@ public class ModbusTcpServer {
{
try {

//断线重新连接
// 必须开启新的线程执行
new Thread(new Runnable() {
ThreadManager.Get().StartLong("PLC断线重连线程", true, new IThread() {
@Override
public void run() {
public void Run() throws InterruptedException {
try {
while (true)
{
ModbusMaster master= ModbusTcpHelper.get().getModbusMaster();
if (master==null || master.isConnected() == false) {
ConnectPLC();
}
Thread.sleep(20000);
ModbusMaster master= ModbusTcpHelper.get().getModbusMaster();
if (master==null || master.isConnected() == false) {
ConnectPLC();
}
Thread.sleep(20000);
} catch (Exception e) {
Log.i("PLC", "PLC重连接失败!"+e.getMessage());
}
}
}).start();
@Override
public void RunComplete() throws InterruptedException {
}
});
}catch (Exception e) {
MessageLog.ShowInfo("重新连接Modbus异常," +e.getMessage());
}


Loading…
取消
儲存