From a6077217e25f5804027194a5c2848e773eda1abd Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期五, 21 十一月 2025 15:47:17 +0800
Subject: [PATCH] 修改

---
 src/home/CardMachineUI.java |   85 ++++++++++++++++++++++++++++++++----------
 1 files changed, 65 insertions(+), 20 deletions(-)

diff --git a/src/home/CardMachineUI.java b/src/home/CardMachineUI.java
index 291cd45..caa3f4a 100644
--- a/src/home/CardMachineUI.java
+++ b/src/home/CardMachineUI.java
@@ -13,7 +13,6 @@
 import xitongshezhi.AdminLoginDialog;
 import xitongshezhi.CardPickupDialog;
 import xitongshezhi.ConfigSet;
-import xitongshezhi.Fkj;
 import chuankou.SerialPortService;
 import chuankou.Sendmsg;
 
@@ -77,9 +76,12 @@
 	private JPanel commFaultPanel;
 
 	public CardMachineUI() {
-	    try {
+		try {
 	        // 鍏堝垵濮嬪寲绯荤粺閰嶇疆鍜岀粍浠�
 	        initializeSystem();
+	        
+	        // 鍒濆鍖栦覆鍙hВ鏋愬櫒
+	        initializeSerialParser();
 	        
 	        // 鐒跺悗鍒濆鍖朥I
 	        initializeUI();
@@ -87,7 +89,7 @@
 	        startUIUpdates(); // UI鍒锋柊瀹氭椂鍣�
 	        startSerialStatusMonitoring(); // 涓插彛鐘舵�佺洃鎺�        
 	        
-	        System.out.println("涓荤晫闈㈠垵濮嬪寲瀹屾垚");
+	        //System.out.println("涓荤晫闈㈠垵濮嬪寲瀹屾垚");
 	    } catch (Exception e) {
 	        e.printStackTrace();
 	        JOptionPane.showMessageDialog(null, 
@@ -110,7 +112,8 @@
 			if (serialConnected && lunxun.isPolling() && lunxun.isPaused()) {
 				// 鍙湁鍦ㄤ笉鍦ㄨ缃〉闈㈡椂鎵嶈嚜鍔ㄦ仮澶�
 				if (!isInConfigPage()) {
-					lunxun.resumePolling();
+//					lunxun.resumePolling();
+//					System.out.println("灏濊瘯鑷姩鍚姩杞鍔熻兘");
 				}
 			}
 		});
@@ -133,7 +136,7 @@
         try {
             // 鍒濆鍖栧崱妲界鐞嗗櫒 - 蹇呴』棣栧厛鎵ц
             slotManager = new SlotManager();
-            System.out.println("鍗℃Ы绠$悊鍣ㄥ垵濮嬪寲瀹屾垚");
+            //System.out.println("鍗℃Ы绠$悊鍣ㄥ垵濮嬪寲瀹屾垚");
 
             // 鐩存帴浣跨敤宸茬粡鍒濆鍖栫殑閰嶇疆绯荤粺
             Chushihua configSystem = Chushihua.getInstance();
@@ -156,9 +159,9 @@
                 PICKUP_PASSWORD = configSystem.getMachineConfig().getFetchCardPassword();
             }
 
-            System.out.println("绯荤粺閰嶇疆鍒濆鍖栧畬鎴�");
-            System.out.println("绠$悊鍛樺瘑鐮侀暱搴�: " + (ADMIN_PASSWORD != null ? ADMIN_PASSWORD.length() : "null"));
-            System.out.println("鍙栧崱瀵嗙爜闀垮害: " + (PICKUP_PASSWORD != null ? PICKUP_PASSWORD.length() : "null"));
+            //System.out.println("绯荤粺閰嶇疆鍒濆鍖栧畬鎴�");
+            //System.out.println("绠$悊鍛樺瘑鐮侀暱搴�: " + (ADMIN_PASSWORD != null ? ADMIN_PASSWORD.length() : "null"));
+            //System.out.println("鍙栧崱瀵嗙爜闀垮害: " + (PICKUP_PASSWORD != null ? PICKUP_PASSWORD.length() : "null"));
 
         } catch (Exception e) {
             System.err.println("绯荤粺鍒濆鍖栧紓甯�: " + e.getMessage());
@@ -171,7 +174,7 @@
     }
 
 	private void initializeUI() {
-		setTitle("UWB浜哄憳瀹氫綅鍗″彂鍗℃満绠$悊绯荤粺");
+		setTitle("鏅鸿兘浜鸿劯鍙戝崱鏈虹鐞嗙郴缁�");
 		setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
 		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 		setLocationRelativeTo(null);
@@ -288,8 +291,9 @@
 	    refreshBtn.addActionListener(e -> {
 	        updateCardSlotsDisplay();
 	        updateStatistics();
+	        lunxun.resumePolling();
 	        JOptionPane.showMessageDialog(CardMachineUI.this, 
-	                "鎵嬪姩鍒锋柊瀹屾垚锛屽叡鍒锋柊 " + TOTAL_SLOTS + " 涓崱妲�", 
+	                "鎵嬪姩鍒锋柊瀹屾垚锛屽惎鍔ㄨ疆璇紝鍏卞埛鏂� " + TOTAL_SLOTS + " 涓崱妲�", 
 	                "鍒锋柊瀹屾垚", JOptionPane.INFORMATION_MESSAGE);
 	    });
 
@@ -504,7 +508,7 @@
 	    cardSlotsPanel.revalidate();
 	    cardSlotsPanel.repaint();
 	    
-//	    System.out.println("鍗℃Ы鏄剧ず鏇存柊瀹屾垚: " + updatedSlots + " 涓垚鍔�, " + errorSlots + " 涓け璐�");
+//	    //System.out.println("鍗℃Ы鏄剧ず鏇存柊瀹屾垚: " + updatedSlots + " 涓垚鍔�, " + errorSlots + " 涓け璐�");
 	}
 
 	private Color brighterColor(Color color) {
@@ -585,8 +589,9 @@
 	    boolean pickupSuccess = CardPickupDialog.showCardPickup(this, slotId, status);
 	    
 	    if (pickupSuccess) {
-	        // 鍙栧崱鎴愬姛锛岀晫闈㈠凡缁忓湪瀵硅瘽妗嗕腑鏇存柊锛岃繖閲屼笉闇�瑕侀澶栨搷浣�
-	        System.out.println("鍗℃Ы " + slotId + " 鍙栧崱鎴愬姛");
+	        // 鍙栧崱鎴愬姛锛岃皟鐢╟hanggehaska鏂规硶鏀瑰彉鍗℃Ы灞炴��
+	        SlotManager.changgehaska(slotId,1); // "1"琛ㄧず绠$悊鍛樻搷浣�
+	        //System.out.println("鍗℃Ы " + slotId + " 鍙栧崱鎴愬姛锛屽凡鏇存柊鍗℃Ы鐘舵��");
 	    }
 	}
 	
@@ -604,7 +609,7 @@
 		// 鍋滄杞鏌ヨ
 		if (lunxun.isPolling()) {
 			lunxun.stopPolling();
-			System.out.println("搴旂敤绋嬪簭鍏抽棴锛岃疆璇㈡煡璇㈠凡鍋滄");
+			//System.out.println("搴旂敤绋嬪簭鍏抽棴锛岃疆璇㈡煡璇㈠凡鍋滄");
 		}
 		
 		// 鍋滄涓插彛鍗忚瑙f瀽鍣紙鏂板锛�
@@ -784,7 +789,7 @@
 	        if (lunxun.checkSerialConnection()) {
 	            boolean resumed = lunxun.setPollingPaused(false);
 	            if (resumed) {
-	                System.out.println("鍒囨崲鍒颁富椤甸潰锛岃疆璇㈡煡璇㈠凡鎭㈠");
+	                //System.out.println("鍒囨崲鍒颁富椤甸潰锛岃疆璇㈡煡璇㈠凡鎭㈠");
 	            }
 	        } else {
 	            System.err.println("鍒囨崲鍒颁富椤甸潰锛屼覆鍙f湭杩炴帴锛屼繚鎸佽疆璇㈡殏鍋�");
@@ -795,12 +800,15 @@
 	/**
 	 * 鍚姩UI鍒锋柊瀹氭椂鍣� - 姣�3绉掑埛鏂颁竴娆�
 	 */
+	// 鍦╯tartUIUpdates()鏂规硶涓皟鐢�
 	private void startUIUpdates() {
-		uiUpdateTimer = new Timer(3000, e -> {			
-			updateCardSlotsDisplay();
-			updateStatistics();
-		});
-		uiUpdateTimer.start();
+	    uiUpdateTimer = new Timer(3000, e -> {
+	        ensurePollingRunning(); // 纭繚杞杩愯
+	        ensureSerialParserRunning(); // 纭繚涓插彛瑙f瀽鍣ㄨ繍琛�
+	        updateCardSlotsDisplay();
+	        updateStatistics();
+	    });
+	    uiUpdateTimer.start();
 	}
 	
 	/**
@@ -828,5 +836,42 @@
 	public SlotManager getSlotManager() {
 	    return slotManager;
 	}
+	
+	/**
+	 * 妫�鏌ュ苟纭繚杞鏌ヨ姝e父杩愯
+	 */
+	private void ensurePollingRunning() {
+	    if (!lunxun.isPolling() && lunxun.checkSerialConnection()) {
+	        // 濡傛灉杞鏈繍琛屼絾涓插彛宸茶繛鎺ワ紝鑷姩鍚姩杞
+	        boolean started = lunxun.startPolling();
+	        if (started) {
+	            System.out.println("妫�娴嬪埌杞鏈繍琛岋紝宸茶嚜鍔ㄥ惎鍔�");
+	        }
+	    }
+	}
+	
+	/**
+	 * 纭繚涓插彛瑙f瀽鍣ㄦ甯歌繍琛�
+	 */
+	private void ensureSerialParserRunning() {
+	    // 濡傛灉涓插彛瑙f瀽鍣ㄦ湭杩愯浣嗕覆鍙e凡杩炴帴锛岃嚜鍔ㄥ惎鍔�
+	    if (serialProtocolParser != null && !serialProtocolParser.isRunning() && lunxun.checkSerialConnection()) {
+	        serialProtocolParser.start();
+	        //System.out.println("妫�娴嬪埌涓插彛瑙f瀽鍣ㄦ湭杩愯锛屽凡鑷姩鍚姩");
+	    }
+	}
+	
+	/**
+	 * 鍒濆鍖栦覆鍙hВ鏋愬櫒
+	 */
+	private void initializeSerialParser() {
+	    try {
+	        serialProtocolParser = new SerialProtocolParser();
+	        serialProtocolParser.start();
+	        //System.out.println("涓插彛鍗忚瑙f瀽鍣ㄥ凡鍚姩");
+	    } catch (Exception e) {
+	        System.err.println("鍒濆鍖栦覆鍙hВ鏋愬櫒澶辫触: " + e.getMessage());
+	    }
+	}
 		
 }
\ No newline at end of file

--
Gitblit v1.9.3