diff --git a/src/main/java/a8k/appbean/HardwareException.java b/src/main/java/a8k/appbean/HardwareException.java index 81cd939..7fa3fcf 100644 --- a/src/main/java/a8k/appbean/HardwareException.java +++ b/src/main/java/a8k/appbean/HardwareException.java @@ -19,11 +19,12 @@ public class HardwareException extends Exception { this.moduleId = moduleId; } - int getModuleId() { + public int getModuleId() { return moduleId; } public int getErrorCode() { return errorCode; } + } diff --git a/src/main/java/a8k/appbean/ecode/AppEcode.java b/src/main/java/a8k/appbean/ecode/AppEcode.java index f834c36..db5699f 100644 --- a/src/main/java/a8k/appbean/ecode/AppEcode.java +++ b/src/main/java/a8k/appbean/ecode/AppEcode.java @@ -2,10 +2,11 @@ package a8k.appbean.ecode; import a8k.a8k_can_protocol.MId; import a8k.a8k_can_protocol.A8kEcode; +import a8k.appbean.HardwareException; public class AppEcode { public A8kEcode errorCode; - public MId mid; + public MId mid; public AppEcode(A8kEcode errorCode, MId mid) { @@ -13,6 +14,11 @@ public class AppEcode { this.mid = mid; } + public AppEcode(HardwareException e) { + this.errorCode = A8kEcode.valueOf(e.getErrorCode()); + this.mid = MId.valueOf(e.getModuleId()); + } + public AppEcode(A8kEcode errorCode) { this.errorCode = errorCode; this.mid = MId.NotSet; diff --git a/src/main/java/a8k/service/ctrl_service/DeviceInitializationCtrlService.java b/src/main/java/a8k/service/ctrl_service/DeviceInitializationCtrlService.java index bc7f990..e1af2e4 100644 --- a/src/main/java/a8k/service/ctrl_service/DeviceInitializationCtrlService.java +++ b/src/main/java/a8k/service/ctrl_service/DeviceInitializationCtrlService.java @@ -7,6 +7,7 @@ import a8k.appbean.HardwareException; import a8k.appbean.ecode.AppEcode; import a8k.base_hardware.A8kCanBusService; import a8k.service.db.dao.SamplesPreProcessModuleCtrlParamsService; +import a8k.service.hardware.CommonHardwareOpeartion; import jakarta.annotation.Resource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,6 +25,9 @@ public class DeviceInitializationCtrlService { A8kCanBusService canBus; @Resource + CommonHardwareOpeartion hardwareOpeartion; + + @Resource SamplesPreProcessModuleCtrlParamsService samplesPreProcessModuleCtrlParams; @@ -35,6 +39,7 @@ public class DeviceInitializationCtrlService { * 3.使能所有电机 */ + hardwareOpeartion.enableAllMotor(); //打开必要的电源 canBus.setIOState(IOId.RecycleBinOverflowPPSPowerCtrl, true); @@ -165,10 +170,10 @@ public class DeviceInitializationCtrlService { } //复位设备 - // ecode = moveMotorToZero(); - // if (!ecode.isOk()) { - // return ecode; - // } + ecode = moveMotorToZero(); + if (!ecode.isOk()) { + return ecode; + } //清空耗材 @@ -177,11 +182,17 @@ public class DeviceInitializationCtrlService { logger.error("HardwareException %s", e); throw new RuntimeException(e); } catch (InterruptedException e) { - logger.error("InterruptedException"); + logger.error("InterruptedException", e); throw new RuntimeException(e); + } finally { + try { + canBus.stepMotorEnable(MId.ShakeModClampingM, 1); + canBus.stepMotorEasyMoveBy(MId.ShakeModClampingM, 2); + canBus.waitForMod(MId.ShakeModClampingM, actionOvertime); + } catch (HardwareException | InterruptedException ignored) { + } } - return new AppEcode(A8kEcode.Success); } diff --git a/src/main/java/a8k/service/hardware/CommonHardwareOpeartion.java b/src/main/java/a8k/service/hardware/CommonHardwareOpeartion.java new file mode 100644 index 0000000..a575990 --- /dev/null +++ b/src/main/java/a8k/service/hardware/CommonHardwareOpeartion.java @@ -0,0 +1,126 @@ +package a8k.service.hardware; + +import a8k.a8k_can_protocol.A8kEcode; +import a8k.a8k_can_protocol.MId; +import a8k.appbean.HardwareException; +import a8k.appbean.ecode.AppEcode; +import a8k.base_hardware.A8kCanBusService; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Component; + +@Component +public class CommonHardwareOpeartion { + + + @Resource + A8kCanBusService canBus; + + public AppEcode enableAllMotorNoExcep() { + try { + enableAllMotor(); + } catch (HardwareException e) { + return new AppEcode(e); + } + return new AppEcode(A8kEcode.Success); + } + + public AppEcode disableAllMotorNoExcep() { + try { + enableAllMotor(); + } catch (HardwareException e) { + return new AppEcode(e); + } + return new AppEcode(A8kEcode.Success); + } + + public void enableAllMotor() throws HardwareException { + //进出料初始化 + canBus.stepMotorEnable(MId.FeedingModInfeedM, 1); + canBus.stepMotorEnable(MId.FeedingModXM, 1); + canBus.stepMotorEnable(MId.FeedingModOutfeedM, 1); + + //摇匀模组初始化 + canBus.stepMotorEnable(MId.ShakeModClampingM, 1); + canBus.stepMotorEnable(MId.ShakeModGripperZM, 1); + canBus.stepMotorEnable(MId.ShakeModShakeM, 1); + canBus.miniServoEnable(MId.ShakeModGripperYM, 1); + canBus.miniServoEnable(MId.ShakeModGripperSV, 1); + canBus.miniServoEnable(MId.ShakeModTubeScanerClampingSV, 1); + canBus.miniServoEnable(MId.ShakeModTubeScanerRotateSV, 1); + + //板夹仓初始化 + canBus.stepMotorEnable(MId.PlatesBoxYM, 1); + canBus.stepMotorEnable(MId.PlatesBoxPusherM, 1); + + //光学模组初始化 + canBus.stepMotorEnable(MId.OptModPullM, 1); + canBus.stepMotorEnable(MId.OptModScannerM, 1); + + //HBot初始化 + canBus.stepMotorEnable(MId.HbotM, 1); + canBus.stepMotorEnable(MId.PipetteModZM, 1); + + //转盘归零 + canBus.stepMotorEnable(MId.IncubatorRotateCtrlM, 1); + + } + + public void disableAllMotor() throws HardwareException { + //进出料初始化 + canBus.stepMotorEnable(MId.FeedingModInfeedM, 0); + canBus.stepMotorEnable(MId.FeedingModXM, 0); + canBus.stepMotorEnable(MId.FeedingModOutfeedM, 0); + + //摇匀模组初始化 + canBus.stepMotorEnable(MId.ShakeModClampingM, 0); + canBus.stepMotorEnable(MId.ShakeModGripperZM, 0); + canBus.stepMotorEnable(MId.ShakeModShakeM, 0); + canBus.miniServoEnable(MId.ShakeModGripperYM, 0); + canBus.miniServoEnable(MId.ShakeModGripperSV, 0); + canBus.miniServoEnable(MId.ShakeModTubeScanerClampingSV, 0); + canBus.miniServoEnable(MId.ShakeModTubeScanerRotateSV, 0); + + //板夹仓初始化 + canBus.stepMotorEnable(MId.PlatesBoxYM, 0); + canBus.stepMotorEnable(MId.PlatesBoxPusherM, 0); + + //光学模组初始化 + canBus.stepMotorEnable(MId.OptModPullM, 0); + canBus.stepMotorEnable(MId.OptModScannerM, 0); + + //HBot初始化 + canBus.stepMotorEnable(MId.HbotM, 0); + canBus.stepMotorEnable(MId.PipetteModZM, 0); + + //转盘归零 + canBus.stepMotorEnable(MId.IncubatorRotateCtrlM, 0); + + } + + public void stopAllMOtor() { + //进出料初始化 + try {canBus.moduleStop(MId.FeedingModInfeedM);} catch (HardwareException ignored) {} + try {canBus.moduleStop(MId.FeedingModXM);} catch (HardwareException ignored) {} + try {canBus.moduleStop(MId.FeedingModOutfeedM);} catch (HardwareException ignored) {} + //摇匀模组初始化 + try {canBus.moduleStop(MId.ShakeModClampingM);} catch (HardwareException ignored) {} + try {canBus.moduleStop(MId.ShakeModGripperZM);} catch (HardwareException ignored) {} + try {canBus.moduleStop(MId.ShakeModShakeM);} catch (HardwareException ignored) {} + try {canBus.moduleStop(MId.ShakeModGripperYM);} catch (HardwareException ignored) {} + try {canBus.moduleStop(MId.ShakeModGripperSV);} catch (HardwareException ignored) {} + try {canBus.moduleStop(MId.ShakeModTubeScanerClampingSV);} catch (HardwareException ignored) {} + try {canBus.moduleStop(MId.ShakeModTubeScanerRotateSV);} catch (HardwareException ignored) {} + //板夹仓初始化 + try {canBus.moduleStop(MId.PlatesBoxYM);} catch (HardwareException ignored) {} + try {canBus.moduleStop(MId.PlatesBoxPusherM);} catch (HardwareException ignored) {} + //光学模组初始化 + try {canBus.moduleStop(MId.OptModPullM);} catch (HardwareException ignored) {} + try {canBus.moduleStop(MId.OptModScannerM);} catch (HardwareException ignored) {} + //HBot初始化 + try {canBus.moduleStop(MId.HbotM);} catch (HardwareException ignored) {} + try {canBus.moduleStop(MId.PipetteModZM);} catch (HardwareException ignored) {} + //转盘归零 + try {canBus.moduleStop(MId.IncubatorRotateCtrlM);} catch (HardwareException ignored) {} + + } +} diff --git a/zhaohe_app.db b/zhaohe_app.db index 5fd87a8..628a149 100644 Binary files a/zhaohe_app.db and b/zhaohe_app.db differ