148 lines
4.4 KiB
C#
148 lines
4.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using CoreUnit.Common;
|
|
|
|
namespace CoreUnit.Motion.UserControl
|
|
{
|
|
public partial class SingleAxisHomeUserControl : System.Windows.Forms.UserControl
|
|
{
|
|
MotionUnit m_motionUnit = null;
|
|
BackgroundWorkerUnit m_backgroundWorkerUnit = null;
|
|
|
|
|
|
public SingleAxisHomeUserControl()
|
|
{
|
|
InitializeComponent();
|
|
|
|
m_backgroundWorkerUnit = new BackgroundWorkerUnit(this, 300);
|
|
m_backgroundWorkerUnit.evtDoWork += new BackgroundWorkerUnit.EventDoWork(UpdatePage);
|
|
|
|
}
|
|
private void UpdatePage()
|
|
{
|
|
try
|
|
{
|
|
uint rate = 0;
|
|
if (m_motionUnit.GetHomeRate(comboBoxAxis.SelectedIndex, ref rate) == 0)
|
|
{
|
|
if(rate ==0)
|
|
{
|
|
int alarmCode = 0;
|
|
m_motionUnit.GetServoAlarmCode(comboBoxAxis.SelectedIndex, ref alarmCode);
|
|
labelHomeStatus.Text = "Alarm : " + alarmCode;
|
|
progressBarHome.Value = (int)rate;
|
|
}
|
|
else if(rate == 100)
|
|
{
|
|
if(m_motionUnit.IsOriginComplete(comboBoxAxis.SelectedIndex))
|
|
{
|
|
labelHomeStatus.Text = "Home Complete";
|
|
progressBarHome.Value = (int)rate;
|
|
}
|
|
else
|
|
{
|
|
if(!m_motionUnit.IsServoOn(comboBoxAxis.SelectedIndex))
|
|
{
|
|
labelHomeStatus.Text = "Servo OFF";
|
|
progressBarHome.Value = 0;
|
|
}
|
|
else
|
|
{
|
|
labelHomeStatus.Text = "Need Home Searching";
|
|
progressBarHome.Value = 0;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
labelHomeStatus.Text = "Step: " + rate +" /100";
|
|
progressBarHome.Value = (int)rate;
|
|
}
|
|
}
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
throw new System.Exception(string.Format("ERR_GET_MOTION_STATUS_FAIL_TO_UPDATE;ERROR MSG:{0}", ex.Message));
|
|
}
|
|
}
|
|
|
|
|
|
public void Initialize(MotionUnit motionUnit)
|
|
{
|
|
m_motionUnit = motionUnit;
|
|
|
|
comboBoxAxis.Items.Clear();
|
|
|
|
|
|
foreach (Motion.InfoAxis axis in m_motionUnit.Axes)
|
|
{
|
|
comboBoxAxis.Items.Add(axis.AxisName);
|
|
}
|
|
|
|
if (comboBoxAxis.Items.Count != 0)
|
|
{
|
|
comboBoxAxis.SelectedIndex = 0;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
private void buttonPreviousAxis_Click(object sender, EventArgs e)
|
|
{
|
|
if (comboBoxAxis.SelectedIndex != 0)
|
|
{
|
|
int currentAxis = comboBoxAxis.SelectedIndex;
|
|
comboBoxAxis.SelectedIndex = currentAxis - 1;
|
|
}
|
|
}
|
|
|
|
private void buttonNextAxis_Click(object sender, EventArgs e)
|
|
{
|
|
if (comboBoxAxis.SelectedIndex < comboBoxAxis.Items.Count - 1)
|
|
{
|
|
int currentAxis = comboBoxAxis.SelectedIndex;
|
|
comboBoxAxis.SelectedIndex = currentAxis + 1;
|
|
}
|
|
}
|
|
|
|
private void SingleAxisStatusUserControl_VisibleChanged(object sender, EventArgs e)
|
|
{
|
|
if (Visible)
|
|
{
|
|
m_backgroundWorkerUnit.RunDoWork(sender);
|
|
}
|
|
else
|
|
{
|
|
m_backgroundWorkerUnit.StopDoWork();
|
|
}
|
|
}
|
|
|
|
private void buttonHome_Click(object sender, EventArgs e)
|
|
{
|
|
int rv = m_motionUnit.HomeStart(comboBoxAxis.SelectedIndex);
|
|
|
|
if (rv != 0)
|
|
{
|
|
labelHomeStatus.Text = rv.ToString();
|
|
}
|
|
|
|
}
|
|
|
|
private void buttonStop_Click(object sender, EventArgs e)
|
|
{
|
|
m_motionUnit.StopSingleAxis(comboBoxAxis.SelectedIndex);
|
|
}
|
|
}
|
|
}
|