You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
327 lines
11 KiB
C#
327 lines
11 KiB
C#
using Rs.Controls;
|
|
using Rs.Framework;
|
|
using Rs.Motion;
|
|
using Rs.Motion.Base;
|
|
using Rs.MotionPlat.Commom;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Rs.MotionPlat
|
|
{
|
|
public partial class AxisMove : UserControl
|
|
{
|
|
BindingList<RunResult> bindList = new BindingList<RunResult>();
|
|
public AxisMove()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private IAxis m_axis;
|
|
|
|
protected void CommonMoveDist_Click(object sender, EventArgs e)
|
|
{
|
|
Label lblNum = (Label)sender;
|
|
txtMoveDist.Text = lblNum.Text;
|
|
chkMoveStep.Checked = true;
|
|
}
|
|
|
|
protected void Calc_Click(object sender, EventArgs e)
|
|
{
|
|
chkMoveStep.Checked = true;
|
|
Label lblNum = (Label)sender;
|
|
if (lblNum.Text.ToLower() == "c")
|
|
{
|
|
txtMoveDist.Text = "";
|
|
}
|
|
else
|
|
{
|
|
if (lblNum.Text == ".")
|
|
{
|
|
if (txtMoveDist.Text.IndexOf(".") == -1 && txtMoveDist.Text.Length > 0)
|
|
txtMoveDist.Text += ".";
|
|
}
|
|
else
|
|
{
|
|
txtMoveDist.Text += lblNum.Text;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void tbarSpeed_ValueChanged(object sender, EventArgs e)
|
|
{
|
|
lblSpeed.Text = $"{tbarSpeed.Value}%";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 绑定轴
|
|
/// </summary>
|
|
/// <param name="axis"></param>
|
|
public void BindAxis(IAxis axis)
|
|
{
|
|
dataGridView1.AutoGenerateColumns = false;
|
|
bindList.Clear();
|
|
dataGridView1.DataSource = bindList;
|
|
lblDriver.Visible = txtDriverPos.Visible = false;
|
|
m_axis = axis;
|
|
if(m_axis.Config.EnableEncoder==1)
|
|
{
|
|
m_axis.GetDriverPosition(out double driverPos);
|
|
txtDriverPos.Text = driverPos.ToString("0.000");
|
|
lblDriver.Visible = true;
|
|
txtDriverPos.Visible = true;
|
|
}
|
|
timer1.Interval = 200;
|
|
timer1.Enabled = true;
|
|
|
|
label5.Visible = false;
|
|
txtAuEncPos.Visible = false;
|
|
if (m_axis != null && m_axis.Config.AssistEncoder > 0)
|
|
{
|
|
label5.Visible = true;
|
|
txtAuEncPos.Visible = true;
|
|
}
|
|
txtAxisPelLimit.Text=axis.Config.PelSoftwarePosition.ToString("0.000");
|
|
txtAxisNelLimit.Text = axis.Config.NelSoftwarePosition.ToString("0.000");
|
|
if(m_axis!=null && !m_axis.Config.CanJogMove)
|
|
{
|
|
chkMoveStep.Checked = true;
|
|
chkMoveStep.Enabled = false;
|
|
}
|
|
else
|
|
{
|
|
chkMoveStep.Enabled = true;
|
|
}
|
|
}
|
|
|
|
private void btnServoOn_Click(object sender, EventArgs e)
|
|
{
|
|
if(m_axis!=null)
|
|
{
|
|
m_axis.Enable();
|
|
}
|
|
}
|
|
|
|
private void btnServoOff_Click(object sender, EventArgs e)
|
|
{
|
|
if (m_axis != null)
|
|
{
|
|
m_axis.Disable();
|
|
}
|
|
}
|
|
|
|
private void timer1_Tick(object sender, EventArgs e)
|
|
{
|
|
if(m_axis!=null)
|
|
{
|
|
if(m_axis.Config.NeedGoHome==0)
|
|
{
|
|
btnGoHome.Visible = false;
|
|
}
|
|
else
|
|
{
|
|
btnGoHome.Visible = true;
|
|
}
|
|
ErrorCode errCode;
|
|
m_axis.GetPrfPosition(out double prfPos);
|
|
txtPrfPos.Text = prfPos.ToString("0.000");
|
|
m_axis.GetEncoderPosition(out double encPos);
|
|
txtEncPos.Text = encPos.ToString("0.000");
|
|
m_axis.GetAuEncoderPosition(out double auEncPos);
|
|
txtAuEncPos.Text = auEncPos.ToString("0.000");
|
|
if (m_axis.Config.EnableEncoder==1)
|
|
{
|
|
m_axis.GetDriverPosition(out double driverPos);
|
|
txtDriverPos.Text = driverPos.ToString("0.000");
|
|
}
|
|
if(m_axis.HomeStatus== Motion.EHomeStatus.Finished && lblHomed.BackColor!=Color.Lime)
|
|
lblHomed.BackColor = Color.Lime;
|
|
else if(m_axis.HomeStatus!= Motion.EHomeStatus.Finished)
|
|
{
|
|
if (lblHomed.BackColor != Color.Silver)
|
|
lblHomed.BackColor = Color.Silver;
|
|
}
|
|
m_axis.GetAlarmStatus(out bool bAlarm);
|
|
if (bAlarm && lblAxisAlarm.BackColor != Color.Lime)
|
|
{
|
|
lblAxisAlarm.BackColor = Color.Lime;
|
|
btnClearAlarm.Visible = true;
|
|
}
|
|
|
|
else if(bAlarm==false)
|
|
{
|
|
if (lblAxisAlarm.BackColor != Color.Silver)
|
|
{
|
|
lblAxisAlarm.BackColor = Color.Silver;
|
|
btnClearAlarm.Visible = false;
|
|
}
|
|
}
|
|
m_axis.IsEnable(out bool bServo);
|
|
if (bServo && lblAxisServo.BackColor != Color.Lime)
|
|
lblAxisServo.BackColor = Color.Lime;
|
|
else if(bServo==false)
|
|
{
|
|
if (lblAxisServo.BackColor != Color.Silver)
|
|
lblAxisServo.BackColor = Color.Silver;
|
|
}
|
|
errCode = m_axis.IsStop(out bool bStop);
|
|
if (!bStop && lblAxisMoving.BackColor != Color.Lime && errCode== ErrorCode.Ok)
|
|
lblAxisMoving.BackColor = Color.Lime;
|
|
else if (bStop)
|
|
{
|
|
if (lblAxisMoving.BackColor != Color.Silver)
|
|
lblAxisMoving.BackColor = Color.Silver;
|
|
}
|
|
m_axis.GetOrgStatus(out bool bOrg);
|
|
if (bOrg && lblOrg.BackColor != Color.Lime)
|
|
lblOrg.BackColor = Color.Lime;
|
|
else if (bOrg == false)
|
|
{
|
|
if (lblOrg.BackColor != Color.Silver)
|
|
lblOrg.BackColor = Color.Silver;
|
|
}
|
|
|
|
m_axis.GetPelStatus(out bool bPel);
|
|
if (bPel && lblPlimit.BackColor != Color.Lime)
|
|
lblPlimit.BackColor = Color.Lime;
|
|
else if (bPel == false)
|
|
{
|
|
if (lblPlimit.BackColor != Color.Silver)
|
|
lblPlimit.BackColor = Color.Silver;
|
|
}
|
|
|
|
m_axis.GetNelStatus(out bool bNel);
|
|
if (bNel && lblNlimit.BackColor != Color.Lime)
|
|
lblNlimit.BackColor = Color.Lime;
|
|
else if (bNel == false)
|
|
{
|
|
if (lblNlimit.BackColor != Color.Silver)
|
|
lblNlimit.BackColor = Color.Silver;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Mouse_Down(object sender,MouseEventArgs e)
|
|
{
|
|
if(m_axis!=null)
|
|
{
|
|
double.TryParse(txtMoveDist.Text, out double moveDistance);
|
|
int speed = tbarSpeed.Value;
|
|
ButtonEx button = (ButtonEx)sender;
|
|
if (chkMoveStep.Checked)//
|
|
{
|
|
if (button.ShowText == "-")
|
|
{
|
|
moveDistance *= -1;
|
|
}
|
|
ErrorCode errCode = m_axis.MoveOffset(moveDistance, speed);
|
|
AddMessage(errCode.ToString());
|
|
}
|
|
else
|
|
{
|
|
short dir = 1;
|
|
if (button.ShowText == "-")
|
|
dir = 0;
|
|
ErrorCode errCode = m_axis.MoveJog(dir, speed);
|
|
AddMessage(errCode.ToString());
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private void Mouse_Up(object sender,MouseEventArgs e)
|
|
{
|
|
if (m_axis != null && chkMoveStep.Checked==false)
|
|
{
|
|
m_axis.Stop();
|
|
}
|
|
}
|
|
|
|
private void btnGoHome_Click(object sender, EventArgs e)
|
|
{
|
|
if(m_axis!=null)
|
|
{
|
|
bool gohome = true;
|
|
if(m_axis.Config.AbsoluteEncoder==1)
|
|
{
|
|
DialogResult dr = MessageBox.Show($"{m_axis.Config.AxisName}轴为绝对值编码器,确定设置当前位置为零点位吗?", "Question?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
|
|
if(dr!= DialogResult.OK)
|
|
{
|
|
gohome = false;
|
|
}
|
|
}
|
|
if(gohome)
|
|
{
|
|
ErrorCode errCode = m_axis.Home();
|
|
AddMessage(errCode.ToString());
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnStop_Click(object sender, EventArgs e)
|
|
{
|
|
if(m_axis!=null)
|
|
{
|
|
ErrorCode errCode = m_axis.Stop();
|
|
m_axis.Abort_Go_Home();
|
|
AddMessage(errCode.ToString());
|
|
}
|
|
}
|
|
|
|
void AddMessage(string msg)
|
|
{
|
|
if (bindList.Count > 10)
|
|
bindList.RemoveAt(bindList.Count - 1);
|
|
bindList.Insert(0, new RunResult() {
|
|
Time = DateTime.Now.ToString("HH:ss:mm fff"),
|
|
Result = msg
|
|
});
|
|
}
|
|
|
|
private void lblAxisAlarm_Click(object sender, EventArgs e)
|
|
{
|
|
if(m_axis != null)
|
|
{
|
|
ErrorCode errCode = m_axis.ClearAlarm();
|
|
AddMessage(errCode.ToString());
|
|
}
|
|
}
|
|
|
|
private void AxisMove_Load(object sender, EventArgs e)
|
|
{
|
|
//MessageBox.Show(Thread.CurrentThread.CurrentUICulture.DisplayName);
|
|
if(Thread.CurrentThread.CurrentUICulture.Name=="zh-CN")
|
|
{
|
|
ControlLanguageHelper.SetDefaultLanguage("zh-CN");
|
|
}
|
|
else
|
|
{
|
|
ControlLanguageHelper.SetDefaultLanguage("en-US");
|
|
}
|
|
ControlLanguageHelper.LoadLanguage(this, this.GetType());
|
|
}
|
|
|
|
private void btnClearAlarm_Click(object sender, EventArgs e)
|
|
{
|
|
if (m_axis != null)
|
|
{
|
|
ErrorCode errCode = m_axis.ClearAlarm();
|
|
AddMessage(errCode.ToString());
|
|
}
|
|
}
|
|
}
|
|
|
|
public class RunResult
|
|
{
|
|
public string Time { get; set; }
|
|
public string Result { get; set; }
|
|
}
|
|
}
|