// WeldingCommon/Devices/ACS/ScannerACS.cs using Aurora; using Aurora.Api; using Aurora.Api.Devices; using Aurora.Util.HislogPlus; using AuroraACS; using ACS.SPiiPlusNET; using Hermes; using System.Windows; using WeldingCommon.Device.ACS; using WeldingCommon.Settings; namespace WeldingCommon.Devices.ACS { public interface IScannerACS { bool IsActivated(); // 홈 bool AllAxisHomeStart(); bool AllAxisHomeStop(); bool CheckAllAxisHome(); // MOTF bool MOTFStart(); bool MOTFStop(); bool CheckMOTFComp(); // 레이저 bool SetLaserIOUse(bool on); bool IsLaserOn(); // 알람 bool ResetAlarm(); void AllAxisServoOff(); } public partial class ScannerACS : ACSDevice, IScannerACS { // TODO: Scanner용 Setting ID 확정 후 교체 private ACSDeviceSetting _setting; private ACSMotor MotorStageX; // AxisX2 = Scanner Stage X public MotionVariable _motorVariable; public bool HasHeavyAlarm { get; private set; } public bool HasLightAlarm { get; private set; } public int[] HaveAlarmCodes { get => _HaveAlarmCodes; } private int[] _HaveAlarmCodes = new int[11]; public ScannerACS(bool isSimulation, bool useTerminateUMD = false) : base(isSimulation, useTerminateUMD) { _motorVariable = new MotionVariable(); } protected override int DoActivate(IDeviceConfig config) { if (base.DoActivate(config) != E1.OK) return E2.ABORTED; var env = Application.Current.AuroraEnv(); // TODO: Scanner용 SettingIds 확정 후 교체 // _setting = env.SettingEntry[ScannerSettingIds.ACS] as ACSDeviceSetting; // Stage X 모터 취득 (null-safe) // TODO: 이정인 선임 변수 맵 수신 후 축 번호 검증 try { MotorStageX = env.DeviceManager[CommonDeviceIds.AxisX2] as ACSMotor; } catch { MotorStageX = null; } SetMonitoringService(UpdateACSParam, 50); StartMonitoringService(); return E1.OK; } private void UpdateACSParam() { // Stage X 상태 갱신 if (MotorStageX != null) { _motorVariable.X2AxisPosition = MotorStageX.GetActualPos(); _motorVariable.X2InPosition = MotorStageX.IsInpos(); _motorVariable.X2AxisVelocity = MotorStageX.GetFeedbackVelocity(); _motorVariable.X2AxisAcceleration = MotorStageX.GetAcceleration(); _motorVariable.IsHome = MotorStageX.GetServoStatus() == 1; } // 알람 상태 갱신 HasHeavyAlarm = ReadVariableInt(HeavyAlarm) == 1; HasLightAlarm = ReadVariableInt(LightAlarm) == 1; ReadVariableIntArrRef(AlarmCodes, ref _HaveAlarmCodes, ProgramBuffer.ACSC_NONE, 0, 10); } protected override int DoDeactivate() { StopMonitoringService(); return base.DoDeactivate(); } // ── 홈 ─────────────────────────────────────────── bool IScannerACS.AllAxisHomeStart() { if (RunBuffer((ProgramBuffer)eBuffer.All_Axis_Home)) { Log.D("AllAxisHomeStart >> Complete"); return true; } Log.D("AllAxisHomeStart >> Fail"); return false; } bool IScannerACS.AllAxisHomeStop() { StopBuffer((ProgramBuffer)eBuffer.All_Axis_Home); Log.D("AllAxisHomeStop >> Complete"); return true; } bool IScannerACS.CheckAllAxisHome() => ReadVariableInt(iAllAxisHomeComplete) > 0; // ── MOTF ───────────────────────────────────────── // TODO: 이정인 선임 변수 맵 수신 후 버퍼 번호 및 변수명 교체 bool IScannerACS.MOTFStart() { if (IsSimul) return true; if (RunBuffer((ProgramBuffer)eBuffer.MOTF_Start)) { Log.I("MOTFStart >> Complete"); return true; } Log.D("MOTFStart >> Fail"); return false; } bool IScannerACS.MOTFStop() { StopBuffer((ProgramBuffer)eBuffer.MOTF_Start); Log.D("MOTFStop >> Complete"); return true; } bool IScannerACS.CheckMOTFComp() { if (IsSimul) return true; return ReadVariableInt(iMOTFComplete) > 0; } // ── 레이저 ─────────────────────────────────────── bool IScannerACS.SetLaserIOUse(bool on) { if (WriteRealVariable(iLaserUse, on ? 1 : 0)) { Log.D($"SetLaserIOUse {on} >> Complete"); return true; } Log.D("SetLaserIOUse >> Fail"); return false; } bool IScannerACS.IsLaserOn() { if (!IsActivated || !IsConnected) return false; return ReadVariableInt(IsLaserOn) > 0; } // ── 알람 ───────────────────────────────────────── bool IScannerACS.ResetAlarm() { TerminalCommand("FCLEAR ALL"); return WriteVariableInt(AlarmReset, 1); } void IScannerACS.AllAxisServoOff() { if (!IsActivated || !IsConnected) return; SetMotorDisableAll(); } bool IScannerACS.IsActivated() => IsActivated; } }