Browse Source

1

调味吧台(白底)
fyf 1 year ago
parent
commit
6258185117
2 changed files with 23 additions and 13 deletions
  1. +11
    -1
      app/src/main/java/com/example/bpa/MainActivity.java
  2. +12
    -12
      app/src/main/java/com/example/bpa/helper/ModbusTcpServer.java

+ 11
- 1
app/src/main/java/com/example/bpa/MainActivity.java View File

@@ -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();
//消息中心


+ 12
- 12
app/src/main/java/com/example/bpa/helper/ModbusTcpServer.java View File

@@ -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)


Loading…
Cancel
Save