@implements IAsyncDisposable ASRS · OPC UA
@StatusText @if (S.Available && S.Online) { Homed: @Fmt(S.Homed)  |  Busy: @Fmt(S.Busy)  |  Fault: @Fmt(S.Fault) }
@if (!string.IsNullOrEmpty(S.LastError)) { @S.LastError } @if (_expanded && S.Available) { Kho (cột × tầng) — chọn ô@(_from is null ? "" : $": {Name(_from.Value)}")@(_to is null ? "" : $" → {Name(_to.Value)}")
@for (int shelf = AsrsOpcLayout.Shelves; shelf >= 1; shelf--) { T@(shelf) @for (int col = 1; col <= AsrsOpcLayout.Columns; col++) { var cell = (col, shelf); } }
Băng tải
BT1 · Trái BT2 · Phải
Lệnh
Retrieve Store Move StoreAny Home
}
@code { [Inject] StateService State { get; set; } = default!; [Inject] CommandService Cmd { get; set; } = default!; private bool _expanded = true; private void Toggle() => _expanded = !_expanded; private int _conveyor = 1; private (int Col, int Shelf)? _from; private (int Col, int Shelf)? _to; private AsrsOpcPushDto S => State.AsrsOpc; protected override async Task OnInitializedAsync() { await State.StartAsync(); State.AsrsOpcChanged += Refresh; } public ValueTask DisposeAsync() { State.AsrsOpcChanged -= Refresh; return ValueTask.CompletedTask; } private void Refresh() => InvokeAsync(StateHasChanged); // ── Status ────────────────────────────────────────────────────────── // PLC giữ Busy=1 thêm ~3s sau mỗi lệnh để chờ lệnh kế tiếp chạy nối luôn → vẫn cho gửi lệnh. private string StatusText => !S.Available ? "CHỈ CÓ TRÊN REAL STACK" : !S.Online ? "OFFLINE" : S.Fault == true ? "FAULT (E-STOP / SAFETY)" : S.DriverBusy ? $"ĐANG CHẠY: {S.CurrentOp}" : S.Busy == true ? "SẴN SÀNG · PLC CHỜ LỆNH KẾ TIẾP" : "SẴN SÀNG"; private Color StatusColor => !S.Available || !S.Online ? Color.Default : S.Fault == true ? Color.Error : S.DriverBusy ? Color.Info : Color.Success; private static string Fmt(bool? v) => v switch { true => "1", false => "0", _ => "-" }; // ── Slots ─────────────────────────────────────────────────────────── private bool? Occ((int Col, int Shelf) c) => S.Occupied.ElementAtOrDefault(AsrsOpcLayout.SlotIndex(c.Col, c.Shelf)); private static string Name((int Col, int Shelf) c) => $"{c.Col}.{c.Shelf}"; private string CellClass((int Col, int Shelf) c) { var cls = Occ(c) switch { true => "slot full", false => "slot", _ => "slot unknown" }; if (_from == c) cls += " sel-from"; if (_to == c) cls += " sel-to"; return cls; } /// Click 1 = ô chính (Retrieve/Store/nguồn Move). Click 2 ô khác = ô đích Move. Click lại = bỏ chọn. private void Pick((int Col, int Shelf) c) { if (_from == c) { _from = _to; _to = null; } else if (_to == c) { _to = null; } else if (_from is null) _from = c; else _to = c; } // ── Enable rules (server vẫn kiểm tra lại) ───────────────────────── private bool CanCommand => State.CanControl && S.Available && S.Online && S.Fault != true && !S.DriverBusy; private bool CanRetrieve => CanCommand && _from is { } f && _to is null && Occ(f) == true; private bool CanStore => CanCommand && _from is { } f && _to is null && Occ(f) == false; private bool CanMove => CanCommand && _from is { } f && _to is { } t && Occ(f) == true && Occ(t) == false; private bool CanStoreAny => CanCommand && S.Occupied.Any(o => o == false); // ── Commands ─────────────────────────────────────────────────────── private async Task Retrieve() { var f = _from!.Value; ClearSel(); await Cmd.AsrsOpcRetrieveAsync(f.Col, f.Shelf, _conveyor); } private async Task Store() { var f = _from!.Value; ClearSel(); await Cmd.AsrsOpcStoreAsync(f.Col, f.Shelf, _conveyor); } private async Task Move() { var f = _from!.Value; var t = _to!.Value; ClearSel(); await Cmd.AsrsOpcMoveAsync(f.Col, f.Shelf, t.Col, t.Shelf); } private Task StoreAny() => Cmd.AsrsOpcStoreAnyAsync(_conveyor); private Task Home() => Cmd.AsrsOpcHomeAsync(); private void ClearSel() { _from = null; _to = null; } }