DeviceStartStep.java 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package com.mes.step;
  2. import com.mes.core.StationContext;
  3. import com.mes.device.IDeviceDriver;
  4. /**
  5. * 设备启动步骤
  6. * 向PLC发送启动信号/就绪信号
  7. * 注意:心跳启动已移至单独的 StartHeartbeatStep
  8. */
  9. public class DeviceStartStep extends AbstractStep {
  10. public DeviceStartStep() {
  11. super("device_start", "启动设备");
  12. this.async = false;
  13. this.requiresUserInteraction = false;
  14. }
  15. @Override
  16. public boolean execute(StationContext context) {
  17. // 检查设备是否启用
  18. if (!context.isDeviceEnabled()) {
  19. log.info("[{}] 设备未启用,跳过设备启动", context.getStationCode());
  20. return true;
  21. }
  22. IDeviceDriver driver = context.getDeviceDriver();
  23. if (driver == null) {
  24. log.warn("[{}] 设备驱动未配置", context.getStationCode());
  25. return true; // 无设备时跳过
  26. }
  27. try {
  28. // 发送就绪/启动信号
  29. driver.signalReady();
  30. log.info("[{}] 设备启动信号已发送", context.getStationCode());
  31. context.setStatusMessage("设备已启动", 0);
  32. return true;
  33. } catch (Exception e) {
  34. log.error("[{}] 设备启动失败: {}", context.getStationCode(), e.getMessage(), e);
  35. context.setStatusMessage("设备启动失败: " + e.getMessage(), -1);
  36. return false;
  37. }
  38. }
  39. @Override
  40. public boolean canExecute(StationContext context) {
  41. // 质量检查通过才能启动设备
  42. return context.isQualityPassed();
  43. }
  44. @Override
  45. public boolean canSkip(StationContext context) {
  46. // 设备未启用时跳过
  47. return !context.isDeviceEnabled();
  48. }
  49. @Override
  50. public void onSkip(StationContext context) {
  51. log.info("[{}] 设备启动步骤已跳过(设备未启用)", context.getStationCode());
  52. }
  53. }