From ba65ca24c7a55eb55ff5116a278dd19bd535c361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=A2=A6=E8=BF=9C?= <1063331231@qq.com> Date: Thu, 17 Jul 2025 17:54:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E5=B0=84=E7=AE=A1=E9=81=93=E6=B8=85?= =?UTF-8?q?=E6=B4=97=20=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../front/cmd/business/SyringePipelineWash.java | 125 +++++++++++---------- .../cmd/business/SyringePipelineWashStop.java | 54 +++++---- 2 files changed, 93 insertions(+), 86 deletions(-) diff --git a/src/main/java/com/qyft/ms/app/front/cmd/business/SyringePipelineWash.java b/src/main/java/com/qyft/ms/app/front/cmd/business/SyringePipelineWash.java index 393ab55..122f375 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/business/SyringePipelineWash.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/business/SyringePipelineWash.java @@ -24,7 +24,7 @@ import org.springframework.stereotype.Component; import java.util.concurrent.CompletableFuture; /** - * 注射器管路_清洗注射器管路 + * 清洗注射器管路 */ @Slf4j @Component @@ -40,7 +40,10 @@ public class SyringePipelineWash extends BaseCommandHandler { @Override public CompletableFuture handle(FrontCmdControlForm form) { - if (deviceStatus.isCleaningSyringePipeline() || deviceStatus.isCleaningNozzlePipeline()) { + if(deviceStatus.isSpraying()){ + throw new RuntimeException("正在喷涂,无法开启清洗注射器管路"); + } + if ( deviceStatus.isCleaningSyringePipeline() || deviceStatus.isCleaningNozzlePipeline()) { throw new RuntimeException("正在清洗喷嘴管路或注射器管路,无法开启清洗注射器管路"); } Double speed = form.getDoubleParam("speed"); @@ -49,71 +52,69 @@ public class SyringePipelineWash extends BaseCommandHandler { throw new RuntimeException("参数 speed 必填"); } if (speed > 100) { - webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "清洗速度不能大于100")); - throw new RuntimeException("预充速度不能大于100"); + webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "移动速度不能大于100")); + throw new RuntimeException("移动速度不能大于100"); } - try { - //2.判断z轴是否在安全距离,如果不在安全距离可以不抬升z轴 - DeviceCommand motorXyzPositionGetCommand = DeviceCommandGenerator.motorXyzPositionGet(); - CommandFuture motorXyzPositionGetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXyzPositionGetCommand); - commandWait(motorXyzPositionGetCommandFuture); - JSONObject motorXyzPositionGetCommandDeviceResult = motorXyzPositionGetCommandFuture.getResponseResult(); - Double zAxisPosition = motorXyzPositionGetCommandDeviceResult.getJSONObject("data").getDouble("zAxisPosition"); - if (zAxisPosition == null) { - webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "获得电机XYZ相对原点坐标失败", motorXyzPositionGetCommandDeviceResult)); - throw new RuntimeException("获得电机XYZ相对原点坐标失败"); - } - zAxisPosition = Math.abs(zAxisPosition); - SysSettings safeZHeightSysSettings = sysSettingsService.getOne(new LambdaQueryWrapper().eq(SysSettings::getCode, "safe_z_height")); - double safeZHeight = Double.parseDouble(safeZHeightSysSettings.getValue()); - if (zAxisPosition > safeZHeight) { //z轴超出安全距离,抬升z轴 - DeviceCommand motorZPositionSetCommand = DeviceCommandGenerator.motorZPositionSet(safeZHeight, 15.0); + return runAsync(() -> { + try { + deviceStatus.setCleaningSyringePipeline(true); + //2.判断z轴是否在安全距离,如果不在安全距离可以不抬升z轴 + DeviceCommand motorXyzPositionGetCommand = DeviceCommandGenerator.motorXyzPositionGet(); + CommandFuture motorXyzPositionGetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXyzPositionGetCommand); + commandWait(motorXyzPositionGetCommandFuture); + JSONObject motorXyzPositionGetCommandDeviceResult = motorXyzPositionGetCommandFuture.getResponseResult(); + Double zAxisPosition = motorXyzPositionGetCommandDeviceResult.getJSONObject("data").getDouble("zAxisPosition"); + if (zAxisPosition == null) { + webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "获得电机XYZ相对原点坐标失败", motorXyzPositionGetCommandDeviceResult)); + throw new RuntimeException("获得电机XYZ相对原点坐标失败"); + } + zAxisPosition = Math.abs(zAxisPosition); + SysSettings safeZHeightSysSettings = sysSettingsService.getOne(new LambdaQueryWrapper().eq(SysSettings::getCode, "safe_z_height")); + double safeZHeight = Double.parseDouble(safeZHeightSysSettings.getValue()); + if (zAxisPosition > safeZHeight) { //z轴超出安全距离,抬升z轴 + DeviceCommand motorZPositionSetCommand = DeviceCommandGenerator.motorZPositionSet(safeZHeight, 15.0); + CommandFuture motorZPositionSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZPositionSetCommand); + commandWait(motorZPositionSetCommandFuture); + } + Position wasteLiquor = positionService.getOne(new LambdaQueryWrapper().eq(Position::getPointCode, "waste_liquor")); + //3.x轴移动到废液位置 + DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(wasteLiquor.getX(), 20.0); + CommandFuture motorXPositionSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXPositionSetCommand); + commandWait(motorXPositionSetCommandFuture); + //4.下降z轴高度,防止飞溅 + DeviceCommand motorZPositionSetCommand = DeviceCommandGenerator.motorZPositionSet(wasteLiquor.getZ(), 20.0); CommandFuture motorZPositionSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZPositionSetCommand); commandWait(motorZPositionSetCommandFuture); - } - Position wasteLiquor = positionService.getOne(new LambdaQueryWrapper().eq(Position::getPointCode, "waste_liquor")); - //xy轴移动到废液位置 - DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(wasteLiquor.getX(), 20.0); - CommandFuture motorXPositionSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXPositionSetCommand); - DeviceCommand motorYPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(wasteLiquor.getY(), 20.0); - CommandFuture motorYPositionSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYPositionSetCommand); - commandWait(motorXPositionSetCommandFuture, motorYPositionSetCommandFuture); - //下降z轴高度,防止飞溅 - DeviceCommand motorZPositionSetCommand = DeviceCommandGenerator.motorZPositionSet(wasteLiquor.getZ(), 20.0); - CommandFuture motorZPositionSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZPositionSetCommand); - commandWait(motorZPositionSetCommandFuture); - - //5.开启喷嘴阀 - DeviceCommand nozzleValveOpenCommand = DeviceCommandGenerator.nozzleValveOpen(); // 开启喷嘴阀 - CommandFuture nozzleValveOpenCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), nozzleValveOpenCommand); - commandWait(nozzleValveOpenCommandFuture); - Thread.sleep(500);//开启喷嘴阀后需要延迟500毫秒 - - //6.设置注射泵速度,推注射泵 - DeviceCommand syringePumpStartCommand = DeviceCommandGenerator.syringePumpForward(speed); // 生成移动注射泵指令 - CommandFuture syringePumpStartCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpStartCommand); - commandWait(syringePumpStartCommandFuture); - - //5.打开三通阀注射器管路 -// DeviceCommand threeWayValveOpenNozzlePipelineCommand = DeviceCommandGenerator.threeWayValveOpenNozzlePipeline(); -// CommandFuture threeWayValveOpenNozzlePipelineCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), threeWayValveOpenNozzlePipelineCommand); -// commandWait(threeWayValveOpenNozzlePipelineCommandFuture); - - //6.打开清洗阀 -// DeviceCommand washValveOpenCommand = DeviceCommandGenerator.washValveOpen(); // 生成打开清洗阀指令 -// CommandFuture washValveOpenCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), washValveOpenCommand); -// commandWait(washValveOpenCommandFuture); - - - deviceStatus.setCleaningSyringePipeline(true); - } catch (Exception e) { - deviceStatus.setCleaningSyringePipeline(false); - throw new RuntimeException(e); - } - - return runAsync(() -> { + //5.三通阀打开注射器管路 + DeviceCommand openSyringePipelineCommand = DeviceCommandGenerator.threeWayValveOpenSyringePipeline(); + CommandFuture openSyringePipelineCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), openSyringePipelineCommand); + commandWait(openSyringePipelineCommandFuture); + + //6.关闭清洗和除湿阀 开启喷嘴阀 + DeviceCommand nozzleValveOpenCommand = DeviceCommandGenerator.nozzleValveOpen(); // 开启喷嘴阀 + CommandFuture nozzleValveOpenCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), nozzleValveOpenCommand); + commandWait(nozzleValveOpenCommandFuture); + + DeviceCommand washValveCloseCommand = DeviceCommandGenerator.washValveClose(); // 关闭清洗阀 + CommandFuture washValveCloseCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), washValveCloseCommand); + commandWait(washValveCloseCommandFuture); + + DeviceCommand dehumidifierCloseCommand = DeviceCommandGenerator.dehumidifierValveClose(); // 关闭除湿阀门 + CommandFuture dehumidifierCloseCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), dehumidifierCloseCommand); + commandWait(dehumidifierCloseCommandFuture); + + Thread.sleep(500); + + //7.设置注射泵速度,推注射泵 + DeviceCommand syringePumpStartCommand = DeviceCommandGenerator.syringePumpForward(speed); // 生成移动注射泵指令 + CommandFuture syringePumpStartCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpStartCommand); + commandWait(syringePumpStartCommandFuture); + } catch (Exception e) { + deviceStatus.setCleaningSyringePipeline(false); + throw new RuntimeException(e); + } }); diff --git a/src/main/java/com/qyft/ms/app/front/cmd/business/SyringePipelineWashStop.java b/src/main/java/com/qyft/ms/app/front/cmd/business/SyringePipelineWashStop.java index 5a572a0..9b2c29b 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/business/SyringePipelineWashStop.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/business/SyringePipelineWashStop.java @@ -29,35 +29,41 @@ public class SyringePipelineWashStop extends BaseCommandHandler { @Override public CompletableFuture handle(FrontCmdControlForm form) { return runAsync(() -> { - DeviceCommand motorXStopCommand = DeviceCommandGenerator.motorXStop(); //x轴停止移动 - DeviceCommand motorYStopCommand = DeviceCommandGenerator.motorYStop(); //y轴停止移动 - DeviceCommand motorZStopCommand = DeviceCommandGenerator.motorZStop(); //z轴停止移动 - CommandFuture motorXStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXStopCommand); - CommandFuture motorYStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYStopCommand); - CommandFuture motorZStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZStopCommand); - commandWait(motorXStopCommandFuture, motorYStopCommandFuture, motorZStopCommandFuture); + try { + DeviceCommand motorXStopCommand = DeviceCommandGenerator.motorXStop(); //x轴停止移动 + DeviceCommand motorYStopCommand = DeviceCommandGenerator.motorYStop(); //y轴停止移动 + DeviceCommand motorZStopCommand = DeviceCommandGenerator.motorZStop(); //z轴停止移动 + CommandFuture motorXStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXStopCommand); + CommandFuture motorYStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYStopCommand); + CommandFuture motorZStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZStopCommand); + commandWait(motorXStopCommandFuture, motorYStopCommandFuture, motorZStopCommandFuture); - //1.停止推动注射泵 - DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop(); //停止推动注射泵 - CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpStopCommand); + //1.停止推动注射泵 + DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop(); //停止推动注射泵 + CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpStopCommand); + //2.全部关闭三通阀 + DeviceCommand threeWayValveCloseAllCommand = DeviceCommandGenerator.threeWayValveCloseAll(); // 生成全部关闭三通阀指令 + CommandFuture threeWayValveCloseAllCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), threeWayValveCloseAllCommand); + commandWait(syringePumpStopCommandFuture, threeWayValveCloseAllCommandFuture); - //2.全部关闭三通阀 - DeviceCommand threeWayValveCloseAllCommand = DeviceCommandGenerator.threeWayValveCloseAll(); // 生成全部关闭三通阀指令 - CommandFuture threeWayValveCloseAllCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), threeWayValveCloseAllCommand); - commandWait(syringePumpStopCommandFuture, threeWayValveCloseAllCommandFuture); + //3.关闭清洗阀 + DeviceCommand washValveCloseCommand = DeviceCommandGenerator.washValveClose(); // 关闭清洗阀 + CommandFuture washValveCloseCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), washValveCloseCommand); + commandWait(washValveCloseCommandFuture); - //6.关闭清洗阀 - DeviceCommand washValveCloseCommand = DeviceCommandGenerator.washValveClose(); // 关闭清洗阀 - CommandFuture washValveCloseCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), washValveCloseCommand); - commandWait(washValveCloseCommandFuture); + //4.关闭喷嘴阀 + DeviceCommand nozzleValveCloseCommand = DeviceCommandGenerator.nozzleValveClose(); // 关闭喷嘴阀 + CommandFuture nozzleValveCloseCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), nozzleValveCloseCommand); + commandWait(nozzleValveCloseCommandFuture); - //7.关闭喷嘴阀 - DeviceCommand nozzleValveCloseCommand = DeviceCommandGenerator.nozzleValveClose(); // 关闭喷嘴阀 - CommandFuture nozzleValveCloseCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), nozzleValveCloseCommand); - commandWait(nozzleValveCloseCommandFuture); + //5.关闭除湿阀 + DeviceCommand dehumidifierValveCloseCommand = DeviceCommandGenerator.dehumidifierValveClose(); // 关闭除湿阀 + CommandFuture dehumidifierValveCloseCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), dehumidifierValveCloseCommand); + commandWait(dehumidifierValveCloseCommandFuture); + }finally { + deviceStatus.setCleaningSyringePipeline(false); + } - deviceStatus.setCleaningSyringePipeline(false); - deviceStatus.setCleaningNozzlePipeline(false); }); }