From 5bc1b4aa6d7dfb8cd92679b65d9e81e3d646463f Mon Sep 17 00:00:00 2001 From: "zhengxuan.zhang" Date: Thu, 28 Mar 2024 10:03:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=A7=BB=E5=8A=A8=E5=89=8D?= =?UTF-8?q?=20=E8=BD=B4=E4=BD=BF=E8=83=BD=E7=8A=B6=E6=80=81=E7=9A=84?= =?UTF-8?q?=E5=88=A4=E6=96=AD=EF=BC=8C=E5=BD=93=E8=BD=B4=E6=9C=AA=E4=BD=BF?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E4=BD=BF=E8=83=BD=E8=BD=B4=E5=B9=B6=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8=EF=BC=9B=E5=A2=9E=E5=8A=A0=E4=BA=86=E7=9B=91=E5=90=AC?= =?UTF-8?q?=E7=AB=AF=E5=8F=A3=E7=9A=84=E9=85=8D=E7=BD=AE=EF=BC=9B=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E4=BA=8B=E4=BB=B6=E7=9A=84=E6=B3=A8=E5=86=8C=E5=92=8C?= =?UTF-8?q?=E9=94=80=E6=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HexcalMC/HexcalMC.csproj | 1 + HexcalMC/MainFrom.Designer.cs | 21 +++++++++++- HexcalMC/MainFrom.cs | 40 ++++++++++++++++++----- HexcalMC/Motion/Motion.cs | 39 +++++++++++++--------- HexcalMC/Properties/Resources.Designer.cs | 10 ++++++ HexcalMC/Properties/Resources.resx | 9 +++-- 6 files changed, 92 insertions(+), 28 deletions(-) diff --git a/HexcalMC/HexcalMC.csproj b/HexcalMC/HexcalMC.csproj index 082c6f8..fd186d6 100644 --- a/HexcalMC/HexcalMC.csproj +++ b/HexcalMC/HexcalMC.csproj @@ -282,6 +282,7 @@ + diff --git a/HexcalMC/MainFrom.Designer.cs b/HexcalMC/MainFrom.Designer.cs index 36be145..6ca791d 100644 --- a/HexcalMC/MainFrom.Designer.cs +++ b/HexcalMC/MainFrom.Designer.cs @@ -56,6 +56,8 @@ this.rtb_SetX = new Telerik.WinControls.UI.RadTextBoxElement(); this.rtb_Sety = new Telerik.WinControls.UI.RadTextBoxElement(); this.rtb_SetZ = new Telerik.WinControls.UI.RadTextBoxElement(); + this.radRibbonBarGroup7 = new Telerik.WinControls.UI.RadRibbonBarGroup(); + this.rtb_stop = new Telerik.WinControls.UI.RadButtonElement(); this.ribbonTab2 = new Telerik.WinControls.UI.RibbonTab(); this.radRibbonBarGroup2 = new Telerik.WinControls.UI.RadRibbonBarGroup(); this.rtb_about = new Telerik.WinControls.UI.RadButtonElement(); @@ -211,7 +213,8 @@ this.radRibbonBarGroup1, this.radRibbonBarGroup4, this.radRibbonBarGroup5, - this.radRibbonBarGroup6}); + this.radRibbonBarGroup6, + this.radRibbonBarGroup7}); this.ribbonTab1.Name = "ribbonTab1"; this.ribbonTab1.Text = "常用"; this.ribbonTab1.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault; @@ -394,6 +397,20 @@ this.rtb_SetZ.TextAlign = System.Windows.Forms.HorizontalAlignment.Left; this.rtb_SetZ.UseCompatibleTextRendering = false; // + // radRibbonBarGroup7 + // + this.radRibbonBarGroup7.Items.AddRange(new Telerik.WinControls.RadItem[] { + this.rtb_stop}); + this.radRibbonBarGroup7.Name = "radRibbonBarGroup7"; + this.radRibbonBarGroup7.Text = "立即停止"; + // + // rtb_stop + // + this.rtb_stop.Image = global::HexcalMC.Properties.Resources.stop; + this.rtb_stop.Name = "rtb_stop"; + this.rtb_stop.Text = ""; + this.rtb_stop.Click += new System.EventHandler(this.rtb_stop_Click); + // // ribbonTab2 // this.ribbonTab2.AutoEllipsis = false; @@ -1445,5 +1462,7 @@ private Telerik.WinControls.UI.RadTextBoxElement rtb_SetX; private Telerik.WinControls.UI.RadTextBoxElement rtb_Sety; private Telerik.WinControls.UI.RadTextBoxElement rtb_SetZ; + private Telerik.WinControls.UI.RadRibbonBarGroup radRibbonBarGroup7; + private Telerik.WinControls.UI.RadButtonElement rtb_stop; } } diff --git a/HexcalMC/MainFrom.cs b/HexcalMC/MainFrom.cs index a51ad30..65b8d4f 100644 --- a/HexcalMC/MainFrom.cs +++ b/HexcalMC/MainFrom.cs @@ -128,6 +128,9 @@ namespace HexcalMC XMinstrokesw = FileIni.ReadDouble(StrConfigFile, "MOTOR", "X_MINSTROKESW"); YMinstrokesw = FileIni.ReadDouble(StrConfigFile, "MOTOR", "Y_MINSTROKESW"); ZMinstrokesw = FileIni.ReadDouble(StrConfigFile, "MOTOR", "Z_MINSTROKESW"); + + port = FileIni.ReadInt(StrConfigFile, "MOTOR", "Port"); + DebugDfn.AddLogText($"当前监听端口{port}"); } private void Plot2D(List pointCloud) @@ -180,6 +183,7 @@ namespace HexcalMC private Label[] _mlblInPos; //轴就位 private Label[] _mlblEnable; //使能 bool[] axisEnabled = new bool[MaxUiLimitCnt]; //轴使能状态 + public bool totalAxisEnabled = false; private HomeStates _homeStates; //回家状态 private MotionStates _currentMotionState; //当前运动状态 @@ -200,6 +204,7 @@ namespace HexcalMC public static double XMinstrokesw = -30; //负限位 public static double YMinstrokesw = -10; public static double ZMinstrokesw = -280; + public static int port = 1234; //默认监听端口 //定义一个3D点,存储当前平台位置 private Point3D _mPoint3D; @@ -221,7 +226,7 @@ namespace HexcalMC } //启动服务器,并获取数据,解析 - _mTcpIpServer = new TcpIpServer(IPAddress.Any.ToString(), Convert.ToString(1234)); + _mTcpIpServer = new TcpIpServer(IPAddress.Any.ToString(), Convert.ToString(port)); _mTcpIpServer.UseMode = 1; //设置通讯返回数据流格式 try { @@ -244,8 +249,6 @@ namespace HexcalMC } } - - private void ReceiveByte(object sender, byte[] e) { DebugDfn.AddLogText("接收到" + BitConverter.ToString(e)); @@ -834,10 +837,12 @@ namespace HexcalMC private void Btn_ACSStop_Click(object sender, EventArgs e) //断开连接 { - DisableFaultEvent(); + if (_mAcsConnected) { + DisableFaultEvent(); _acs.CloseComm(); + } tmrMonitor.Stop(); @@ -939,6 +944,9 @@ namespace HexcalMC axisEnabled[_axisNo] = false; } } + + totalAxisEnabled = CalculateTotalEnabled(axisEnabled, 0, 1, 8); + DebugDfn.AddLogText($"总的使能状态为:{(totalAxisEnabled ? "使能" : "未使能")}"); } private void IsHomed() //读取回家状态,当未回家时执行回家指令 @@ -1106,9 +1114,8 @@ namespace HexcalMC point3D.Z }; //判断各轴使能状态,如果未使能,则使能 - bool totalEnabled = CalculateTotalEnabled(axisEnabled, 0, 1, 8); - DebugDfn.AddLogText($"总的使能状态为:{(totalEnabled ? "使能" : "未使能")}"); - if (!totalEnabled) + + if (!totalAxisEnabled) { _acs.EnableM(UseAxis); for (int i = 0; i < UseAxis.Length; i++) @@ -1222,6 +1229,23 @@ namespace HexcalMC } return totalEnabled; } + + private void rtb_stop_Click(object sender, EventArgs e) + { + try + { + Axis[] m_arrAxisList = new Axis[] { Axis.ACSC_AXIS_0, Axis.ACSC_AXIS_1, Axis.ACSC_AXIS_8, Axis.ACSC_NONE }; + + if (m_arrAxisList != null) _acs.HaltM(m_arrAxisList); + + DebugDfn.AddLogText("立即停止 已发送命令"); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); + Debug.WriteLine(ex.Message); + } + } #endregion ACS平台相关 #region 菜单栏 @@ -1240,7 +1264,7 @@ namespace HexcalMC } else { - Motion motion = new Motion(_acs); + Motion motion = new Motion(this); motion.Show(); } diff --git a/HexcalMC/Motion/Motion.cs b/HexcalMC/Motion/Motion.cs index 4ff5971..897d03e 100644 --- a/HexcalMC/Motion/Motion.cs +++ b/HexcalMC/Motion/Motion.cs @@ -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); //等待回家完成 } diff --git a/HexcalMC/Properties/Resources.Designer.cs b/HexcalMC/Properties/Resources.Designer.cs index 3c2023e..c2b881b 100644 --- a/HexcalMC/Properties/Resources.Designer.cs +++ b/HexcalMC/Properties/Resources.Designer.cs @@ -189,5 +189,15 @@ namespace HexcalMC.Properties { return ((System.Drawing.Bitmap)(obj)); } } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap stop { + get { + object obj = ResourceManager.GetObject("stop", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } } } diff --git a/HexcalMC/Properties/Resources.resx b/HexcalMC/Properties/Resources.resx index 2d44e38..f8a1cee 100644 --- a/HexcalMC/Properties/Resources.resx +++ b/HexcalMC/Properties/Resources.resx @@ -136,9 +136,6 @@ ..\Resources\Hexagon.ico;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\help.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - ..\Resources\quick_location.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -157,4 +154,10 @@ ..\Resources\demo_show.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\help.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\stop.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file