diff --git a/src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java b/src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java index eeddf84..a0c3cbe 100644 --- a/src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java +++ b/src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java @@ -83,14 +83,14 @@ public class SprayTaskExecutor { //先移动到玻片位置 DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(slideArr[sprayTaskStep.getIndex()][0], 20.0); DeviceCommand motorYPositionSetCommand = DeviceCommandGenerator.motorYPositionSet(75.5 - slideArr[sprayTaskStep.getIndex()][1], 20.0); - CommandFuture motorXPositionSetCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXPositionSetCommand); - CommandFuture motorYPositionSetCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYPositionSetCommand); + CommandFuture motorXPositionSetCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXPositionSetCommand); + CommandFuture motorYPositionSetCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYPositionSetCommand); SysSettings slideHeightSysSettings = sysSettingsService.getOne(new LambdaQueryWrapper().eq(SysSettings::getCode, "slide_height")); Double slideHeight = Double.parseDouble(slideHeightSysSettings.getValue()); Double height = slideHeight - sprayTask.getSprayParams().getMotorZHeight();//下降z轴高度 DeviceCommand motorZPositionSetAboveSlideCommand = DeviceCommandGenerator.motorZPositionSet(height, 15.0); - CommandFuture motorZPositionSetAboveSlideCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZPositionSetAboveSlideCommand); + CommandFuture motorZPositionSetAboveSlideCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZPositionSetAboveSlideCommand); commandWait(motorXPositionSetCommandFuture, motorYPositionSetCommandFuture, motorZPositionSetAboveSlideCommandFuture); } Thread.sleep(100); @@ -110,7 +110,7 @@ public class SprayTaskExecutor { } if(i == 1){ DeviceCommand syringePumpForwardCommand = DeviceCommandGenerator.syringePumpForward(sprayTask.getSprayParams().getVolume());//推动移动注射泵 - CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpForwardCommand); + CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpForwardCommand); commandWait(syringePumpForwardCommandFuture); } sprayTask.setFirstImmobility(true); @@ -127,12 +127,12 @@ public class SprayTaskExecutor { ySprayStepCommands.getParam().put("position", Double.parseDouble(df.format(aYPoint))); if (cacheXPoint != aXPoint) { - CommandFuture commandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), xSprayStepCommands); + CommandFuture commandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), xSprayStepCommands); commandFutureList.add(commandFuture); cacheXPoint = aXPoint; } if (cacheYPoint != aYPoint) { - CommandFuture commandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), ySprayStepCommands); + CommandFuture commandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), ySprayStepCommands); commandFutureList.add(commandFuture); cacheYPoint = aYPoint; } @@ -160,7 +160,7 @@ public class SprayTaskExecutor { deviceStatus.setSuspendable(false); if (currentStep >= reCurrentStep) { DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop();//停止推动注射泵 - CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpStopCommand); + CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpStopCommand); commandWait(syringePumpStopCommandFuture); } sprayCount++; @@ -168,20 +168,20 @@ public class SprayTaskExecutor { } DeviceCommand highVoltageCloseCommand = DeviceCommandGenerator.highVoltageClose();//关闭高压 - CommandFuture highVoltageCloseCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), highVoltageCloseCommand); + CommandFuture highVoltageCloseCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), highVoltageCloseCommand); commandWait(highVoltageCloseCommandFuture); Thread.sleep(500); DeviceCommand nozzleValveCloseCommand = DeviceCommandGenerator.nozzleValveClose();//关闭喷嘴阀 - CommandFuture nozzleValveCloseCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), nozzleValveCloseCommand); + CommandFuture nozzleValveCloseCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), nozzleValveCloseCommand); commandWait(nozzleValveCloseCommandFuture); //XYZ回原点 DeviceCommand motorXOriginCommand = DeviceCommandGenerator.motorXOrigin(); DeviceCommand motorYOriginCommand = DeviceCommandGenerator.motorYOrigin(); DeviceCommand motorZOriginCommand = DeviceCommandGenerator.motorZOrigin(); - CommandFuture motorXOriginCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXOriginCommand); - CommandFuture motorYOriginCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYOriginCommand); - CommandFuture motorZOriginCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZOriginCommand); + CommandFuture motorXOriginCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXOriginCommand); + CommandFuture motorYOriginCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYOriginCommand); + CommandFuture motorZOriginCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZOriginCommand); commandWait(motorXOriginCommandFuture, motorYOriginCommandFuture, motorZOriginCommandFuture); diff --git a/src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java b/src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java index f387cc2..1a0ee14 100644 --- a/src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java +++ b/src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java @@ -4,6 +4,7 @@ import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.qyft.ms.app.core.event.VirtualDeviceCmdResponseEvent; import com.qyft.ms.app.device.status.DeviceStatus; +import com.qyft.ms.app.device.status.SprayTask; import com.qyft.ms.system.common.constant.CommandStatus; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.CyclicNumberGenerator; @@ -72,6 +73,14 @@ public class DeviceCommandService { return commandFuture; } + public CommandFuture sendCommandSprayTask(String cmdId, String cmdCode, DeviceCommand deviceCommand) throws Exception { + SprayTask sprayTask = SprayTask.getInstance(); + if (sprayTask.isClosing() || Thread.currentThread().isInterrupted()) { + throw new InterruptedException(); + } + return sendCommand(cmdId, cmdCode, deviceCommand); + } + public void completeCommandResponse(JSONObject deviceResult) { Integer cmdId = deviceResult.getInt("cmdId"); if (cmdId != null) {