diff --git a/src/main/java/com/xydl/cac/serialport/SerialPortServer.java b/src/main/java/com/xydl/cac/serialport/SerialPortServer.java index 795f1f2..0cd89d7 100644 --- a/src/main/java/com/xydl/cac/serialport/SerialPortServer.java +++ b/src/main/java/com/xydl/cac/serialport/SerialPortServer.java @@ -10,16 +10,18 @@ import org.springframework.stereotype.Service; import javax.annotation.PreDestroy; import java.util.ArrayList; import java.util.Arrays; -import java.util.Iterator; import java.util.List; -import java.util.regex.Pattern; @Service @Slf4j public class SerialPortServer { + @Value("${cac.warnport.name}") + public String portname; + @Value("${cac.warnport.intervaltime:60}") public Integer intervaltime; + @Value("${cac.warnport.warntime:5}") public Integer warntime; @@ -40,7 +42,7 @@ public class SerialPortServer { log.info("获取串口: " + port.getSystemPortName()); String systemPortName = port.getSystemPortName(); if (systemPortName != null) { - if (systemPortName.startsWith("ttyCH341")) { + if (systemPortName.startsWith(portname)) { currentPort = port; log.info("获取到硬接点告警串口: " + port.getSystemPortName()); } @@ -50,7 +52,6 @@ public class SerialPortServer { } else { log.error("硬接点串口存在!"); } - } public void closeSerialPort() { @@ -77,10 +78,12 @@ public class SerialPortServer { } else { if (l - LastWarningTime <= (intervaltime * 1000)) { started = false; + log.info("告警频繁,取消告警!"); return; } } LastWarningTime = l; + log.info("开始发送告警!"); port.writeBytes(openbuffer, openbuffer.length); int seconds = 0; while (StaticVariable.shutdown == 0 && seconds < warntime) { @@ -90,10 +93,13 @@ public class SerialPortServer { } catch (Exception ignore) { } } + log.info("开始关闭告警!"); port.writeBytes(stopbuffer, stopbuffer.length); + } } started = false; + closeSerialPort(); } }