Files
BQP/srcs/RobotNet10/RobotApp/RobotNet10.RobotApp/Services/Robot/Actions/CameraLightOffAction.cs
2026-07-13 09:25:40 +07:00

45 lines
1.5 KiB
C#

using RobotNet.VDA5050.Type;
using RobotNet10.RobotApp.Interfaces;
namespace RobotNet10.RobotApp.Services.Robot.Actions;
/// <summary>
/// Tắt đèn camera (M918 - Light on OFF).
/// </summary>
[RobotAction(ActionType.CAMERA_LIGHT_OFF,
[ActionScope.INSTANT, ActionScope.NODE, ActionScope.EDGE],
[BlockingType.NONE, BlockingType.SOFT, BlockingType.HARD],
"Tắt đèn camera (M918 Light on OFF).",
"Đèn camera đã tắt (M918 Light on OFF).")]
public class CameraLightOffAction(IServiceProvider ServiceProvider) : RobotAction(ServiceProvider)
{
private IPlcController? PlcController;
private const int MAX_TIMEOUT = 4000;
private int CountTimeout = 0;
protected override Task StartAction()
{
PlcController = ServiceProvider.GetRequiredService<IPlcController>();
PlcController.SetLightOn(false); // M918 Light on OFF
return base.StartAction();
}
protected override Task ExecuteAction()
{
if (PlcController is not null && !PlcController.SetLightOnValue)
{
SetStatus(ActionEvent.FINISHED);
ResultDescription = string.IsNullOrEmpty(ActionAttribute.ResultDescription) ? ResultDescription : ActionAttribute.ResultDescription;
}
else if (CountTimeout++ > MAX_TIMEOUT / ActionInterval)
{
SetStatus(ActionEvent.FAILED);
ResultDescription = "Timeout action";
}
return base.ExecuteAction();
}
}