From 2a00664d3e1eb872ec0c1e393884321e798b7d14 Mon Sep 17 00:00:00 2001 From: sige Date: Thu, 22 Feb 2024 17:01:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B7=E6=9C=AC=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../graphiteDigesterBg/task/TaskSampleTakeOut.java | 51 +++++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/src/src/main/java/com/my/graphiteDigesterBg/task/TaskSampleTakeOut.java b/src/src/main/java/com/my/graphiteDigesterBg/task/TaskSampleTakeOut.java index bc0822f..39cde3b 100644 --- a/src/src/main/java/com/my/graphiteDigesterBg/task/TaskSampleTakeOut.java +++ b/src/src/main/java/com/my/graphiteDigesterBg/task/TaskSampleTakeOut.java @@ -1,28 +1,75 @@ package com.my.graphiteDigesterBg.task; +import com.my.graphiteDigesterBg.MyDevice; import com.my.graphiteDigesterBg.diframe.DiTaskBase; import com.my.graphiteDigesterBg.diframe.Task; +import com.my.graphiteDigesterBg.diframe.actuator.DiActMotor; import com.my.graphiteDigesterBg.model.MdbOperationLog; import com.my.graphiteDigesterBg.move.MoveMoveTubeRackFromHeatPlateToLiquidPlate; import com.my.graphiteDigesterBg.resource.ResHeatingTubeRackSlotManager; - @Task(name="SampleTakeOut") public class TaskSampleTakeOut extends DiTaskBase { // slot index public Integer slotIndex; + // done lock + private final Object confirmLock = new Object(); @Override - public void run() { + protected void execute() { + this.setStatus(TaskStatus.RUNNING); MdbOperationLog.log(this.getUser(), "试管架%d : 取出样本", this.slotIndex); var slotMan = this.getResourceManager(ResHeatingTubeRackSlotManager.class); var slot = slotMan.getSlotByIndex(this.slotIndex); + if ( !slot.getIsLocked() ) { + throw new RuntimeException("试管架位为空,无法取出样本"); + } + + if ( slot.isHeating ) { + throw new RuntimeException("试管架正在加热中,无法取出样本"); + } + + if ( slot.rackPosition.equals("LiquidPlate") ) { + throw new RuntimeException("试管架未复位到加热盘,无法取出样本"); + } + + // 从加热盘移动到液体盘 var moveTubeRackFromHeatPlateToLiquidPlate = new MoveMoveTubeRackFromHeatPlateToLiquidPlate(); moveTubeRackFromHeatPlateToLiquidPlate.slotIndex = this.slotIndex; moveTubeRackFromHeatPlateToLiquidPlate.setDevice(this.getDevice()); moveTubeRackFromHeatPlateToLiquidPlate.run(); + // 打开设备门 + DiActMotor doorMotor = this.getActuator(MyDevice.ACT_DOOR_MOTOR, DiActMotor.class); + doorMotor.reset(); + + // 等待用户取出确认 + this.waitForUserTakeOutConfirm(); + + // 关闭设备门 + doorMotor.moveToIO(1, 1); + slot.unlock(); this.setStatus(TaskStatus.FINISHED); } + + // wait for user action + private void waitForUserTakeOutConfirm() { + this.setRuntimeStatus("WAIT_FOR_TAKING_CONFIRM"); + synchronized (this.confirmLock) { + try { + this.confirmLock.wait(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + this.clearRuntimeStatus(); + } + + // tube rack take out confirm + public void done() { + synchronized (this.confirmLock) { + this.confirmLock.notifyAll(); + } + } }