From 9232abfa743066362fdb9b7d455041f2ac879f97 Mon Sep 17 00:00:00 2001 From: liuguijing <123456> Date: Tue, 10 Dec 2024 14:50:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E7=A1=AC=E6=8E=A5=E7=82=B9?= =?UTF-8?q?=E8=A3=85=E7=BD=AE=E7=9D=A1=E7=9C=A0=E6=97=B6=E9=97=B4=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xydl/cac/serialport/SerialPortServer.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/xydl/cac/serialport/SerialPortServer.java b/src/main/java/com/xydl/cac/serialport/SerialPortServer.java index 91356e5..1fbd079 100644 --- a/src/main/java/com/xydl/cac/serialport/SerialPortServer.java +++ b/src/main/java/com/xydl/cac/serialport/SerialPortServer.java @@ -1,6 +1,7 @@ package com.xydl.cac.serialport; import com.fazecast.jSerialComm.SerialPort; +import com.xydl.cac.model.StaticVariable; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Async; @@ -80,14 +81,17 @@ public class SerialPortServer { } LastWarningTime = l; port.writeBytes(openbuffer, openbuffer.length); - try { - Thread.sleep(warntime * 1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } finally { - port.writeBytes(stopbuffer, stopbuffer.length); - started = false; + int seconds = 0; + while (StaticVariable.shutdown == 0 && seconds > warntime) { + try { + Thread.sleep(1000); + seconds++; + } catch (Exception ignore) { + port.writeBytes(stopbuffer, stopbuffer.length); + started = false; + } } + port.writeBytes(stopbuffer, stopbuffer.length); } } started = false;