告警硬接点装置重连逻辑修改

main
liuguijing 6 months ago
parent 3f7b3a0dc6
commit fa1037a674

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

Loading…
Cancel
Save