|
|
|
|
@ -4,6 +4,7 @@ |
|
|
|
|
|
|
|
|
|
@using IOModuleTestBlazor.Services |
|
|
|
|
@inject ISerialPortService SerialService |
|
|
|
|
@inject IJSRuntime JS |
|
|
|
|
|
|
|
|
|
<PageTitle>Serial Terminal</PageTitle> |
|
|
|
|
|
|
|
|
|
@ -122,6 +123,8 @@ |
|
|
|
|
private string? _connectError; |
|
|
|
|
private List<string> _availablePorts = new(); |
|
|
|
|
private List<string> _displayLines = new(); |
|
|
|
|
private IJSObjectReference? _jsModule; |
|
|
|
|
private bool _scrollPending = false; |
|
|
|
|
|
|
|
|
|
private static readonly (string Label, string Cmd)[] _quickCommands = |
|
|
|
|
[ |
|
|
|
|
@ -188,15 +191,30 @@ |
|
|
|
|
InvokeAsync(() => |
|
|
|
|
{ |
|
|
|
|
RefreshLines(); |
|
|
|
|
_scrollPending = true; |
|
|
|
|
StateHasChanged(); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender) |
|
|
|
|
{ |
|
|
|
|
if (firstRender) |
|
|
|
|
_jsModule = await JS.InvokeAsync<IJSObjectReference>( |
|
|
|
|
"import", "./Components/Pages/SerialTerminal.razor.js"); |
|
|
|
|
|
|
|
|
|
if (_scrollPending && _jsModule is not null) |
|
|
|
|
{ |
|
|
|
|
_scrollPending = false; |
|
|
|
|
await _jsModule.InvokeVoidAsync("scrollToBottom", "terminal-output"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void RefreshLines() |
|
|
|
|
=> _displayLines = SerialService.GetLines().ToList(); |
|
|
|
|
|
|
|
|
|
private void ClearTerminal() |
|
|
|
|
{ |
|
|
|
|
SerialService.ClearLines(); |
|
|
|
|
_displayLines.Clear(); |
|
|
|
|
StateHasChanged(); |
|
|
|
|
} |
|
|
|
|
@ -205,5 +223,8 @@ |
|
|
|
|
=> string.Join("\n", _displayLines); |
|
|
|
|
|
|
|
|
|
public void Dispose() |
|
|
|
|
=> SerialService.DataReceived -= OnDataReceived; |
|
|
|
|
{ |
|
|
|
|
SerialService.DataReceived -= OnDataReceived; |
|
|
|
|
_jsModule?.DisposeAsync(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|