Files
LM-Middleware/HexcalMC/Motion/DemoShow.cs
T
2025-03-29 16:20:59 +08:00

151 lines
3.4 KiB
C#

using ACS.SPiiPlusNET;
using System;
using System.Drawing;
using System.Windows.Forms;
using Telerik.WinControls.UI;
namespace HexcalMC
{
public partial class DemoShow : RadForm
{
public enum DemoStatus
{
NotStarted, // 未演示
InProgress, // 演示中
Completed, // 演示完成
Error // 演示出错
}
private readonly Api _motionApi;
public DemoShow(Api mothionApi)
{
InitializeComponent();
if (mothionApi == null)
{
throw new ArgumentNullException("运动平台未连接");
}
_motionApi = mothionApi;
Status = DemoStatus.NotStarted;
}
public DemoStatus Status { get; set; }
public TimeSpan TotalDuration { get; set; }
private void btn_StartShow_Click(object sender, EventArgs e)
{
if (_motionApi == null)
{
MessageBox.Show("Motion API is not initialized.", "提示", MessageBoxButtons.OK,
MessageBoxIcon.Information);
return;
}
//判断通讯状态
if (!_motionApi.IsConnected)
{
//连接失败
MessageBox.Show("请先点击连接运动平台", "提示", MessageBoxButtons.OK,
MessageBoxIcon.Information);
return;
}
//判断是否在演示中
if (Status == DemoStatus.InProgress)
{
MessageBox.Show("演示正在进行中,请先停止演示", "提示", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
//运行演示
try
{
_motionApi.RunBuffer(ProgramBuffer.ACSC_BUFFER_12, null);
Status = DemoStatus.InProgress;
}
catch (Exception exception)
{
MessageBox.Show("运行演示失败:" + exception.Message, "提示", MessageBoxButtons.OK,
MessageBoxIcon.Information);
Status = DemoStatus.Error;
throw;
}
}
private void btn_StopShow_Click(object sender, EventArgs e)
{
if (_motionApi == null)
{
MessageBox.Show("Motion API is not initialized.", "提示", MessageBoxButtons.OK,
MessageBoxIcon.Information);
return;
}
if (!_motionApi.IsConnected)
{
MessageBox.Show("请先点击连接运动平台", "提示", MessageBoxButtons.OK,
MessageBoxIcon.Information);
return;
}
if (Status != DemoStatus.InProgress)
{
MessageBox.Show("演示未开始或已结束", "提示", MessageBoxButtons.OK,
MessageBoxIcon.Information);
return;
}
try
{
_motionApi.StopBuffer(ProgramBuffer.ACSC_BUFFER_12); //停止演示
Status = DemoStatus.Completed;
}
catch (Exception exception)
{
MessageBox.Show("运行演示失败:" + exception.Message, "提示", MessageBoxButtons.OK,
MessageBoxIcon.Information);
throw;
}
}
private void timer_UI_Tick(object sender, EventArgs e)
{
lable_showstatus.Text = Status.ToString();
switch (Status)
{
case DemoStatus.NotStarted:
lable_showstatus.ForeColor = Color.Black;
lable_showstatus.Text = "未演示";
break;
case DemoStatus.InProgress:
lable_showstatus.ForeColor = Color.Blue;
lable_showstatus.Text = "演示中";
break;
case DemoStatus.Completed:
lable_showstatus.ForeColor = Color.Green;
lable_showstatus.Text = "演示完成";
break;
case DemoStatus.Error:
lable_showstatus.ForeColor = Color.Red;
lable_showstatus.Text = "演示出错";
break;
}
}
private void DemoShow_Load(object sender, EventArgs e)
{
timer_UI.Start();
}
private void DemoShow_FormClosing(object sender, FormClosingEventArgs e)
{
timer_UI.Stop();
}
}
}