38 lines
1.4 KiB
C#
38 lines
1.4 KiB
C#
using RobotNet.VDA5050.Type;
|
|
using RobotNet10.RobotApp.Interfaces;
|
|
|
|
namespace RobotNet10.RobotApp.Services.Robot.Actions;
|
|
|
|
[RobotAction(ActionType.MUTED_LOAD_OFF,
|
|
[ActionScope.INSTANT, ActionScope.NODE, ActionScope.EDGE],
|
|
[BlockingType.NONE, BlockingType.SOFT, BlockingType.HARD],
|
|
"Tắt chế độ muted load robot.",
|
|
"Robot đã tắt chế độ muted load.")]
|
|
public class RobotMutedLoadOffAction(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.SetMutedLoad(false);
|
|
return base.StartAction();
|
|
}
|
|
|
|
protected override Task ExecuteAction()
|
|
{
|
|
if (PlcController is not null && !PlcController.MutedLoad)
|
|
{
|
|
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();
|
|
}
|
|
}
|