Browse Source

fixed target control

main
jkpete 1 month ago
parent
commit
239adb4d05
  1. 44
      Components/Pages/Control.razor
  2. 11
      Script/Model/ModelSerialTest.cs
  3. 20
      Script/Model/ModelTrackControl.cs

44
Components/Pages/Control.razor

@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
@if (isTargetOperationInProgress)
{
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
<span>@(isTargetActive ? "停止中..." : "启动中...")</span>
<span>@(isTargetActive ? "启动中..." : "停止中...")</span>
}
else
{
@ -36,6 +36,22 @@ @@ -36,6 +36,22 @@
<p>空轨移动中,请等待...</p>
</div>
}
<div class="form-group">
<label for="deviceId">校准零点位置:</label>
<InputNumber id="deviceId" class="form-control" @bind-Value="@MoveStep" />
</div>
<div class="control-section">
<button class="btn btn-primary" @onclick="SetPosition">
<span>调整零点位置</span>
</button>
<button class="btn btn-info" @onclick="SetZero">
<span>设置零点</span>
</button>
</div>
</div>
@code {
@ -44,6 +60,7 @@ @@ -44,6 +60,7 @@
private bool isTargetActive = false;
private bool isTargetOperationInProgress = false;
public ModelTrackControl ModelTrackControl { set; get; }
public int MoveStep { set; get; } = 0;
protected override void OnInitialized()
{
ModelTrackControl = this.GetModule<ModelTrackControl>();
@ -73,6 +90,14 @@ @@ -73,6 +90,14 @@
StateHasChanged();
}
private void SetPosition(){
this.ModelTrackControl.SetTargetPosition(MoveStep);
}
private void SetZero(){
this.ModelTrackControl.ManualClear();
}
}
<style>
@ -169,4 +194,21 @@ @@ -169,4 +194,21 @@
align-items: center;
z-index: 100;
}
.form-group {
margin-bottom: 1.5rem;
}
.form-group label {
display: block;
margin-bottom: 0.5rem;
font-weight: 500;
}
.form-control {
width: 100%;
padding: 0.5rem;
border: 1px solid #ced4da;
border-radius: 0.25rem;
}
</style>

11
Script/Model/ModelSerialTest.cs

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
using System.Runtime.InteropServices;
using EGFramework;
/// <summary>
@ -23,8 +24,16 @@ public class ModelSerialTest : EGModule,IEGFramework @@ -23,8 +24,16 @@ public class ModelSerialTest : EGModule,IEGFramework
public IUnRegister EngineInitEvent{ set; get; }
public override void Init()
{;
{
this.EGOnMessage<ResponseTarget>();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
IsLinux = false;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
IsLinux = true;
}
if (!IsLinux)
{
TestPort = PORT_WIN;

20
Script/Model/ModelTrackControl.cs

@ -48,6 +48,26 @@ public class ModelTrackControl : EGModule, IEGFramework @@ -48,6 +48,26 @@ public class ModelTrackControl : EGModule, IEGFramework
}
}
public void SetTargetPosition(int position)
{
if (position >= 0)
{
this.EGSendMessage(new RequestTargetControl(2000, (ushort)position, false), this.GetModule<ModelSerialTest>().EngineSerialPort, ProtocolType.SerialPort);
}
else
{
position = -position;
this.EGSendMessage(new RequestTargetControl(2000, (ushort)position, true), this.GetModule<ModelSerialTest>().EngineSerialPort, ProtocolType.SerialPort);
}
}
public void ManualClear()
{
this.EGSendMessage(new RequestTargetResetPosition(), this.GetModule<ModelSerialTest>().EngineSerialPort, ProtocolType.SerialPort);
CurrentRotation = 0;
this.GetModule<ModelActionStatus>().SetRotation(CurrentRotation);
}
public async void DelayClear()
{
await Task.Delay(3000);

Loading…
Cancel
Save