liuwei před 14 hodinami
rodič
revize
df4dc069cf
1 změnil soubory, kde provedl 6 přidání a 42 odebrání
  1. 6 42
      src/com/mes/plc/QmPlcMonitorPanel.java

+ 6 - 42
src/com/mes/plc/QmPlcMonitorPanel.java

@@ -14,7 +14,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 public class QmPlcMonitorPanel extends JPanel {
 
     private final JLabel statusLabel = new JLabel("未连接");
-    private final JTextField hostField = new JTextField(16);
+    private final JLabel hostLabel = new JLabel("-");
     private final JLabel dbLabel = new JLabel("-");
 
     private final PointRow inflationTime = new PointRow("框架充气时间", "Real");
@@ -42,12 +42,7 @@ public class QmPlcMonitorPanel extends JPanel {
         JPanel top = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 8));
         JLabel ipTitle = new JLabel("PLC IP:");
         ipTitle.setFont(new Font("微软雅黑", Font.PLAIN, 18));
-        hostField.setFont(new Font("Consolas", Font.PLAIN, 18));
-        hostField.setPreferredSize(new Dimension(180, 32));
-
-        JButton saveIpBtn = new JButton("保存IP");
-        saveIpBtn.setFont(new Font("微软雅黑", Font.PLAIN, 16));
-        saveIpBtn.addActionListener(e -> saveIp());
+        hostLabel.setFont(new Font("Consolas", Font.PLAIN, 18));
 
         JButton refreshBtn = new JButton("立即刷新");
         refreshBtn.setFont(new Font("微软雅黑", Font.PLAIN, 16));
@@ -57,8 +52,7 @@ public class QmPlcMonitorPanel extends JPanel {
         dbLabel.setFont(new Font("Consolas", Font.PLAIN, 16));
 
         top.add(ipTitle);
-        top.add(hostField);
-        top.add(saveIpBtn);
+        top.add(hostLabel);
         top.add(refreshBtn);
         top.add(dbLabel);
         top.add(statusLabel);
@@ -105,7 +99,7 @@ public class QmPlcMonitorPanel extends JPanel {
 
     private void loadUiFromConfig() {
         config = QmPlcConfig.load();
-        hostField.setText(config.host);
+        hostLabel.setText(config.host == null || config.host.isEmpty() ? "-" : config.host);
         dbLabel.setText("DB" + config.db);
         inflationTime.setAddr(String.format("DB%d.DBD%d", config.db, config.inflationTimeOffset));
         holdTime.setAddr(String.format("DB%d.DBD%d", config.db, config.holdTimeOffset));
@@ -120,37 +114,13 @@ public class QmPlcMonitorPanel extends JPanel {
         scanFeedback.setAddr(String.format("DB%d.DBX%d.%d", config.db, config.scanFeedbackByte, config.scanFeedbackBit));
     }
 
-    private void saveIp() {
-        String ip = hostField.getText() == null ? "" : hostField.getText().trim();
-        if (ip.isEmpty()) {
-            JOptionPane.showMessageDialog(this, "请输入 PLC IP", "提示", JOptionPane.WARNING_MESSAGE);
-            return;
-        }
-        boolean ok = QmPlcConfig.saveHost(ip);
-        if (config != null) {
-            config.host = ip;
-        }
-        if (s7Client != null) {
-            s7Client.updateHost(ip);
-        }
-        QmPlcPoller.reloadHost(ip);
-        if (ok) {
-            statusLabel.setForeground(new Color(0, 128, 0));
-            statusLabel.setText("IP已保存: " + ip);
-        } else {
-            statusLabel.setForeground(Color.ORANGE.darker());
-            statusLabel.setText("IP已用于当前连接,但写配置文件失败");
-        }
-        refreshOnce();
-    }
-
     public void startMonitor() {
         active = true;
         loadUiFromConfig();
         if (s7Client == null) {
             s7Client = new QmS7Client(config);
-        } else {
-            s7Client.updateHost(hostField.getText().trim());
+        } else if (config != null && config.host != null) {
+            s7Client.updateHost(config.host);
         }
         if (timer != null) {
             timer.cancel();
@@ -187,14 +157,8 @@ public class QmPlcMonitorPanel extends JPanel {
             if (config == null) {
                 config = QmPlcConfig.load();
             }
-            String ip = hostField.getText() == null ? "" : hostField.getText().trim();
-            if (!ip.isEmpty()) {
-                config.host = ip;
-            }
             if (s7Client == null) {
                 s7Client = new QmS7Client(config);
-            } else {
-                s7Client.updateHost(config.host);
             }
 
             final Snapshot s = new Snapshot();