Day 1 Develop backgroun functions and base visual style of Temperature Page

master
Jan Beníček 2023-12-17 02:26:36 +01:00
parent 484c3b7dd6
commit 572db9200b
13 changed files with 459 additions and 63 deletions

View File

@ -1,12 +1,14 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
<Blazored.Modal.CascadingBlazoredModal>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</Blazored.Modal.CascadingBlazoredModal>

View File

@ -0,0 +1,84 @@
@using Blazored.Modal.Services
@using UI_SequentMicrosystems.Components
@using UI_SequentMicrosystems.Constants
@using UI_SequentMicrosystems.Services
@using Blazored.Modal
<div class="row">
<div class="col-2 col-sm-4 col-md-4 col-xl-4 h5 text-end align-self-center"><strong>@(RecalculateValues(RTD8tmService.GetActualData(StackID, ChanelID), RTD8tmService.GetValueType(StackID, ChanelID)))</strong></div>
@if (Edit)
{
<div class="col-2 h5 text-start align-self-center" @onclick="(() => Modal.Show<RTD8TMSensorTypeModal>(ModalTitle, new ModalParameters {{nameof(RTD8TMSensorTypeModal.StackID), StackID}, {nameof(RTD8TMSensorTypeModal.ChanelID), ChanelID}}, new ModalOptions { HideCloseButton = true }))">@(ValueType(RTD8tmService.GetValueType(StackID, ChanelID)))</div>
}
else
{
<div class="col-2 h5 text-start align-self-center">@(ValueType(RTD8tmService.GetValueType(StackID, ChanelID)))</div>
}
@if (Edit)
{
<div class="col">
<input type="text" class="form-control form-control-sm bg-black text-white no-border" value="@(RTD8tmService.GetChanelName(StackID, ChanelID))" @onchange="((x) => ChangeName(x.Value.ToString()))" >
</div>
}
else
{
<div class="col">@(RTD8tmService.GetChanelName(StackID, ChanelID))</div>
}
</div>
@code {
[Parameter]
public byte StackID { get; set; }
[Parameter]
public byte ChanelID { get; set; }
[Parameter]
public bool Edit { get; set; }
[Parameter]
public RTD8TMService RTD8tmService { get; set; }
private string ModalTitle = "Select value Type";
[CascadingParameter] public IModalService Modal { get; set; } = default!;
/// <summary>
/// Internal event for Name Change
/// </summary>
/// <param name="NewName"></param>
private void ChangeName(string NewName)
{
RTD8tmService.SetChanelNames(StackID, ChanelID, NewName);
}
private float RecalculateValues(float resistance, byte Type = 0)
{
if (Type == RTD8TMSensorTypes.PT100)
{
return (float)Math.Round(Calculations.Electric.RTD.PT100.ResistanceToTemperature(resistance), 2);
}
else
{
return resistance;
}
}
private string ValueType(byte Type)
{
if (Type == RTD8TMSensorTypes.PT100)
{
return "°C";
}
else
{
return "Ω";
}
}
}

View File

@ -0,0 +1,44 @@
@using Blazored.Modal
@using Blazored.Modal.Services
@using UI_SequentMicrosystems.Constants
@using UI_SequentMicrosystems.Services
@inject RTD8TMService _RTD8TMService
<div class="row">
<div class="col">
<button class="btn btn-dark" @onclick="((a) => Select(RTD8TMSensorTypes.Resistance))">Resistance</button>
</div>
<div class="col">
<button class="btn btn-dark" @onclick="((a) => Select(RTD8TMSensorTypes.PT100))">PT100</button>
</div>
</div>
@code {
[CascadingParameter] BlazoredModalInstance BlazoredModal { get; set; } = default!;
[Parameter]
public byte StackID { get; set; }
[Parameter]
public byte ChanelID { get; set; }
private void Select(byte type)
{
_RTD8TMService.SetValueType(StackID, ChanelID, type);
SubmitForm();
}
private async void SubmitForm() => await BlazoredModal.CloseAsync();
}

View File

@ -0,0 +1,16 @@

namespace UI_SequentMicrosystems.Constants
{
public static class RTD8TMSensorTypes
{
public readonly static byte Resistance = 0;
public readonly static byte PT100 = 1;
}
}

View File

@ -15,7 +15,7 @@
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<NavLink class="nav-link" href="RTD8TM">
<span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> Temperature
</NavLink>
</div>

View File

@ -1,34 +0,0 @@
@page "/counter"
@using UI_SequentMicrosystems.Services
@inject NavigationManager Navigator
@inject RTD8TMService _RTD8TMService
<PageTitle>Counter</PageTitle>
<h1>Counter</h1>
<h2>@Navigator.BaseUri --> @address</h2>
<p role="status">Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
private string address = "";
protected override void OnInitialized()
{
_RTD8TMService.SetAddress(Navigator.BaseUri);
}
}

95
Pages/RTD8TMPage.razor Normal file
View File

@ -0,0 +1,95 @@
@page "/RTD8TM"
@using Blazored.Modal.Services
@using UI_SequentMicrosystems.Components
@using UI_SequentMicrosystems.Services
@using Blazored.Modal
@inject NavigationManager Navigator
@inject RTD8TMService _RTD8TMService
<PageTitle>Temperature</PageTitle>
<div class="row text-center">
<div class="col">Device Address: @_RTD8TMService.GetAddress() | DataUpdate: @_UpdateCounter | </div>
<div class="col text-start">
<div class="form-check form-switch">
@if (EditName)
{
<input class="form-check-input" type="checkbox" role="switch" id="flexSwitchCheckDefault" @onclick="(() =>
{
EditName = false;
Task.Run(() =>_RTD8TMService.SetChanelsNames());
Task.Run(() => _RTD8TMService.PostValueTypes());
})" checked>
}
else
{
<input class="form-check-input" type="checkbox" role="switch" id="flexSwitchCheckDefault" @onclick="(() => EditName = true)">
}
<label class="form-check-label" for="flexSwitchCheckDefault">Configure Inputs</label>
</div>
</div>
@if (EditName)
{
<div class="col text-start">
<button class="btn btn-dark text-white no-border" @onclick="(() => _RTD8TMService.ClearChanelNames())">Reset Names</button>
</div>
<div class="col text-start">
<button class="btn btn-dark text-white no-border" @onclick="(() => _RTD8TMService.ClearValueTypes())">Reset Value Types</button>
</div>
}
</div>
<div class="row">
<div class="col-lg-6 graybg">
<div class="well">
1 - Future Graph
</div>
</div>
<div class="col-lg-6">
<div class="row">
@foreach(byte StackID in _RTD8TMService.GetActualData().Keys)
{
<div class="col-sm-6 col-xxl-4">
<div class="text-center">Stack ID: @StackID</div>
@for (byte chanel = 0; chanel < 8; chanel++)
{
<RTD8TMChanelComponent StackID=@StackID ChanelID=@chanel Edit=@EditName RTD8tmService=@_RTD8TMService />
}
</div>
}
</div>
</div>
</div>
@code {
public int _UpdateCounter = 0;
private bool EditName = false;
[CascadingParameter] public IModalService Modal { get; set; } = default!;
protected override void OnInitialized()
{
_RTD8TMService.SetAddress("http://10.1.20.5/");//Navigator.BaseUri);
_RTD8TMService.EventUpdateValues += UpdateView;
}
public async Task UpdateView(object? o, bool b)
{
await InvokeAsync(() =>
{
StateHasChanged();
_UpdateCounter++;
});
}
}

View File

@ -17,7 +17,7 @@ Welcome to your new app.
protected override void OnInitialized()
{
_RTD8TMService.SetAddress(Navigator.BaseUri);
_RTD8TMService.SetAddress("http://10.1.20.5/");// Navigator.BaseUri);

View File

@ -1,3 +1,4 @@
using Blazored.Modal;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using UI_SequentMicrosystems.Services;
@ -12,6 +13,7 @@ namespace UI_SequentMicrosystems
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddBlazoredModal();
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddSingleton<RTD8TMService>();

View File

@ -6,9 +6,9 @@ namespace UI_SequentMicrosystems.Services
{
public class RTD8TMService
{
private SortedList<byte, string[]> ChanelNames = new SortedList<byte, string[]>();
private SortedList<byte, float[]> ActualValues = new SortedList<byte, float[]>();
private SortedList<byte, byte[]> ValuesType = new SortedList<byte, byte[]>();
private List<RTD8TMGraphModel> GraphData = new();
private byte GraphDataCounterCount = 10;
private byte GraphDataCounter = 0;
@ -18,6 +18,8 @@ namespace UI_SequentMicrosystems.Services
private RTD8TM _RTD8TM = new RTD8TM();
private System.Timers.Timer _timer = new(1000);
public delegate Task AsyncEventHandler<TEventArgs>(object? sender, TEventArgs? e);
public event AsyncEventHandler<bool>? EventUpdateValues;
public RTD8TMService()
{
@ -37,6 +39,7 @@ namespace UI_SequentMicrosystems.Services
{
Address = address;
GetChanelsNames();
GetValueTypes();
}
/// <summary>
@ -55,10 +58,12 @@ namespace UI_SequentMicrosystems.Services
}
}
//Actual Data
/// <summary>
/// Read Actual values from Device
/// </summary>
public async void GetActualValues()
private async void GetActualValues()
{
if (Address == null) { return; }
@ -73,9 +78,37 @@ namespace UI_SequentMicrosystems.Services
{
GraphDataCounter++;
}
}
/// <summary>
/// Request for actual data
/// </summary>
/// <returns></returns>
public SortedList<byte, float[]> GetActualData()
{
return ActualValues;
}
/// <summary>
/// Get actual data Value
/// </summary>
/// <param name="stack">Stack ID</param>
/// <param name="chanel">Chanel ID</param>
/// <returns>Measure Resistance</returns>
public float GetActualData(byte stack, byte chanel)
{
if (ActualValues.ContainsKey(stack))
{
return ActualValues[stack][chanel];
}
else
{
return 0;
}
}
//ChanelsNames
/// <summary>
/// Read configured chanels Names from Device
/// </summary>
@ -93,11 +126,9 @@ namespace UI_SequentMicrosystems.Services
/// </summary>
/// <param name="names">chanels names sorted list</param>
#pragma warning disable CS1998 // V této asynchronní metodě chybí operátory await a spustí se synchronně.
public async Task SetChanelsNames(SortedList<byte, string[]> names)
public async Task SetChanelsNames()
#pragma warning restore CS1998 // V této asynchronní metodě chybí operátory await a spustí se synchronně.
{
ChanelNames = names;
if (Address == null)
return;
@ -114,6 +145,11 @@ namespace UI_SequentMicrosystems.Services
foreach (byte key in ActualValues.Keys)
{
if (!ChanelNames.ContainsKey(key))
{
ChanelNames.Add(key, new string[8]);
}
for (int i = 0; i < 8; i++)
{
if (ChanelNames[key][i] == null)
@ -124,16 +160,152 @@ namespace UI_SequentMicrosystems.Services
}
}
/// <summary>
/// Get chanel names
/// </summary>
/// <returns>Chanels names object</returns>
public SortedList<byte, string[]> GetChanelNames()
{
return ChanelNames;
}
private void TimerElapsed(object? o, ElapsedEventArgs? e)
/// <summary>
/// Set chanel Name
/// </summary>
/// <param name="stack">Stack ID</param>
/// <param name="chanel">Chanel ID</param>
/// <param name="name">New Name</param>
public void SetChanelNames(byte stack, byte chanel, string name)
{
if (!ChanelNames.ContainsKey(stack))
{
ChanelNames.Add(stack, new string[8]);
}
ChanelNames[stack][chanel] = name;
}
/// <summary>
/// Read chanel name
/// </summary>
/// <param name="stack">Stack ID</param>
/// <param name="chanel">Chanel ID</param>
/// <returns>Chanel name</returns>
public string GetChanelName(byte stack, byte chanel)
{
if (ChanelNames.ContainsKey(stack))
{
return ChanelNames[stack][chanel];
}
else
{
return "----------";
}
}
/// <summary>
/// Clear chanels Names to default
/// </summary>
public void ClearChanelNames()
{
ChanelNames.Clear();
AutoUpdateChanelsName();
}
//Timer
private async void TimerElapsed(object? o, ElapsedEventArgs? e)
{
GetActualValues();
AutoUpdateChanelsName();
if (EventUpdateValues != null)
{
await EventUpdateValues.Invoke(this, true);
}
}
//Graph Data
/// <summary>
/// Get data for graph visualize
/// </summary>
/// <returns>saved Graphn Data</returns>
public List<RTD8TMGraphModel> GetGraphData()
{
return GraphData;
}
/// <summary>
/// Clear data from Graph
/// </summary>
public void ClearGraph()
{
GraphData.Clear();
}
//Values Types
/// <summary>
/// Set Value Type identifier
/// </summary>
/// <param name="StackID">Stack ID</param>
/// <param name="ChanelID">Chanel ID</param>
/// <param name="Type">Value Type</param>
public void SetValueType(byte StackID, byte ChanelID, byte Type)
{
if (!ValuesType.ContainsKey(StackID))
{
ValuesType.Add(StackID, new byte[8]);
}
ValuesType[StackID][ChanelID] = Type;
}
/// <summary>
/// Get Value Type
/// </summary>
/// <param name="StackID">Stack ID</param>
/// <param name="ChanelID">Chanel ID</param>
/// <returns>Value Type</returns>
public byte GetValueType(byte StackID, byte ChanelID)
{
if (ValuesType.ContainsKey(StackID))
{
return ValuesType[StackID][ChanelID];
}
else
{
return 0;
}
}
/// <summary>
/// Get ValueTypes From API
/// </summary>
public async void GetValueTypes()
{
if (Address == null) { return; }
ValuesType = await _RTD8TM.GetValueTypes(Address);
}
/// <summary>
/// Post ValueTypes to API
/// </summary>
public void PostValueTypes()
{
if (Address == null) { return; }
_RTD8TM.PostValueTypes(Address, ValuesType);
}
public void ClearValueTypes()
{
ValuesType.Clear();
}
}

View File

@ -8,11 +8,13 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Blazored.Modal" Version="7.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CalculationsLib\Calculations.csproj" />
<ProjectReference Include="..\Wrapper_Api_SequentMicrosystems\Wrapper_Api_SequentMicrosystems.csproj" />
</ItemGroup>

View File

@ -3,15 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34309.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UI_SequentMicrosystems", "UI_SequentMicrosystems.csproj", "{5CA9656E-173B-495E-8407-209AE67BAA13}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UI_SequentMicrosystems", "UI_SequentMicrosystems.csproj", "{5CA9656E-173B-495E-8407-209AE67BAA13}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wrapper_Api_SequentMicrosystems", "..\Wrapper_Api_SequentMicrosystems\Wrapper_Api_SequentMicrosystems.csproj", "{54BC70B0-BE0E-4C2C-8DE2-7A9BEA7C0E94}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wrapper_Api_SequentMicrosystems", "..\Wrapper_Api_SequentMicrosystems\Wrapper_Api_SequentMicrosystems.csproj", "{54BC70B0-BE0E-4C2C-8DE2-7A9BEA7C0E94}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DEAA95EC-24FE-42EC-B078-723C4A6173E6}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Calculations", "..\CalculationsLib\Calculations.csproj", "{67349A12-2544-4A15-93F6-AC6E039F5F52}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -26,6 +28,10 @@ Global
{54BC70B0-BE0E-4C2C-8DE2-7A9BEA7C0E94}.Debug|Any CPU.Build.0 = Debug|Any CPU
{54BC70B0-BE0E-4C2C-8DE2-7A9BEA7C0E94}.Release|Any CPU.ActiveCfg = Release|Any CPU
{54BC70B0-BE0E-4C2C-8DE2-7A9BEA7C0E94}.Release|Any CPU.Build.0 = Release|Any CPU
{67349A12-2544-4A15-93F6-AC6E039F5F52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{67349A12-2544-4A15-93F6-AC6E039F5F52}.Debug|Any CPU.Build.0 = Debug|Any CPU
{67349A12-2544-4A15-93F6-AC6E039F5F52}.Release|Any CPU.ActiveCfg = Release|Any CPU
{67349A12-2544-4A15-93F6-AC6E039F5F52}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -4,6 +4,18 @@
}
.graybg {
background: gray;
color: yellow;
}
.no-border {
border: 0;
box-shadow: none; /* You may want to include this as bootstrap applies these styles too */
}
@ -11,8 +23,3 @@