From 31f3cb26d845cdd1f175241ba56339ef65f0b037 Mon Sep 17 00:00:00 2001 From: Brendan Westley Date: Sun, 20 Oct 2024 17:27:57 -0500 Subject: [PATCH] Update raman graph after data is recieved and not before --- .../Core/Components/RamanGraph.razor | 94 ++----------------- 1 file changed, 9 insertions(+), 85 deletions(-) diff --git a/Basestation_Software.Web/Core/Components/RamanGraph.razor b/Basestation_Software.Web/Core/Components/RamanGraph.razor index fe0d003..cbb5f29 100644 --- a/Basestation_Software.Web/Core/Components/RamanGraph.razor +++ b/Basestation_Software.Web/Core/Components/RamanGraph.razor @@ -7,6 +7,7 @@

+

@@ -14,132 +15,55 @@ @code { - //Variables - private static List _raman1 = new List(500), - _raman2 = new List(500), - _raman3 = new List(500), - _raman4 = new List(500), - _raman5 = new List(48); - - class DataItem { public int Raman_Shift { get; set; } public double Intensity { get; set; } - - public DataItem() - { - Raman_Shift = 0; - Intensity = 0f; - } } DataItem[] ramanGraph = new DataItem[2048]; - private async void RequestRamanData() + private async Task RequestRamanData() { await _RoveCommService.SendAsync("Instruments", "RequestRamanReading", [0], reliable: false); - - for (int i = 0; i < 2048; i++) - { - if (i < 500) - { - ramanGraph[i] = new DataItem - { - Raman_Shift = i, - Intensity = _raman1[i], - }; - } - else if (i >= 500 && i < 1000) - { - ramanGraph[i] = new DataItem - { - Raman_Shift = i, - Intensity = _raman2[i - 500], - }; - } - - else if (i >= 1000 && i < 1500) - { - ramanGraph[i] = new DataItem - { - Raman_Shift = i, - Intensity = _raman3[i - 1000], - }; - } - - else if (i >= 1500 && i < 2000) - { - ramanGraph[i] = new DataItem - { - Raman_Shift = i, - Intensity = _raman4[i - 1500], - }; - } - - else - { - ramanGraph[i] = new DataItem - { - Raman_Shift = i, - Intensity = _raman5[i - 2000], - }; - } - } } - protected override async Task OnInitializedAsync() { - //Initialize values of ramanGraph and _raman variables to not throw errors if RoveComm packets not sent + // Initialize ramanGraph for (int i = 0; i < 2048; i++) - { - ramanGraph[i] = new DataItem(); - } - - for (int i = 0; i < 500; i++) - { - _raman1.Add(0); - _raman2.Add(0); - _raman3.Add(0); - _raman4.Add(0); - } - - for (int i = 0; i < 48; i++) - { - _raman5.Add(0); - } + ramanGraph[i] = new DataItem { Raman_Shift = i, Intensity = 0 }; //Receiving RoveComm packets if they are sent in _RoveCommService.On("Instruments", "RamanReading_Part1", async (packet) => { - _raman1 = packet.Data; + for (int i = 0; i < 500; i++) ramanGraph[i].Intensity = packet.Data[i]; await InvokeAsync(StateHasChanged); }); await Task.CompletedTask; _RoveCommService.On("Instruments", "RamanReading_Part2", async (packet) => { - _raman2 = packet.Data; + for (int i = 0; i < 500; i++) ramanGraph[i + 500].Intensity = packet.Data[i]; await InvokeAsync(StateHasChanged); }); _RoveCommService.On("Instruments", "RamanReading_Part3", async (packet) => { - _raman3 = packet.Data; + for (int i = 0; i < 500; i++) ramanGraph[i + 1000].Intensity = packet.Data[i]; await InvokeAsync(StateHasChanged); }); _RoveCommService.On("Instruments", "RamanReading_Part4", async (packet) => { - _raman4 = packet.Data; + for (int i = 0; i < 500; i++) ramanGraph[i + 1500].Intensity = packet.Data[i]; await InvokeAsync(StateHasChanged); }); _RoveCommService.On("Instruments", "RamanReading_Part5", async (packet) => { - _raman5 = packet.Data; + for (int i = 0; i < 48; i++) ramanGraph[i + 2000].Intensity = packet.Data[i]; await InvokeAsync(StateHasChanged); }); }