69 lines
2.3 KiB
C#
69 lines
2.3 KiB
C#
using System;
|
|
using XP.Hardware.MotionControl.Abstractions;
|
|
using XP.Hardware.MotionControl.Abstractions.Enums;
|
|
using XP.Hardware.MotionControl.Config;
|
|
using XP.Hardware.Plc.Abstractions;
|
|
|
|
namespace XP.Hardware.MotionControl.Implementations
|
|
{
|
|
/// <summary>
|
|
/// 基于 PLC 的安全门实现 | PLC-based Safety Door Implementation
|
|
/// 信号名称硬编码在 MotionSignalNames 中 | Signal names hardcoded in MotionSignalNames
|
|
/// </summary>
|
|
public class PlcSafetyDoor : SafetyDoorBase
|
|
{
|
|
private readonly ISignalDataService _signalService;
|
|
private bool _isInterlocked;
|
|
|
|
public PlcSafetyDoor(ISignalDataService signalService)
|
|
{
|
|
_signalService = signalService ?? throw new ArgumentNullException(nameof(signalService));
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public override bool IsInterlocked => _isInterlocked;
|
|
|
|
/// <inheritdoc/>
|
|
public override MotionResult Open()
|
|
{
|
|
if (IsInterlocked)
|
|
return MotionResult.Fail("联锁信号有效,禁止开门 | Interlock active, door open blocked");
|
|
_signalService.EnqueueWrite(MotionSignalNames.Door_Open, true);
|
|
_status = DoorStatus.Opening;
|
|
return MotionResult.Ok();
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public override MotionResult Close()
|
|
{
|
|
_signalService.EnqueueWrite(MotionSignalNames.Door_Close, true);
|
|
_status = DoorStatus.Closing;
|
|
return MotionResult.Ok();
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public override MotionResult Stop()
|
|
{
|
|
_signalService.EnqueueWrite(MotionSignalNames.Door_Stop, true);
|
|
return MotionResult.Ok();
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public override void UpdateStatus()
|
|
{
|
|
_isInterlocked = _signalService.GetValueByName<byte>(MotionSignalNames.Door_Interlock) == 10;
|
|
var statusValue = _signalService.GetValueByName<int>(MotionSignalNames.Door_Status);
|
|
_status = statusValue switch
|
|
{
|
|
1 => DoorStatus.Opening,
|
|
2 => DoorStatus.Open,
|
|
3 => DoorStatus.Closing,
|
|
4 => DoorStatus.Closed,
|
|
5 => DoorStatus.Locked,
|
|
6 => DoorStatus.Error,
|
|
_ => DoorStatus.Unknown
|
|
};
|
|
}
|
|
}
|
|
}
|