|
|
@@ -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()); |
|
|
|
} |
|
|
|