|
|
@ -20,8 +20,6 @@ import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.concurrent.ArrayBlockingQueue; |
|
|
|
import java.util.concurrent.BlockingQueue; |
|
|
|
import java.util.concurrent.locks.Lock; |
|
|
|
import java.util.concurrent.locks.ReentrantLock; |
|
|
|
|
|
|
|
/** |
|
|
|
* 加液模块 |
|
|
@ -35,7 +33,6 @@ public class SolutionModuleService { |
|
|
|
private final LiquidDistributionArmDriver liquidDistributionArmDriver; |
|
|
|
private final WebSocketSender webSocketService; |
|
|
|
|
|
|
|
private final Lock moduleLock = new ReentrantLock(); |
|
|
|
private final BlockingQueue<Thread> waitingQueue = new ArrayBlockingQueue<>(1); |
|
|
|
|
|
|
|
/** |
|
|
@ -48,8 +45,9 @@ public class SolutionModuleService { |
|
|
|
/** |
|
|
|
* 申请使用加液模块 |
|
|
|
*/ |
|
|
|
public void requestSolutionModule(String commandId, String command) { |
|
|
|
public synchronized void requestSolutionModule(String commandId, String command) { |
|
|
|
try { |
|
|
|
log.info("申请使用加液模块"); |
|
|
|
// 如果加液模块繁忙,加入队列等待 |
|
|
|
while (!deviceStateService.getDeviceState().getSolutionModule().isIdle()) { |
|
|
|
if (commandId != null && command != null) { |
|
|
@ -59,7 +57,8 @@ public class SolutionModuleService { |
|
|
|
// 把当前线程放到队列中等待 |
|
|
|
waitingQueue.put(Thread.currentThread()); // 阻塞当前线程直到被唤醒 |
|
|
|
} |
|
|
|
occupySolutionModule(); |
|
|
|
deviceStateService.getDeviceState().getSolutionModule().setIdle(false); |
|
|
|
log.info("加液模块申请成功"); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
Thread.currentThread().interrupt(); |
|
|
|
throw new RuntimeException("等待加液区空闲错误", e); |
|
|
@ -67,18 +66,9 @@ public class SolutionModuleService { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 占用加液模块 |
|
|
|
*/ |
|
|
|
private void occupySolutionModule() { |
|
|
|
moduleLock.lock(); |
|
|
|
deviceStateService.getDeviceState().getSolutionModule().setIdle(false); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 释放加液区 |
|
|
|
*/ |
|
|
|
public void releaseSolutionModule() throws InterruptedException { |
|
|
|
try { |
|
|
|
public synchronized void releaseSolutionModule() throws InterruptedException { |
|
|
|
deviceStateService.getDeviceState().getSolutionModule().setIdle(true); |
|
|
|
// 唤醒队列中的第一个线程 |
|
|
|
if (!waitingQueue.isEmpty()) { |
|
|
@ -87,29 +77,21 @@ public class SolutionModuleService { |
|
|
|
waitingThread.notify(); // 唤醒队列中的第一个等待线程 |
|
|
|
} |
|
|
|
} |
|
|
|
} finally { |
|
|
|
if (moduleLock.tryLock()) { |
|
|
|
moduleLock.unlock(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public boolean getModuleLockTryLock(){ |
|
|
|
return moduleLock.tryLock(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 双轴械臂 移动至指定试管 |
|
|
|
*/ |
|
|
|
public void dualRobotMovePoint(int index) throws Exception { |
|
|
|
liquidDistributionArmDriver.liquidDistributionArmMoveTo(LiquidArmMId.LiquidDistributionArm, index); |
|
|
|
liquidDistributionArmDriver.liquidDistributionArmMoveToBlock(LiquidArmMId.LiquidDistributionArm, index); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 加液机械臂回原点 |
|
|
|
*/ |
|
|
|
public void dualRobotOrigin() throws Exception { |
|
|
|
liquidDistributionArmDriver.liquidDistributionArmMoveTo(LiquidArmMId.LiquidDistributionArm, 0); |
|
|
|
liquidDistributionArmDriver.liquidDistributionArmMoveToBlock(LiquidArmMId.LiquidDistributionArm, 0); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -210,7 +192,7 @@ public class SolutionModuleService { |
|
|
|
/** |
|
|
|
* 添加溶液 |
|
|
|
*/ |
|
|
|
public void acidPumpMoveBy(String commandId, String command, AcidPumpDeviceCode acidPumpDevice, double position) throws Exception { |
|
|
|
public CommandFuture acidPumpMoveBy(String commandId, String command, AcidPumpDeviceCode acidPumpDevice, double position) throws Exception { |
|
|
|
DeviceCommandBundle deviceCommand; |
|
|
|
switch (acidPumpDevice) { |
|
|
|
case acid_pump_01 -> { |
|
|
@ -239,8 +221,7 @@ public class SolutionModuleService { |
|
|
|
} |
|
|
|
default -> throw new RuntimeException("index 未找到"); |
|
|
|
} |
|
|
|
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(commandId, command, deviceCommand); |
|
|
|
CommandUtil.wait(deviceCommandFuture); |
|
|
|
return deviceCommandService.sendCommand(commandId, command, deviceCommand); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|