From 781273f7f74dab6b3aeda5ca15d40f69da677bd7 Mon Sep 17 00:00:00 2001 From: shenzhouyu Date: Mon, 23 Nov 2026 09:26:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=9F=AD=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=86=85=E4=B8=8D=E6=8F=92=E5=85=A5=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devicecollector/runner/DeviceRunner.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/glue-modbus-collector/src/main/java/com/xujie/devicecollector/runner/DeviceRunner.java b/glue-modbus-collector/src/main/java/com/xujie/devicecollector/runner/DeviceRunner.java index 982f803..0ba0f7a 100644 --- a/glue-modbus-collector/src/main/java/com/xujie/devicecollector/runner/DeviceRunner.java +++ b/glue-modbus-collector/src/main/java/com/xujie/devicecollector/runner/DeviceRunner.java @@ -55,6 +55,9 @@ public class DeviceRunner implements CommandLineRunner { private ResourceDao resourceDao; private static final long CHECK_INTERVAL = 2000;// 毫秒 + private static final long MIN_SMALL_CUT_INTERVAL_NANOS = TimeUnit.SECONDS.toNanos(15); + // 按设备记录最近一次接受的小卷分切信号时间,使用单调时钟计算间隔。 + private final Map lastSmallCutSignalTimes = new HashMap<>(); @Override public void run(String... args) throws Exception { @@ -288,6 +291,28 @@ public class DeviceRunner implements CommandLineRunner { Integer smallCutSignal = collectUtil.readHoldingRegister(ip, port, smallCutSignalAddr); logger.info("小卷分切信号:{}", smallCutSignal); + if (Objects.equals(smallCutSignal, 1)) { + String deviceKey = ip + ":" + port; + long elapsedNanos = Long.MAX_VALUE; + synchronized (lastSmallCutSignalTimes) { + long now = System.nanoTime(); + Long lastSignalTime = lastSmallCutSignalTimes.get(deviceKey); + if (lastSignalTime != null) { + elapsedNanos = now - lastSignalTime; + } + if (elapsedNanos >= MIN_SMALL_CUT_INTERVAL_NANOS) { + lastSmallCutSignalTimes.put(deviceKey, now); + } + } + if (elapsedNanos < MIN_SMALL_CUT_INTERVAL_NANOS) { + // 重复信号仍需清零,避免留到时间窗口结束后再次录入。 + collectUtil.writeHoldingRegister(ip, port, smallCutSignalAddr, 0); + logger.info("设备{}小卷分切信号距上次接受信号仅{}毫秒,小于15秒,已清零并跳过处理", + deviceKey, TimeUnit.NANOSECONDS.toMillis(elapsedNanos)); + return; + } + } + // 如果获取到小卷分切信号为 1,则读取寄存器地址 199 和 200 的值(32位浮点数,低字在前) Integer lowWord = null; // 寄存器201:低16位 Integer highWord = null; // 寄存器200:高16位