From 54170f3a5249dcb935002312d33ff8d0c0c707dc Mon Sep 17 00:00:00 2001 From: "zhengxuan.zhang" Date: Tue, 26 Mar 2024 17:23:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=A7=BB=E5=8A=A8=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E5=89=8D=EF=BC=8C=E7=94=B5=E6=9C=BA=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E7=9A=84=E6=A3=80=E6=9F=A5=EF=BC=9B=20=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E7=AA=97=E4=BD=93=EF=BC=8C=E5=85=B3=E9=97=AD=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HexcalMC/MainFrom.cs | 66 +++++++++++++++++++++++------- HexcalMC/Motion/Motion.Designer.cs | 2 +- HexcalMC/Motion/Motion.cs | 28 ++++++------- 3 files changed, 67 insertions(+), 29 deletions(-) diff --git a/HexcalMC/MainFrom.cs b/HexcalMC/MainFrom.cs index 8405c6f..a51ad30 100644 --- a/HexcalMC/MainFrom.cs +++ b/HexcalMC/MainFrom.cs @@ -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) //关于界面 diff --git a/HexcalMC/Motion/Motion.Designer.cs b/HexcalMC/Motion/Motion.Designer.cs index a427460..7152a05 100644 --- a/HexcalMC/Motion/Motion.Designer.cs +++ b/HexcalMC/Motion/Motion.Designer.cs @@ -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"; diff --git a/HexcalMC/Motion/Motion.cs b/HexcalMC/Motion/Motion.cs index 2ef44b0..4ff5971 100644 --- a/HexcalMC/Motion/Motion.cs +++ b/HexcalMC/Motion/Motion.cs @@ -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); //多轴运动到指定位置