@layout Layout.HMILayout @page "/sehc/da3/line1" @using Microsoft.AspNetCore.SignalR.Client @using RobotNet.Script.Shares @using RobotNet.WebApp.Clients @attribute [Authorize] @implements IAsyncDisposable @inject HMIHubClient hmiClient @inject ISnackbar Snackbar @inject IDialogService Dialog
STEP NUMBER
@Line1_HMI_Model.SEHCMissionStep
Trolley
CONNECTING ...
WAIT FOR RUNNING ...
@code { private bool DisableControl = true; private bool DisableProcess => !DisableControl && processorState != ProcessorState.Running; private ProcessorState processorState = ProcessorState.Idle; private string hmiBtnResetStepClass => $"{(Line1_HMI_Model.Request_Reset_SEHC_DA3_Line1 ? "inactive" : "")}"; private string hmiBtnIsWorkingClass => $"{(Line1_HMI_Model.IsWorking ? "" : "inactive")}"; private string hmiBtnHasEmptyTrolleyClass => $"{(Line1_HMI_Model.Has_Empty_Trolley ? "" : "inactive")}"; private string hmiBtnGoHomeClass => $"{(Line1_HMI_Model.Request_GoHome ? "inactive" : "")}"; private string hmiBtnEnAutoAClass => $"{(Line1_HMI_Model.EnableAutoA ? "" : "off")}"; private string hmiBtnInAClass => $"{(Line1_HMI_Model.EnableAutoA ? "inactive" : "")} {(Line1_HMI_Model.Req_In_A ? "" : "off")}"; private string hmiBtnInBesideAClass => $"{(Line1_HMI_Model.EnableAutoA ? "inactive" : "")} {(Line1_HMI_Model.Req_In_Beside_A ? "" : "off")}"; private string hmiBtnCloseAClass => $"{(Line1_HMI_Model.EnableAutoA ? "inactive" : "")} {(Line1_HMI_Model.Req_Close_Cylinder_A ? "" : "off")}"; private string hmiBtnEnAutoBClass => $"{(Line1_HMI_Model.EnableAutoB ? "" : "off")}"; private string hmiBtnInBClass => $"{(Line1_HMI_Model.EnableAutoB ? "inactive" : "")} {(Line1_HMI_Model.Req_In_B ? "" : "off")}"; private string hmiBtnInBesideBClass => $"{(Line1_HMI_Model.EnableAutoB ? "inactive" : "")} {(Line1_HMI_Model.Req_In_Beside_B ? "" : "off")}"; private string hmiBtnCloseBClass => $"{(Line1_HMI_Model.EnableAutoB ? "inactive" : "")} {(Line1_HMI_Model.Req_Close_Cylinder_B ? "" : "off")}"; private string cylinderStateAClass => $"{(Line1_HMI_Model.Cylinder_Opened_A ? "" : "led-indicator")}"; private string cylinderStateBClass => $"{(Line1_HMI_Model.Cylinder_Opened_B ? "" : "led-indicator")}"; private string trolleyAClass => $"{(Line1_HMI_Model.Empty_A ? "trolley-inactive" : "")}"; private string trolleyBClass => $"{(Line1_HMI_Model.Empty_B ? "trolley-inactive" : "")}"; private string trolleyFullClass => $"{(Line1_HMI_Model.AGV_Push_Noti_Mem ? "" : "trolley-inactive")}"; private string indicatorAClass => GetIndicatorAClass(); private string indicatorBClass => GetIndicatorBClass(); private string amrReadyUndockAClass => $"{(Line1_HMI_Model.AMR_Ready_Undock_A ? "" : "image-inactive")}"; private string amrReadyUndockBClass => $"{(Line1_HMI_Model.AMR_Ready_Undock_B ? "" : "image-inactive")}"; private string amrInAClass => $"{(Line1_HMI_Model.AMR_In_Station_A ? "" : "image-inactive")}"; private string amrInBClass => $"{(Line1_HMI_Model.AMR_In_Station_B ? "" : "image-inactive")}"; private string accessInAClass => Line1_HMI_Model.Access_In_A ? "access-allowed" : "access-denied"; private string accessInBClass => Line1_HMI_Model.Access_In_B ? "access-allowed" : "access-denied"; private string accessInBesideAClass => Line1_HMI_Model.Access_In_Beside_A ? "access-allowed" : "access-denied"; private string accessInBesideBClass => Line1_HMI_Model.Access_In_Beside_B ? "access-allowed" : "access-denied"; private SEHC_DA3_Line1_HMI_Model Line1_HMI_Model; IDictionary SyncVariables = new Dictionary() { {nameof(SEHC_DA3_Line1_HMI_Model.IsWorking), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.SEHCMissionStep), "-1" }, {nameof(SEHC_DA3_Line1_HMI_Model.EnableAutoA), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.EnableAutoB), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.Request_Reset_SEHC_DA3_Line1), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.AMR_In_Station_A), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.AMR_In_Station_B), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.AMR_Ready_Undock_A), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.AMR_Ready_Undock_B), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.Req_In_A), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.Req_In_B), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.Req_In_Beside_A), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.Req_In_Beside_B), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.Req_Close_Cylinder_A), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.Req_Close_Cylinder_B), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.Robot_Working_A), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.Robot_Working_B), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.Empty_A), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.Empty_B), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.Cylinder_Opened_A), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.Cylinder_Opened_B), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.Access_In_A), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.Access_In_B), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.Access_In_Beside_A), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.Access_In_Beside_B), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.AGV_Push_Noti_Mem), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.Has_Empty_Trolley), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.MoveTrolleyInStationA), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.MoveTrolleyInStationB), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.MoveTrolleyOutStationA), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.MoveTrolleyOutStationB), bool.FalseString }, {nameof(SEHC_DA3_Line1_HMI_Model.Request_GoHome), bool.FalseString }, }; System.Timers.Timer timer = new System.Timers.Timer(300) { AutoReset = true, }; protected override async Task OnInitializedAsync() { timer.Elapsed += OnTimerElapsed; hmiClient.ConnectionStateChanged += OnConnectionStateChanged; hmiClient.StateChanged += OnProcessStateChanged; await hmiClient.StartAsync(); timer.Start(); OnProcessStateChanged(await hmiClient.GetState()); await base.OnInitializedAsync(); } void OnConnectionStateChanged(HubConnectionState state) { Console.WriteLine($"HubConnectionState={state}"); DisableControl = state != HubConnectionState.Connected; StateHasChanged(); } void OnProcessStateChanged(ProcessorState state) { processorState = state; if (state == ProcessorState.Running) { if (!timer.Enabled) { timer.Start(); } } else if (timer.Enabled) { timer.Stop(); } StateHasChanged(); } void OnTimerElapsed(object? sender, System.Timers.ElapsedEventArgs e) { InvokeAsync(async Task () => { var variables = await hmiClient.GetVariables(SyncVariables.Keys); foreach (var key in variables.Keys) { SyncVariables[key] = variables[key]; } Line1_HMI_Model.IsWorking = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.IsWorking)]); Line1_HMI_Model.SEHCMissionStep = int.TryParse(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.SEHCMissionStep)], out int step) ? step : -1; Line1_HMI_Model.EnableAutoA = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.EnableAutoA)]); Line1_HMI_Model.EnableAutoB = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.EnableAutoB)]); Line1_HMI_Model.Request_Reset_SEHC_DA3_Line1 = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Request_Reset_SEHC_DA3_Line1)]); Line1_HMI_Model.AMR_In_Station_A = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.AMR_In_Station_A)]); Line1_HMI_Model.AMR_In_Station_B = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.AMR_In_Station_B)]); Line1_HMI_Model.AMR_Ready_Undock_A = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.AMR_Ready_Undock_A)]); Line1_HMI_Model.AMR_Ready_Undock_B = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.AMR_Ready_Undock_B)]); Line1_HMI_Model.Req_In_A = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Req_In_A)]); Line1_HMI_Model.Req_In_B = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Req_In_B)]); Line1_HMI_Model.Req_In_Beside_A = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Req_In_Beside_A)]); Line1_HMI_Model.Req_In_Beside_B = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Req_In_Beside_B)]); Line1_HMI_Model.Req_Close_Cylinder_A = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Req_Close_Cylinder_A)]); Line1_HMI_Model.Req_Close_Cylinder_B = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Req_Close_Cylinder_B)]); Line1_HMI_Model.Robot_Working_A = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Robot_Working_A)]); Line1_HMI_Model.Robot_Working_B = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Robot_Working_B)]); Line1_HMI_Model.Empty_A = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Empty_A)]); Line1_HMI_Model.Empty_B = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Empty_B)]); Line1_HMI_Model.Cylinder_Opened_A = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Cylinder_Opened_A)]); Line1_HMI_Model.Cylinder_Opened_B = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Cylinder_Opened_B)]); Line1_HMI_Model.Access_In_A = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Access_In_A)]); Line1_HMI_Model.Access_In_B = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Access_In_B)]); Line1_HMI_Model.Access_In_Beside_A = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Access_In_Beside_A)]); Line1_HMI_Model.Access_In_Beside_B = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Access_In_Beside_B)]); Line1_HMI_Model.AGV_Push_Noti_Mem = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.AGV_Push_Noti_Mem)]); Line1_HMI_Model.Has_Empty_Trolley = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Has_Empty_Trolley)]); Line1_HMI_Model.MoveTrolleyInStationA = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.MoveTrolleyInStationA)]); Line1_HMI_Model.MoveTrolleyInStationB = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.MoveTrolleyInStationB)]); Line1_HMI_Model.MoveTrolleyOutStationA = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.MoveTrolleyOutStationA)]); Line1_HMI_Model.MoveTrolleyOutStationB = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.MoveTrolleyOutStationB)]); Line1_HMI_Model.Request_GoHome = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Request_GoHome)]); StateHasChanged(); }).ConfigureAwait(false); } string GetIndicatorAClass() { if (Line1_HMI_Model.Robot_Working_A) return "working"; if (Line1_HMI_Model.IsWorking) { if (Line1_HMI_Model.MoveTrolleyOutStationA) { return "request-out"; } else if (Line1_HMI_Model.MoveTrolleyInStationA) { return "request-in"; } else { return "standby"; } } else { return "hidden"; } } string GetIndicatorBClass() { if (Line1_HMI_Model.Robot_Working_B) return "working"; if (Line1_HMI_Model.IsWorking) { if (Line1_HMI_Model.MoveTrolleyOutStationB) { return "request-out"; } else if (Line1_HMI_Model.MoveTrolleyInStationB) { return "request-in"; } else { return "standby"; } } else { return "hidden"; } } async Task ToggleAutoManualA() { var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.EnableAutoA), Line1_HMI_Model.EnableAutoA ? bool.FalseString : bool.TrueString); if (result == null) { Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error); } else if (!result.IsSuccess) { Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error); } } async Task ToggleAutoManualB() { var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.EnableAutoB), Line1_HMI_Model.EnableAutoB ? bool.FalseString : bool.TrueString); if (result == null) { Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error); } else if (!result.IsSuccess) { Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error); } } async Task ToggleReqInA() { if (Line1_HMI_Model.EnableAutoA) return; var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.Req_In_A), Line1_HMI_Model.Req_In_A ? bool.FalseString : bool.TrueString); if (result == null) { Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error); } else if (!result.IsSuccess) { Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error); } } async Task ToggleReqInBesideA() { if (Line1_HMI_Model.EnableAutoA) return; var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.Req_In_Beside_A), Line1_HMI_Model.Req_In_Beside_A ? bool.FalseString : bool.TrueString); if (result == null) { Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error); } else if (!result.IsSuccess) { Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error); } } async Task ToggleReqCloseCylenderA() { if (Line1_HMI_Model.EnableAutoA) return; var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.Req_Close_Cylinder_A), Line1_HMI_Model.Req_Close_Cylinder_A ? bool.FalseString : bool.TrueString); if (result == null) { Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error); } else if (!result.IsSuccess) { Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error); } } async Task ToggleReqInB() { if (Line1_HMI_Model.EnableAutoB) return; var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.Req_In_B), Line1_HMI_Model.Req_In_B ? bool.FalseString : bool.TrueString); if (result == null) { Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error); } else if (!result.IsSuccess) { Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error); } } async Task ToggleReqInBesideB() { if (Line1_HMI_Model.EnableAutoB) return; var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.Req_In_Beside_B), Line1_HMI_Model.Req_In_Beside_B ? bool.FalseString : bool.TrueString); if (result == null) { Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error); } else if (!result.IsSuccess) { Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error); } } async Task ToggleReqCloseCylenderB() { if (Line1_HMI_Model.EnableAutoB) return; var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.Req_Close_Cylinder_B), Line1_HMI_Model.Req_Close_Cylinder_B ? bool.FalseString : bool.TrueString); if (result == null) { Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error); } else if (!result.IsSuccess) { Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error); } } async Task ToggleHasEmptyTrolley() { var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.Has_Empty_Trolley), Line1_HMI_Model.Has_Empty_Trolley ? bool.FalseString : bool.TrueString); if (result == null) { Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error); } else if (!result.IsSuccess) { Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error); } } async Task ToggleGoHome() { if (Line1_HMI_Model.Request_GoHome) return; var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.Request_GoHome), bool.TrueString); if (result == null) { Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error); } else if (!result.IsSuccess) { Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error); } } async Task ToggleHasFullTrolley() { var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.AGV_Push_Noti_Mem), Line1_HMI_Model.AGV_Push_Noti_Mem ? bool.FalseString : bool.TrueString); if (result == null) { Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error); } else if (!result.IsSuccess) { Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error); } } async Task CallResetStep() { if (Line1_HMI_Model.Request_Reset_SEHC_DA3_Line1) return; bool? confirm = await Dialog.ShowMessageBox( "Reset Mission State", "Hãy xác nhận đặt lại trạng thái hoạt động!", yesText: "Yes", cancelText: "Cancel"); if (confirm != true) return; var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.Request_Reset_SEHC_DA3_Line1), bool.TrueString); if (result == null) { Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error); } else if (!result.IsSuccess) { Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error); } } public async ValueTask DisposeAsync() { timer.Stop(); hmiClient.ConnectionStateChanged -= OnConnectionStateChanged; hmiClient.StateChanged -= OnProcessStateChanged; await hmiClient.StopAsync(); } }