增加移动前 轴使能状态的判断,当轴未使能,使能轴并移动;增加了监听端口的配置;异常事件的注册和销毁

This commit is contained in:
zhengxuan.zhang
2024-03-28 10:03:37 +08:00
parent 54170f3a52
commit 5bc1b4aa6d
6 changed files with 92 additions and 28 deletions
+23 -16
View File
@@ -46,14 +46,16 @@ namespace HexcalMC
private int _mNValues, _mNOutputState;
private object _mObjReadVar;
public Motion(Api api)
private readonly MainFrom mainFrom;
public Motion(MainFrom mainFrom)
{
InitializeComponent();
_acs = api; //初始化 ACS运动控制类
this.mainFrom = mainFrom; // 存储传递的主窗体对象
_acs = this.mainFrom._acs; //初始化 ACS运动控制类
// Register Event 注册时间
_acs.PHYSICALMOTIONEND += ACS_PHYSICALMOTIONEND;
_acs.PHYSICALMOTIONEND += ACS_PHYSICALMOTIONEND; // Register Event 注册时间
_acs.PROGRAMEND += ACS_PROGRAMEND;
}
@@ -223,8 +225,6 @@ namespace HexcalMC
#region
InitMotion();
#endregion
@@ -244,7 +244,6 @@ namespace HexcalMC
string strTemp;
int i;
_mBConnected = _acs.IsConnected;
// Get Total number of axes
@@ -392,7 +391,6 @@ namespace HexcalMC
{
try
{
_mNMotorState = _acs.GetMotorState((Axis)iAxisNo);
// Returned value is integer, you need to use bitmaks
@@ -620,12 +618,9 @@ namespace HexcalMC
{
try
{
// There is no halt all command, so you need to user HaltM function
//
// ex) You want to stop 0, 2, 5 axis
// int[] m_arrAxisList = new int[] { 0, 2, 5, -1 };
//
if (_mArrAxisList != null) _acs.HaltM(_mArrAxisList);
Axis[] m_arrAxisList = new Axis[] { Axis.ACSC_AXIS_0, Axis.ACSC_AXIS_1, Axis.ACSC_AXIS_8, Axis.ACSC_NONE };
if (_mArrAxisList != null) _acs.HaltM(m_arrAxisList);
}
catch (Exception ex)
{
@@ -914,7 +909,6 @@ namespace HexcalMC
lstLog.Items.Add(string.Format(" - Axis {0}, Stoppped", axisNo));
lstLog.SelectedIndex = lstLog.Items.Count - 1;
});
}
}
@@ -1055,12 +1049,25 @@ namespace HexcalMC
0
};
//判断电机状态
if (!this.mainFrom.totalAxisEnabled)
{
DebugDfn.AddLogText("存在电机未使能");
_acs.EnableM(UseAxis);
for (int i = 0; i < UseAxis.Length; i++)
{
_acs.WaitMotorEnabled(UseAxis[i], 1, _motionTimeout); //等待电机使能
}
DebugDfn.AddLogText("电机已启用");
}
//执行运动指令
_acs.ToPointM(MotionFlags.ACSC_NONE, UseAxis, pointsArray); //多轴运动到指定位置
//等待运动完成
for (int i = 0; i < UseAxis.Length-1; i++)
for (int i = 0; i < UseAxis.Length - 1; i++)
{
_acs.WaitMotionEnd(UseAxis[i], _motionTimeout); //等待回家完成
}