diff --git a/app/src/main/java/com/example/bpa/MainActivity.java b/app/src/main/java/com/example/bpa/MainActivity.java index 62e8f26..60815ea 100644 --- a/app/src/main/java/com/example/bpa/MainActivity.java +++ b/app/src/main/java/com/example/bpa/MainActivity.java @@ -42,6 +42,7 @@ import com.example.bpa.helper.UpdateManager; import com.example.bpa.helper.WrapContentLinearLayoutManager; import com.example.bpa.message.MessageLooper; import com.example.bpa.message.MessageManager; +import com.example.bpa.service.DeviceData; import com.example.bpa.service.OrderServer; import com.example.bpa.service.ScanCodeServer; import com.example.bpa.view.adapter.makegood_adapter; @@ -152,7 +153,16 @@ public class MainActivity extends FragmentActivity implements View.OnClickListen private void initBusiness() { Main.getInstance().ToggleEnvironment(); //PLC数据监控 - ModbusTcpServer.get().Connect(ConfigName.getInstance().Address, ConfigName.getInstance().Post); + new Thread(new Runnable() { + @Override + public void run() { + try { + ModbusTcpServer.get().Connect(ConfigName.getInstance().Address, ConfigName.getInstance().Post); + } catch (Exception e) { + + } + } + }).start(); //MQTT数据监听 OrderServer.Get().MqttInit(); //消息中心 diff --git a/app/src/main/java/com/example/bpa/helper/ModbusTcpServer.java b/app/src/main/java/com/example/bpa/helper/ModbusTcpServer.java index 45b5eaa..f626745 100644 --- a/app/src/main/java/com/example/bpa/helper/ModbusTcpServer.java +++ b/app/src/main/java/com/example/bpa/helper/ModbusTcpServer.java @@ -133,18 +133,18 @@ public class ModbusTcpServer { */ public void Connect(String host, int port) { - int status = 1; - while (status == 1) { - try { - //status为0则代表通,为1则代表不通。 - status = Runtime.getRuntime().exec("ping " + host).waitFor(); - if (status == 1) Thread.sleep(1000); - } catch (InterruptedException e) { - MessageLog.ShowInfo("设备 " + host + " 网络验证失败"); - } catch (IOException e) { - MessageLog.ShowInfo("设备 " + host + " 网络验证失败"); - } - } +// int status = 1; +// while (status == 1) { +// try { +// //status为0则代表通,为1则代表不通。 +// status = Runtime.getRuntime().exec("ping " + host).waitFor(); +// if (status == 1) Thread.sleep(1000); +// } catch (InterruptedException e) { +// MessageLog.ShowInfo("设备 " + host + " 网络验证失败"); +// } catch (IOException e) { +// MessageLog.ShowInfo("设备 " + host + " 网络验证失败"); +// } +// } param = TcpParam.create(host, port) .setTimeout(1000)