| | |
| | | |
| | | if (result) { |
| | | if (DEBUG_ENABLED) { |
| | | System.out.println("串口连接正常"); |
| | | //System.out.println("串口连接正常"); |
| | | } |
| | | serialConnected = true; |
| | | } else { |
| | |
| | | */ |
| | | public static boolean startPolling() { |
| | | if (isRunning) { |
| | | System.out.println("轮询查询已经在运行中"); |
| | | //System.out.println("轮询查询已经在运行中"); |
| | | return true; |
| | | } |
| | | |
| | |
| | | pollingThread.setDaemon(true); |
| | | pollingThread.start(); |
| | | if (DEBUG_ENABLED) { |
| | | System.out.println("轮询查询已启动,间隔: " + pollingInterval + "ms"); |
| | | //System.out.println("轮询查询已启动,间隔: " + pollingInterval + "ms"); |
| | | } |
| | | return true; |
| | | } catch (Exception e) { |
| | |
| | | */ |
| | | public static boolean stopPolling() { |
| | | if (!isRunning) { |
| | | System.out.println("轮询查询未在运行"); |
| | | //System.out.println("轮询查询未在运行"); |
| | | return false; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | shouldStop.set(false); |
| | | System.out.println("轮询查询已停止"); |
| | | //System.out.println("轮询查询已停止"); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public static boolean pausePolling() { |
| | | if (!isRunning) { |
| | | if (DEBUG_ENABLED) { |
| | | System.out.println("轮询查询未在运行,无法暂停"); |
| | | //System.out.println("轮询查询未在运行,无法暂停"); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | if (isPaused) { |
| | | if (DEBUG_ENABLED) { |
| | | System.out.println("轮询查询已经处于暂停状态"); |
| | | //System.out.println("轮询查询已经处于暂停状态"); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | isPaused = true; |
| | | System.out.println("轮询查询已暂停"); |
| | | //System.out.println("轮询查询已暂停"); |
| | | return true; |
| | | } |
| | | |
| | |
| | | */ |
| | | public static boolean resumePolling() { |
| | | if (!isRunning) { |
| | | System.out.println("轮询查询未在运行,无法恢复"); |
| | | //System.out.println("轮询查询未在运行,无法恢复"); |
| | | return false; |
| | | } |
| | | |
| | | if (!isPaused) { |
| | | System.out.println("轮询查询未处于暂停状态"); |
| | | //System.out.println("轮询查询未处于暂停状态"); |
| | | return false; |
| | | } |
| | | |
| | |
| | | synchronized (lunxun.class) { |
| | | lunxun.class.notifyAll(); // 唤醒等待的线程 |
| | | } |
| | | System.out.println("轮询查询已恢复"); |
| | | //System.out.println("轮询查询已恢复"); |
| | | return true; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | pollingInterval = interval; |
| | | System.out.println("轮询间隔已设置为: " + interval + "ms"); |
| | | //System.out.println("轮询间隔已设置为: " + interval + "ms"); |
| | | |
| | | // 如果正在运行,重新启动以应用新的间隔 |
| | | if (isRunning) { |
| | |
| | | if (configSystem.isInitialized()) { |
| | | MachineConfig machineConfig = configSystem.getMachineConfig(); |
| | | pollingInterval = machineConfig.getPollingInterval(); |
| | | System.out.println("从配置加载轮询间隔: " + pollingInterval + "ms"); |
| | | //System.out.println("从配置加载轮询间隔: " + pollingInterval + "ms"); |
| | | } else { |
| | | System.out.println("配置系统未初始化,使用默认轮询间隔: " + pollingInterval + "ms"); |
| | | //System.out.println("配置系统未初始化,使用默认轮询间隔: " + pollingInterval + "ms"); |
| | | } |
| | | } catch (Exception e) { |
| | | System.err.println("加载轮询间隔配置失败: " + e.getMessage()); |
| | | System.out.println("使用默认轮询间隔: " + pollingInterval + "ms"); |
| | | //System.out.println("使用默认轮询间隔: " + pollingInterval + "ms"); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | public static void clearQueryCache() { |
| | | queryCommandCache.clear(); |
| | | System.out.println("查询指令缓存已清空"); |
| | | //System.out.println("查询指令缓存已清空"); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | @Override |
| | | public void run() { |
| | | System.out.println("轮询查询线程开始运行"); |
| | | //System.out.println("轮询查询线程开始运行"); |
| | | |
| | | while (isRunning && !Thread.currentThread().isInterrupted() && !shouldStop.get()) { |
| | | try { |
| | |
| | | } |
| | | |
| | | } catch (InterruptedException e) { |
| | | System.out.println("轮询查询线程被中断"); |
| | | //System.out.println("轮询查询线程被中断"); |
| | | Thread.currentThread().interrupt(); |
| | | break; |
| | | } catch (Exception e) { |
| | |
| | | } |
| | | } |
| | | |
| | | System.out.println("轮询查询线程结束运行"); |
| | | //System.out.println("轮询查询线程结束运行"); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | if (sendResult) { |
| | | if (DEBUG_ENABLED) { |
| | | System.out.println("立即查询成功 - 卡槽 " + slotNumber); |
| | | //System.out.println("立即查询成功 - 卡槽 " + slotNumber); |
| | | } |
| | | return true; |
| | | } else { |
| | |
| | | int batchSize = 5; // 每批次发送5个查询 |
| | | int totalSlots = MAX_SLOT - MIN_SLOT + 1; |
| | | |
| | | System.out.println("开始批量查询所有卡槽..."); |
| | | //System.out.println("开始批量查询所有卡槽..."); |
| | | |
| | | for (int batchStart = MIN_SLOT; batchStart <= MAX_SLOT; batchStart += batchSize) { |
| | | if (shouldStop.get()) { |
| | |
| | | } |
| | | } |
| | | |
| | | System.out.println("批量查询完成,成功发送: " + successCount + "/" + totalSlots); |
| | | //System.out.println("批量查询完成,成功发送: " + successCount + "/" + totalSlots); |
| | | return successCount; |
| | | } |
| | | |
| | |
| | | lastSerialCheckTime = System.currentTimeMillis(); |
| | | |
| | | if (connected) { |
| | | System.out.println("串口连接状态已设置为: 已连接"); |
| | | // //System.out.println("串口连接状态已设置为: 已连接"); |
| | | } else { |
| | | System.err.println("串口连接状态已设置为: 未连接"); |
| | | // 如果串口断开且轮询正在运行,自动暂停轮询 |
| | |
| | | */ |
| | | public static boolean setPollingPaused(boolean paused) { |
| | | if (!isRunning) { |
| | | System.out.println("轮询查询未在运行,无法设置暂停状态"); |
| | | //System.out.println("轮询查询未在运行,无法设置暂停状态"); |
| | | return false; |
| | | } |
| | | |
| | |
| | | // 请求暂停 |
| | | if (!isPaused) { |
| | | isPaused = true; |
| | | System.out.println("轮询查询已通过外部调用暂停"); |
| | | //System.out.println("轮询查询已通过外部调用暂停"); |
| | | return true; |
| | | } else { |
| | | System.out.println("轮询查询已经处于暂停状态"); |
| | | //System.out.println("轮询查询已经处于暂停状态"); |
| | | return false; |
| | | } |
| | | } else { |
| | |
| | | synchronized (lunxun.class) { |
| | | lunxun.class.notifyAll(); // 唤醒等待的线程 |
| | | } |
| | | System.out.println("轮询查询已通过外部调用恢复"); |
| | | //System.out.println("轮询查询已通过外部调用恢复"); |
| | | return true; |
| | | } else { |
| | | System.out.println("轮询查询未处于暂停状态"); |
| | | //System.out.println("轮询查询未处于暂停状态"); |
| | | return false; |
| | | } |
| | | } |