package com.mes.step; import com.mes.core.StationContext; import com.mes.device.IDeviceDriver; /** * 设备启动步骤 * 向PLC发送启动信号/就绪信号 * 注意:心跳启动已移至单独的 StartHeartbeatStep */ public class DeviceStartStep extends AbstractStep { public DeviceStartStep() { super("device_start", "启动设备"); this.async = false; this.requiresUserInteraction = false; } @Override public boolean execute(StationContext context) { // 检查设备是否启用 if (!context.isDeviceEnabled()) { log.info("[{}] 设备未启用,跳过设备启动", context.getStationCode()); return true; } IDeviceDriver driver = context.getDeviceDriver(); if (driver == null) { log.warn("[{}] 设备驱动未配置", context.getStationCode()); return true; // 无设备时跳过 } try { // 发送就绪/启动信号 driver.signalReady(); log.info("[{}] 设备启动信号已发送", context.getStationCode()); context.setStatusMessage("设备已启动", 0); return true; } catch (Exception e) { log.error("[{}] 设备启动失败: {}", context.getStationCode(), e.getMessage(), e); context.setStatusMessage("设备启动失败: " + e.getMessage(), -1); return false; } } @Override public boolean canExecute(StationContext context) { // 质量检查通过才能启动设备 return context.isQualityPassed(); } @Override public boolean canSkip(StationContext context) { // 设备未启用时跳过 return !context.isDeviceEnabled(); } @Override public void onSkip(StationContext context) { log.info("[{}] 设备启动步骤已跳过(设备未启用)", context.getStationCode()); } }