104 lines
2.7 KiB
C#
104 lines
2.7 KiB
C#
using ACS.SPiiPlusNET;
|
|
using HexcalMC.Base;
|
|
using System;
|
|
using System.Windows.Forms;
|
|
|
|
namespace HexcalMC
|
|
{
|
|
public partial class MonitorForm : System.Windows.Forms.Form
|
|
{
|
|
private readonly MainForm mainFrom;
|
|
private readonly Api _acs; //ACS控制器
|
|
|
|
private double[] dataX; // X轴数据(时间戳)
|
|
private double[] dataY; // Y轴数据(动态值)
|
|
private int dataLength = 200; // 显示的数据点数量:ml-citation{ref="4,5" data="citationList"}
|
|
private Random rand = new Random();
|
|
|
|
public MonitorForm(MainForm _mainFrom)
|
|
{
|
|
InitializeComponent();
|
|
|
|
mainFrom = _mainFrom;
|
|
this._acs = _mainFrom._acs;
|
|
|
|
this.MaximizeBox = false;
|
|
this.MinimizeBox = false;
|
|
|
|
InitializePlot();
|
|
}
|
|
|
|
// 初始化图表
|
|
private void InitializePlot()
|
|
{
|
|
// 初始化数据数组
|
|
dataX = new double[dataLength];
|
|
dataY = new double[dataLength];
|
|
|
|
// 填充初始数据(示例为随机值)
|
|
for (int i = 0; i < dataLength; i++)
|
|
{
|
|
dataX[i] = System.DateTime.Now.AddSeconds(-dataLength + i).ToOADate();
|
|
dataY[i] = rand.NextDouble() * 100;
|
|
}
|
|
|
|
// 绘制初始曲线
|
|
formsPlot1.Plot.AddScatter(dataX, dataY);
|
|
formsPlot1.Plot.XAxis.DateTimeFormat(true); // X轴显示为时间格式:ml-citation{ref="3" data="citationList"}
|
|
formsPlot1.Plot.XLabel("时间");
|
|
formsPlot1.Plot.YLabel("数值");
|
|
formsPlot1.Plot.Title("Z轴速度-实时动态图");
|
|
formsPlot1.Refresh();
|
|
}
|
|
|
|
// 定时器事件:更新数据并刷新图表
|
|
|
|
private void dataTimer_Tick(object sender, EventArgs e)
|
|
{
|
|
// 生成新数据(模拟实时数据)
|
|
//double newValue = rand.NextDouble() * 100;
|
|
double newValue = GetSpeed(8);
|
|
DebugDfn.AddLogText("newValue:" + newValue);
|
|
|
|
// 数据滚动更新:移除旧数据,添加新数据:ml-citation{ref="4,5" data="citationList"}
|
|
Array.Copy(dataY, 1, dataY, 0, dataY.Length - 1);
|
|
dataY[dataY.Length - 1] = newValue;
|
|
|
|
// 更新时间戳
|
|
Array.Copy(dataX, 1, dataX, 0, dataX.Length - 1);
|
|
dataX[dataX.Length - 1] = System.DateTime.Now.ToOADate();
|
|
|
|
// 在UI线程中更新图表
|
|
formsPlot1.Invoke((MethodInvoker)delegate
|
|
{
|
|
formsPlot1.Plot.Clear();
|
|
formsPlot1.Plot.AddScatter(dataX, dataY);
|
|
formsPlot1.Refresh();
|
|
});
|
|
}
|
|
|
|
private double GetSpeed(int axis)
|
|
{
|
|
//判断对象是否为空
|
|
if (_acs == null)
|
|
{
|
|
return 0;
|
|
}
|
|
// 获取当前速度
|
|
|
|
return _acs.GetRVelocity((ACS.SPiiPlusNET.Axis)axis);
|
|
}
|
|
|
|
private void btn_etalon_import_Click(object sender, EventArgs e)
|
|
{
|
|
//启动定时器刷新
|
|
dataTimer.Start();
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
//停止定时器刷新
|
|
dataTimer.Stop();
|
|
}
|
|
}
|
|
} |