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

main
liuguijing 6 months ago
parent 3f7b3a0dc6
commit fa1037a674

@ -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();
}
}

Loading…
Cancel
Save