From 100f4dcea20a32663a07e91525de111f7515eb79 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期五, 21 十一月 2025 17:25:53 +0800
Subject: [PATCH] 可发布版本202517.25

---
 src/xitongshezhi/SystemDebugDialog.java |   83 ++++++++++++++++++-----------------------
 1 files changed, 36 insertions(+), 47 deletions(-)

diff --git a/src/xitongshezhi/SystemDebugDialog.java b/src/xitongshezhi/SystemDebugDialog.java
index 08ca52c..532bc17 100644
--- a/src/xitongshezhi/SystemDebugDialog.java
+++ b/src/xitongshezhi/SystemDebugDialog.java
@@ -10,6 +10,7 @@
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import chushihua.lunxun;
+import dialog.Errlog;
 
 public class SystemDebugDialog extends JDialog {
     private static final long serialVersionUID = -9131186661220052051L;
@@ -25,11 +26,9 @@
     private static final Color WARNING_COLOR = new Color(243, 156, 18);
     private static final Color DARK_COLOR = new Color(15, 28, 48);
     private static final Color TEXT_COLOR = new Color(224, 224, 224);
-    
-    // UI缁勪欢
+ // UI缁勪欢
     private JTextArea dataTextArea;
     private JButton clearButton;
-    private JButton pollingButton;
     private JButton scrollButton;
     private JTextField sendTextField;
     private JButton sendButton;
@@ -43,7 +42,7 @@
     private SerialPortService serialService;
     
     // 鎺у埗鍙橀噺
-    private boolean autoScroll = true; // 榛樿鑷姩婊氬姩
+    private boolean autoScroll =false; // 榛樿鑷姩婊氬姩
     private static boolean dataUpdateEnabled = true; // 鎺у埗鏁版嵁鏇存柊
     
     // 鏃ユ湡鏍煎紡鍖�
@@ -214,14 +213,6 @@
         scrollButton.setBorder(BorderFactory.createEmptyBorder(8, 20, 8, 20));
         scrollButton.addActionListener(e -> toggleAutoScroll());
         
-        // 鍚姩/鍏抽棴鏌ヨ鎸夐挳
-        pollingButton = new JButton("鍚姩鏌ヨ");
-        pollingButton.setFont(new Font("Microsoft YaHei", Font.BOLD, 14));
-        pollingButton.setBackground(SECONDARY_COLOR);
-        pollingButton.setForeground(Color.WHITE);
-        pollingButton.setFocusPainted(false);
-        pollingButton.setBorder(BorderFactory.createEmptyBorder(8, 20, 8, 20));
-        pollingButton.addActionListener(e -> togglePolling());
         
         // 娓呯┖鎸夐挳
         clearButton = new JButton("娓呯┖鏁版嵁");
@@ -233,7 +224,6 @@
         clearButton.addActionListener(e -> clearData());
         
         buttonPanel.add(scrollButton);
-        buttonPanel.add(pollingButton);
         buttonPanel.add(clearButton);
         
         return buttonPanel;
@@ -331,40 +321,23 @@
         staticDataUpdateEnabled = dataUpdateEnabled; // 鍚屾闈欐�佸彉閲�
 
         if (autoScroll) {
-            scrollButton.setText("鏆傚仠");
+            scrollButton.setText("寮�濮�");
             scrollButton.setBackground(PRIMARY_COLOR);
             if (staticDataTextArea != null) {
                 staticDataTextArea.setCaretPosition(staticDataTextArea.getDocument().getLength());
             }
             appendAsciiData("[" + getCurrentTime() + "] 寮�濮嬫樉绀烘暟鎹甛n");
+            lunxun.resumePolling();
+            lunxun.DEBUG_ENABLED=true;
         } else {
-            scrollButton.setText("寮�濮�");
+            scrollButton.setText("鏆傚仠");
             scrollButton.setBackground(WARNING_COLOR);
             appendAsciiData("[" + getCurrentTime() + "] 鏆傚仠鏄剧ず鏁版嵁\n");
         }
     }
     
-    private void togglePolling() {
-        if (lunxun.isPolling()) {
-            // 濡傛灉姝e湪杞锛屽垯鍋滄
-            if (lunxun.stopPolling()) {
-                pollingButton.setText("鍚姩鏌ヨ");
-                pollingButton.setBackground(SECONDARY_COLOR);
-                onDataReceivedascii("[" + getCurrentTime() + "] stop\n");
-                lunxun.setDEBUG_ENABLED(false);
-            }
-        } else {
-            // 濡傛灉鏈疆璇紝鍒欏惎鍔�
-            if (lunxun.startPolling()) {
-            	lunxun.setDEBUG_ENABLED(true);
-                pollingButton.setText("鍋滄鏌ヨ");
-                pollingButton.setBackground(DANGER_COLOR);
-                onDataReceivedascii("[" + getCurrentTime() + "] strat\n");
-            } else {
-                showMessage("閿欒", "鏃犳硶鍚姩杞鏌ヨ锛岃妫�鏌ヤ覆鍙h繛鎺�", "error");
-            }
-        }
-    }
+   
+
     
     private void sendData() {
         String text = sendTextField.getText().trim();
@@ -418,7 +391,7 @@
                 dataTextArea.setText(sb.toString());
             }
         } catch (Exception e) {
-            System.err.println("淇壀琛屾暟鏃跺彂鐢熼敊璇�: " + e.getMessage());
+            Errlog.logOperation("淇壀琛屾暟鏃跺彂鐢熼敊璇�: " + e.getMessage());
         }
     }
     
@@ -479,7 +452,7 @@
                 staticDataTextArea.setText(sb.toString());
             }
         } catch (Exception e) {
-            System.err.println("淇壀琛屾暟鏃跺彂鐢熼敊璇�: " + e.getMessage());
+            Errlog.logOperation("淇壀琛屾暟鏃跺彂鐢熼敊璇�: " + e.getMessage());
         }
     }
 
@@ -511,7 +484,7 @@
                 }
 
             } catch (Exception e) {
-                System.err.println("鏄剧ず鏁版嵁鏃跺彂鐢熼敊璇�: " + e.getMessage());
+                Errlog.logOperation("鏄剧ず鏁版嵁鏃跺彂鐢熼敊璇�: " + e.getMessage());
             }
         });
     }
@@ -531,14 +504,14 @@
                     displayText = displayText.substring(0, MAX_LINE_LENGTH) + "...";
                 }
 
-                staticDataTextArea.append(displayText);
+                staticDataTextArea.append(displayText+"\n");
 
                 if (staticDataUpdateEnabled) {
                     staticDataTextArea.setCaretPosition(staticDataTextArea.getDocument().getLength());
                 }
 
             } catch (Exception e) {
-                System.err.println("鏄剧ずASCII鏁版嵁鏃跺彂鐢熼敊璇�: " + e.getMessage());
+                Errlog.logOperation("鏄剧ずASCII鏁版嵁鏃跺彂鐢熼敊璇�: " + e.getMessage());
             }
         });
     }
@@ -616,14 +589,13 @@
             memoryMonitorTimer.stop();
         }
         
-        // 鍏抽棴鏃跺仠姝㈣疆璇�
-        if (lunxun.isPolling()) {
-            lunxun.stopPolling();
-        }
+        // 閲嶈淇敼锛氫笉瑕佸仠姝㈣疆璇紝鍙殏鍋滆皟璇曡緭鍑�
+        lunxun.setDEBUG_ENABLED(false);
         
-        // 鍋滄涓插彛鏁版嵁鎹曡幏
+        // 閲嶈淇敼锛氫笉瑕佸仠姝覆鍙f暟鎹崟鑾凤紝鍙Щ闄よ嚜宸辩殑鍥炶皟
         if (serialService != null) {
-            serialService.stopCapture();
+            // 浣跨敤鏂扮殑鏂规硶绉婚櫎鍥炶皟鑰屼笉鍋滄鏁翠釜鎹曡幏
+            removeDataReceivedCallback();
         }
         
         // 娓呯悊闈欐�佸紩鐢紝闃叉鍐呭瓨娉勬紡
@@ -634,4 +606,21 @@
         
         super.dispose();
     }
+
+    // 鏂板锛氱Щ闄ゆ暟鎹帴鏀跺洖璋冪殑鏂规硶
+    private void removeDataReceivedCallback() {
+        if (serialService != null) {
+            try {
+                // 閫氳繃鍙嶅皠鎴栧叾浠栨柟寮忕Щ闄ゅ洖璋冿紝鎴栬�呯畝鍗曞湴璁剧疆涓簄ull
+                // 杩欓噷鍋囪SerialPortService鏈夌Щ闄ゅ洖璋冪殑鏂规硶
+                serialService.setResponseConsumer(null);
+            } catch (Exception e) {
+                Errlog.logOperation("绉婚櫎鏁版嵁鎺ユ敹鍥炶皟鏃跺彂鐢熼敊璇�: " + e.getMessage());
+            }
+        }
+    }
+
+    // 鏂板锛氬惎鐢�/绂佺敤杞鎺у埗鐨勬柟娉�
+    public static void setPollingControlEnabled(boolean enabled) {
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3