增加移动命令前,电机状态的检查; 关闭窗体,关闭服务

This commit is contained in:
zhengxuan.zhang
2024-03-26 17:23:13 +08:00
parent 264c4c5601
commit 54170f3a52
3 changed files with 67 additions and 29 deletions
+52 -14
View File
@@ -87,6 +87,8 @@ namespace HexcalMC
DebugDfn._strEndTime = DateTime.Now.ToString("yyyy.MM.dd HH-mm-ss");
timer_RefreshUI.Stop();
Btn_StopServer_Click(null,null);
Btn_ACSStop_Click(null, null);//关闭ACS
string copyFileName = DebugDfn.StrDebugSavePath + "\\Debug(" + DebugDfn._strStartTime + " To " +
DebugDfn._strEndTime + ")" + ".txt";
@@ -177,6 +179,7 @@ namespace HexcalMC
private Label[] _mlblAcc; //加速中
private Label[] _mlblInPos; //轴就位
private Label[] _mlblEnable; //使能
bool[] axisEnabled = new bool[MaxUiLimitCnt]; //轴使能状态
private HomeStates _homeStates; //回家状态
private MotionStates _currentMotionState; //当前运动状态
@@ -241,6 +244,8 @@ namespace HexcalMC
}
}
private void ReceiveByte(object sender, byte[] e)
{
DebugDfn.AddLogText("接收到" + BitConverter.ToString(e));
@@ -543,7 +548,6 @@ namespace HexcalMC
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
// 防止程序终止
MessageBox.Show("发生了未处理的异常:" + e.Exception.Message);
}
@@ -664,8 +668,6 @@ namespace HexcalMC
int bit = 0x01;
int axisNo = 0;
//DebugDfn.AddLogText(string.Format(" {0}", axis));
for (int i = 0; i < 64; i++)
{
if ((int)axis == bit)
@@ -677,11 +679,6 @@ namespace HexcalMC
bit = bit << 1;
}
if (axisNo == 2)
{
return;
}
//DebugDfn.AddLogText(string.Format(" - Axis {0}, Stoppped", axisNo));
}
@@ -738,7 +735,6 @@ namespace HexcalMC
return false;
}
private void TmrMonitor_Tick(object sender, EventArgs e) //用于刷新状态
{
if (_mAcsConnected)
@@ -935,10 +931,12 @@ namespace HexcalMC
if ((_mNMotorState & MotorStates.ACSC_MST_ENABLE) != 0)
{
_mlblEnable[_axisNo].Image = Resources.On;
axisEnabled[_axisNo] = true; //轴使能
}
else
{
_mlblEnable[_axisNo].Image = Resources.Off;
axisEnabled[_axisNo] = false;
}
}
}
@@ -1072,7 +1070,6 @@ namespace HexcalMC
EnableFaultEvent(); //订阅错误事件
}
public static bool IsWithinLimit(Point3D point) //判断点是否在行程范围内
{
if (point.X >= XMinstrokesw && point.X <= XMaxstrokesw &&
@@ -1108,6 +1105,19 @@ namespace HexcalMC
point3D.Y,
point3D.Z
};
//判断各轴使能状态,如果未使能,则使能
bool totalEnabled = CalculateTotalEnabled(axisEnabled, 0, 1, 8);
DebugDfn.AddLogText($"总的使能状态为:{(totalEnabled ? "使" : "使")}");
if (!totalEnabled)
{
_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); //多轴运动到指定位置
@@ -1184,9 +1194,8 @@ namespace HexcalMC
_acs.SetDeceleration(Axis.ACSC_AXIS_8, speed * 10);
}
private void rtb_quick_loc_Click(object sender, EventArgs e)
private void rtb_quick_loc_Click(object sender, EventArgs e)//快速定位
{
//获取输入
// 获取文本框的值
double x = double.Parse(rtb_SetX.Text);
@@ -1199,14 +1208,43 @@ namespace HexcalMC
SetPositionXyz(point);
}
static bool CalculateTotalEnabled(bool[] axisEnabled, params int[] axisIndices)//判断轴使能状态
{
bool totalEnabled = true;
foreach (int index in axisIndices)
{
bool isEnabled = axisEnabled[index];
if (!isEnabled)
{
totalEnabled = false;
break;
}
}
return totalEnabled;
}
#endregion ACS平台相关
#region
private void btn_motion_Click(object sender, EventArgs e)
{
Motion motion = new Motion(_acs);
motion.Show();
//判断通讯对象是否存在
if (_acs == null || !_acs.IsConnected)
{
DebugDfn.AddLogText("未建立通讯,请在主界面先建立通讯");
// 在合适的位置调用 MessageBox.Show() 方法
MessageBox.Show("未建立通讯,请在主界面先建立通讯", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else
{
Motion motion = new Motion(_acs);
motion.Show();
}
}
private void Rtb_about_Click(object sender, EventArgs e) //关于界面
+1 -1
View File
@@ -557,8 +557,8 @@
this.cboAxisNo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboAxisNo.FormattingEnabled = true;
this.cboAxisNo.Items.AddRange(new object[] {
"1",
"0",
"1",
"8"});
this.cboAxisNo.Location = new System.Drawing.Point(115, 20);
this.cboAxisNo.Name = "cboAxisNo";
+14 -14
View File
@@ -19,7 +19,7 @@ namespace HexcalMC
private const int MaxUiLimitCnt = 8;
private const int MaxUiIoCnt = 8;
private readonly Api _acs;
private readonly int _motionTimeout = 5000; //延时时间
private readonly int _motionTimeout = 50000; //延时时间
private readonly Axis[] UseAxis = MainFrom.UseAxis; //获取激活的轴
@@ -223,6 +223,8 @@ namespace HexcalMC
#region
InitMotion();
#endregion
@@ -242,15 +244,7 @@ namespace HexcalMC
string strTemp;
int i;
//判断通讯对象是否存在
if (_acs == null || !_acs.IsConnected)
{
DebugDfn.AddLogText("未建立通讯,请在主界面先建立通讯");
// 在合适的位置调用 MessageBox.Show() 方法
MessageBox.Show("未建立通讯,请在主界面先建立通讯", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
_mBConnected = _acs.IsConnected;
// Get Total number of axes
@@ -913,11 +907,15 @@ namespace HexcalMC
}
// Add log to ListBox
Invoke((MethodInvoker)delegate
if (lstLog.IsHandleCreated)
{
lstLog.Items.Add(string.Format(" - Axis {0}, Stoppped", axisNo));
lstLog.SelectedIndex = lstLog.Items.Count - 1;
});
Invoke((MethodInvoker)delegate
{
lstLog.Items.Add(string.Format(" - Axis {0}, Stoppped", axisNo));
lstLog.SelectedIndex = lstLog.Items.Count - 1;
});
}
}
private void BtnEventProgramEnd_Click(object sender, EventArgs e)
@@ -1056,6 +1054,8 @@ namespace HexcalMC
0,
0
};
//执行运动指令
_acs.ToPointM(MotionFlags.ACSC_NONE, UseAxis, pointsArray); //多轴运动到指定位置