| | |
| | | import xitongshezhi.AdminLoginDialog; |
| | | import xitongshezhi.CardPickupDialog; |
| | | import xitongshezhi.ConfigSet; |
| | | import xitongshezhi.Fkj; |
| | | import chuankou.SerialPortService; |
| | | import chuankou.Sendmsg; |
| | | |
| | |
| | | private JPanel commFaultPanel; |
| | | |
| | | public CardMachineUI() { |
| | | try { |
| | | try { |
| | | // 先初始化系统配置和组件 |
| | | initializeSystem(); |
| | | |
| | | // 初始化串口解析器 |
| | | initializeSerialParser(); |
| | | |
| | | // 然后初始化UI |
| | | initializeUI(); |
| | |
| | | if (serialConnected && lunxun.isPolling() && lunxun.isPaused()) { |
| | | // 只有在不在设置页面时才自动恢复 |
| | | if (!isInConfigPage()) { |
| | | lunxun.resumePolling(); |
| | | // lunxun.resumePolling(); |
| | | // System.out.println("尝试自动启动轮询功能"); |
| | | } |
| | | } |
| | | }); |
| | |
| | | } |
| | | |
| | | private void initializeUI() { |
| | | setTitle("UWB人员定位卡发卡机管理系统"); |
| | | setTitle("智能人脸发卡机管理系统"); |
| | | setSize(SCREEN_WIDTH, SCREEN_HEIGHT); |
| | | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
| | | setLocationRelativeTo(null); |
| | |
| | | refreshBtn.addActionListener(e -> { |
| | | updateCardSlotsDisplay(); |
| | | updateStatistics(); |
| | | lunxun.resumePolling(); |
| | | JOptionPane.showMessageDialog(CardMachineUI.this, |
| | | "手动刷新完成,共刷新 " + TOTAL_SLOTS + " 个卡槽", |
| | | "手动刷新完成,启动轮询,共刷新 " + TOTAL_SLOTS + " 个卡槽", |
| | | "刷新完成", JOptionPane.INFORMATION_MESSAGE); |
| | | }); |
| | | |
| | |
| | | |
| | | if (pickupSuccess) { |
| | | // 取卡成功,调用changgehaska方法改变卡槽属性 |
| | | SlotManager.changgehaska(slotId, "1"); // "1"表示管理员操作 |
| | | SlotManager.changgehaska(slotId,1); // "1"表示管理员操作 |
| | | //System.out.println("卡槽 " + slotId + " 取卡成功,已更新卡槽状态"); |
| | | } |
| | | } |
| | |
| | | /** |
| | | * 启动UI刷新定时器 - 每3秒刷新一次 |
| | | */ |
| | | // 在startUIUpdates()方法中调用 |
| | | private void startUIUpdates() { |
| | | uiUpdateTimer = new Timer(3000, e -> { |
| | | updateCardSlotsDisplay(); |
| | | updateStatistics(); |
| | | }); |
| | | uiUpdateTimer.start(); |
| | | uiUpdateTimer = new Timer(3000, e -> { |
| | | ensurePollingRunning(); // 确保轮询运行 |
| | | ensureSerialParserRunning(); // 确保串口解析器运行 |
| | | updateCardSlotsDisplay(); |
| | | updateStatistics(); |
| | | }); |
| | | uiUpdateTimer.start(); |
| | | } |
| | | |
| | | /** |
| | |
| | | public SlotManager getSlotManager() { |
| | | return slotManager; |
| | | } |
| | | |
| | | /** |
| | | * 检查并确保轮询查询正常运行 |
| | | */ |
| | | private void ensurePollingRunning() { |
| | | if (!lunxun.isPolling() && lunxun.checkSerialConnection()) { |
| | | // 如果轮询未运行但串口已连接,自动启动轮询 |
| | | boolean started = lunxun.startPolling(); |
| | | if (started) { |
| | | System.out.println("检测到轮询未运行,已自动启动"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 确保串口解析器正常运行 |
| | | */ |
| | | private void ensureSerialParserRunning() { |
| | | // 如果串口解析器未运行但串口已连接,自动启动 |
| | | if (serialProtocolParser != null && !serialProtocolParser.isRunning() && lunxun.checkSerialConnection()) { |
| | | serialProtocolParser.start(); |
| | | //System.out.println("检测到串口解析器未运行,已自动启动"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 初始化串口解析器 |
| | | */ |
| | | private void initializeSerialParser() { |
| | | try { |
| | | serialProtocolParser = new SerialProtocolParser(); |
| | | serialProtocolParser.start(); |
| | | //System.out.println("串口协议解析器已启动"); |
| | | } catch (Exception e) { |
| | | System.err.println("初始化串口解析器失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | } |