initial commit
This commit is contained in:
137
Lab505.Client/Pages/DobotPanel.razor
Normal file
137
Lab505.Client/Pages/DobotPanel.razor
Normal file
@@ -0,0 +1,137 @@
|
||||
@implements IAsyncDisposable
|
||||
|
||||
<MudPaper Elevation="0" Class="pa-3" Style="background:transparent;">
|
||||
|
||||
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center"
|
||||
Style="cursor:pointer" @onclick="ToggleDOBOT">
|
||||
<MudText Typo="Typo.subtitle1">DOBOT</MudText>
|
||||
<MudIcon Icon="@(IsDobotExpanded ? Icons.Material.Filled.ExpandMore : Icons.Material.Filled.ExpandLess)" Size="Size.Small" />
|
||||
</MudStack>
|
||||
|
||||
<div class="status-row mt-2">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Circle" Size="Size.Small" Color="@DobotMudColor" />
|
||||
<div>
|
||||
<MudText Typo="Typo.caption">@DobotStatus.ToUpper()</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color:#9a9a9a;">
|
||||
Code: @State.Imr.CodeDobotStatus_Opc | @DobotStatusCodeText
|
||||
</MudText>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-1 mb-1">
|
||||
<MudButton FullWidth="true" Variant="Variant.Outlined" Color="Color.Error" Size="Size.Small" OnClick="Dobot_Cancel" Disabled="@(!State.CanControl)">Cancel</MudButton>
|
||||
</div>
|
||||
|
||||
@if (IsDobotExpanded)
|
||||
{
|
||||
<MudText Typo="Typo.caption" Class="sec-title mt-2">Control</MudText>
|
||||
<div class="op-grid">
|
||||
<MudButton Variant="Variant.Outlined" Size="Size.Small" OnClick="Dobot_Home" Disabled="@DobotLocked("GoHome")">Home</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Size="Size.Small" OnClick="Dobot_Continue" Disabled="@DobotLocked("Continue")">Continue</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Size="Size.Small" OnClick="Dobot_PowerOn" Disabled="@DobotLocked("PowerOn")">PowerOn</MudButton>
|
||||
</div>
|
||||
<MudText Typo="Typo.caption" Class="sec-title mt-2">Pick</MudText>
|
||||
<div class="op-grid">
|
||||
<MudNumericField T="int?" @bind-Value="okCount" Placeholder="OK" Variant="Variant.Outlined" Class="pnl-num" Min="0" Max="99" />
|
||||
<MudNumericField T="int?" @bind-Value="ngCount" Placeholder="NG" Variant="Variant.Outlined" Class="pnl-num" Min="0" Max="99" />
|
||||
<MudButton Variant="Variant.Outlined" Size="Size.Small" OnClick="PickUp_Vda" Disabled="@ImrLocked("PickUp")">Pick Up</MudButton>
|
||||
</div>
|
||||
}
|
||||
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
[Inject] StateService State { get; set; } = default!;
|
||||
[Inject] CommandService Cmd { get; set; } = default!;
|
||||
|
||||
bool IsDobotExpanded = true;
|
||||
void ToggleDOBOT() => IsDobotExpanded = !IsDobotExpanded;
|
||||
|
||||
int? okCount;
|
||||
int? ngCount;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await State.StartAsync();
|
||||
State.ImrChanged += Refresh; // DobotStatus comes from IMR state
|
||||
State.WorkflowChanged += Refresh;
|
||||
}
|
||||
|
||||
public ValueTask DisposeAsync()
|
||||
{
|
||||
State.ImrChanged -= Refresh;
|
||||
State.WorkflowChanged -= Refresh;
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
|
||||
private void Refresh() => InvokeAsync(StateHasChanged);
|
||||
|
||||
private string DobotStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
var s = State.Imr.DobotStatus_Opc?.ToLower() ?? "";
|
||||
var e = State.Imr.CodeDobotStatus_Opc;
|
||||
if (e == 9999) return "off";
|
||||
if (e != 0) return "error";
|
||||
if (s.Contains("error") || s.Contains("fault")) return "error";
|
||||
if (s.Contains("controlling") || s.Contains("move")) return "moving";
|
||||
if (s.Contains("canceled")) return "canceled";
|
||||
if (s.Contains("finished") || s.Contains("idle")) return "ok";
|
||||
return "ok";
|
||||
}
|
||||
}
|
||||
|
||||
private Color DobotMudColor => DobotStatus switch
|
||||
{
|
||||
"ok" => Color.Success,
|
||||
"idle" => Color.Success,
|
||||
"moving" => Color.Info,
|
||||
"canceled" => Color.Warning,
|
||||
"error" => Color.Error,
|
||||
_ => Color.Default
|
||||
};
|
||||
|
||||
private string DobotStatusCodeText => State.Imr.CodeDobotStatus_Opc switch
|
||||
{
|
||||
0 => "Dobot Waiting",
|
||||
98 => "Dobot Waiting for Connection",
|
||||
99 => "Dobot Reconnecting",
|
||||
100 => "Dobot Running",
|
||||
101 => "Dobot Disconnected",
|
||||
102 => "Dobot No Data Received",
|
||||
103 => "Dobot Data Not Updated",
|
||||
104 => "Dobot Target Coordinates Out of Range",
|
||||
105 => "Dobot Returning Home",
|
||||
106 => "Dobot Checking Emergency Stop Button",
|
||||
107 => "Dobot in Alarm State",
|
||||
108 => "Dobot Powering On, Waiting",
|
||||
109 => "Dobot Powered On",
|
||||
110 => "Dobot in Drag Mode",
|
||||
111 => "Dobot Waiting: Select Continue or Return Home",
|
||||
112 => "Dobot OK Count Limit Reached",
|
||||
113 => "Dobot NG Count Limit Reached",
|
||||
999 => "Dobot Error",
|
||||
_ => "Unknown"
|
||||
};
|
||||
|
||||
// Dobot queue locking
|
||||
private bool DobotLocked(string label)
|
||||
=> !State.CanControl || State.Workflow.DobotBusyLabel == label || State.Workflow.DobotNextLabel == label;
|
||||
|
||||
// PickUp goes through the IMR queue
|
||||
private bool ImrLocked(string label)
|
||||
=> !State.CanControl || State.Workflow.ImrBusyLabel == label || State.Workflow.ImrNextLabel == label;
|
||||
|
||||
private Task Dobot_Cancel() => Cmd.DobotCancelAsync();
|
||||
private Task Dobot_Home() => Cmd.DobotGoHomeAsync();
|
||||
private Task Dobot_Continue() => Cmd.DobotContinueAsync();
|
||||
private Task Dobot_PowerOn() => Cmd.DobotPowerOnAsync();
|
||||
private Task PickUp_Vda() => Cmd.ImrPickupAsync(okCount ?? 0, ngCount ?? 0);
|
||||
}
|
||||
|
||||
<style>
|
||||
.status-row { display:flex; align-items:center; gap:8px; margin-bottom:4px; }
|
||||
.sec-title { display:block; color:#9CA3AF; margin-bottom:4px; }
|
||||
.op-grid { display:grid; grid-template-columns:repeat(3, 1fr); gap:5px; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user