From a6077217e25f5804027194a5c2848e773eda1abd Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期五, 21 十一月 2025 15:47:17 +0800
Subject: [PATCH] 修改
---
src/xitongshezhi/SystemDebugDialog.java | 82 +++++++++++++++++-----------------------
1 files changed, 35 insertions(+), 47 deletions(-)
diff --git a/src/xitongshezhi/SystemDebugDialog.java b/src/xitongshezhi/SystemDebugDialog.java
index 08ca52c..9b19556 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,22 @@
staticDataUpdateEnabled = dataUpdateEnabled; // 鍚屾闈欐�佸彉閲�
if (autoScroll) {
- scrollButton.setText("鏆傚仠");
+ scrollButton.setText("寮�濮�");
scrollButton.setBackground(PRIMARY_COLOR);
if (staticDataTextArea != null) {
staticDataTextArea.setCaretPosition(staticDataTextArea.getDocument().getLength());
}
appendAsciiData("[" + getCurrentTime() + "] 寮�濮嬫樉绀烘暟鎹甛n");
+ 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 +390,7 @@
dataTextArea.setText(sb.toString());
}
} catch (Exception e) {
- System.err.println("淇壀琛屾暟鏃跺彂鐢熼敊璇�: " + e.getMessage());
+ Errlog.logOperation("淇壀琛屾暟鏃跺彂鐢熼敊璇�: " + e.getMessage());
}
}
@@ -479,7 +451,7 @@
staticDataTextArea.setText(sb.toString());
}
} catch (Exception e) {
- System.err.println("淇壀琛屾暟鏃跺彂鐢熼敊璇�: " + e.getMessage());
+ Errlog.logOperation("淇壀琛屾暟鏃跺彂鐢熼敊璇�: " + e.getMessage());
}
}
@@ -511,7 +483,7 @@
}
} catch (Exception e) {
- System.err.println("鏄剧ず鏁版嵁鏃跺彂鐢熼敊璇�: " + e.getMessage());
+ Errlog.logOperation("鏄剧ず鏁版嵁鏃跺彂鐢熼敊璇�: " + e.getMessage());
}
});
}
@@ -531,14 +503,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 +588,13 @@
memoryMonitorTimer.stop();
}
- // 鍏抽棴鏃跺仠姝㈣疆璇�
- if (lunxun.isPolling()) {
- lunxun.stopPolling();
- }
+ // 閲嶈淇敼锛氫笉瑕佸仠姝㈣疆璇紝鍙殏鍋滆皟璇曡緭鍑�
+ lunxun.setDEBUG_ENABLED(false);
- // 鍋滄涓插彛鏁版嵁鎹曡幏
+ // 閲嶈淇敼锛氫笉瑕佸仠姝覆鍙f暟鎹崟鑾凤紝鍙Щ闄よ嚜宸辩殑鍥炶皟
if (serialService != null) {
- serialService.stopCapture();
+ // 浣跨敤鏂扮殑鏂规硶绉婚櫎鍥炶皟鑰屼笉鍋滄鏁翠釜鎹曡幏
+ removeDataReceivedCallback();
}
// 娓呯悊闈欐�佸紩鐢紝闃叉鍐呭瓨娉勬紡
@@ -634,4 +605,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