diff --git a/HexcalMC/Base/BaseFunction.cs b/HexcalMC/Base/BaseFunction.cs index d2b61b5..1c60f15 100644 --- a/HexcalMC/Base/BaseFunction.cs +++ b/HexcalMC/Base/BaseFunction.cs @@ -6,12 +6,13 @@ using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; +using System.Net.NetworkInformation; using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; - +using System.Net.NetworkInformation; namespace HexcalMC.Base { @@ -2948,8 +2949,26 @@ namespace HexcalMC.Base #endregion } - public class IpAddressValidator + + + class Internet { + + public static bool IsIpReachable(string ipAddress) + { + try + { + Ping ping = new Ping(); + PingReply reply = ping.Send(ipAddress); + return (reply.Status == IPStatus.Success); + } + catch (PingException) + { + // 发生 Ping 异常,IP 不可达 + return false; + } + } + public static bool IsIpAddressValid(string ipAddress) { string pattern = @"^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"; diff --git a/HexcalMC/Hexcal/TcpIpServer.cs b/HexcalMC/Hexcal/TcpIpServer.cs index 6d56bf7..f164d72 100644 --- a/HexcalMC/Hexcal/TcpIpServer.cs +++ b/HexcalMC/Hexcal/TcpIpServer.cs @@ -156,7 +156,7 @@ namespace HexcalMC.Hexcal } catch (Exception e) { - throw new Exception("WatchThread异常" + e); + //throw new Exception("WatchThread异常" + e); } } @@ -284,15 +284,32 @@ namespace HexcalMC.Hexcal } } + public bool TrySendData(Socket socket, byte[] data) + { + int sentBytes = socket.Send(data); + return sentBytes == data.Length; // 检查是否完全发送成功 + } public void SendMessageToAllClients(string strMsg) { byte[] arrMsg = Encoding.Default.GetBytes(strMsg); foreach (Socket soc in _dictSocket.Values) { - soc.Send(arrMsg); + bool success = TrySendData(soc, arrMsg); + if (!success) + { + // 如果发送失败,进行重发逻辑 + int attemptCount = 0; + const int maxAttempts = 3; + while (!success && attemptCount < maxAttempts) + { + success = TrySendData(soc, arrMsg); + attemptCount++; + } + } } } + public void SendMessageToAllClients(byte[] arrMsg) { foreach (Socket soc in _dictSocket.Values) diff --git a/HexcalMC/HexcalMC.csproj b/HexcalMC/HexcalMC.csproj index f91d3ee..405214f 100644 --- a/HexcalMC/HexcalMC.csproj +++ b/HexcalMC/HexcalMC.csproj @@ -159,6 +159,12 @@ MainFrom.cs + + Form + + + DemoShow.cs + Form @@ -178,6 +184,9 @@ Designer MainFrom1.Designer.cs + + DemoShow.cs + Motion.cs Designer @@ -234,6 +243,9 @@ + + + diff --git a/HexcalMC/MainFrom.Designer.cs b/HexcalMC/MainFrom.Designer.cs index 6ecd783..32dbc52 100644 --- a/HexcalMC/MainFrom.Designer.cs +++ b/HexcalMC/MainFrom.Designer.cs @@ -36,7 +36,7 @@ this.radTextBoxElement1 = new Telerik.WinControls.UI.RadTextBoxElement(); this.ribbonTab1 = new Telerik.WinControls.UI.RibbonTab(); this.radRibbonBarGroup1 = new Telerik.WinControls.UI.RadRibbonBarGroup(); - this.rtb_motion = new Telerik.WinControls.UI.RadButtonElement(); + this.btn_motion = new Telerik.WinControls.UI.RadButtonElement(); this.radRibbonBarGroup4 = new Telerik.WinControls.UI.RadRibbonBarGroup(); this.radRibbonBarButtonGroup4 = new Telerik.WinControls.UI.RadRibbonBarButtonGroup(); this.radLabelElement5 = new Telerik.WinControls.UI.RadLabelElement(); @@ -47,6 +47,9 @@ this.radRibbonBarButtonGroup6 = new Telerik.WinControls.UI.RadRibbonBarButtonGroup(); this.radLabelElement7 = new Telerik.WinControls.UI.RadLabelElement(); this.rtb_zPos = new Telerik.WinControls.UI.RadTextBoxElement(); + this.radRibbonBarGroup5 = new Telerik.WinControls.UI.RadRibbonBarGroup(); + this.radRibbonBarButtonGroup7 = new Telerik.WinControls.UI.RadRibbonBarButtonGroup(); + this.rtb_demo = 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(); @@ -136,6 +139,7 @@ this.TextBoxMsg = new System.Windows.Forms.RichTextBox(); this.tmrMonitor = new System.Windows.Forms.Timer(this.components); this.timer_RefreshUI = new System.Windows.Forms.Timer(this.components); + this.radRibbonBarGroup6 = new Telerik.WinControls.UI.RadRibbonBarGroup(); ((System.ComponentModel.ISupportInitialize)(this.radRibbonBar1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.radRibbonBarBackstageView1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.radStatusStrip1)).BeginInit(); @@ -201,7 +205,9 @@ this.ribbonTab1.IsSelected = true; this.ribbonTab1.Items.AddRange(new Telerik.WinControls.RadItem[] { this.radRibbonBarGroup1, - this.radRibbonBarGroup4}); + this.radRibbonBarGroup4, + this.radRibbonBarGroup5, + this.radRibbonBarGroup6}); this.ribbonTab1.Name = "ribbonTab1"; this.ribbonTab1.Text = "常用"; this.ribbonTab1.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault; @@ -210,11 +216,11 @@ // // radRibbonBarGroup1 // - this.radRibbonBarGroup1.Alignment = System.Drawing.ContentAlignment.MiddleCenter; + this.radRibbonBarGroup1.Alignment = System.Drawing.ContentAlignment.TopLeft; this.radRibbonBarGroup1.AutoSize = false; - this.radRibbonBarGroup1.Bounds = new System.Drawing.Rectangle(0, 0, 110, 100); + this.radRibbonBarGroup1.Bounds = new System.Drawing.Rectangle(0, 0, 77, 100); this.radRibbonBarGroup1.Items.AddRange(new Telerik.WinControls.RadItem[] { - this.rtb_motion}); + this.btn_motion}); this.radRibbonBarGroup1.Margin = new System.Windows.Forms.Padding(0); this.radRibbonBarGroup1.MaxSize = new System.Drawing.Size(110, 100); this.radRibbonBarGroup1.MinSize = new System.Drawing.Size(110, 100); @@ -222,17 +228,12 @@ this.radRibbonBarGroup1.Text = "运动控制"; this.radRibbonBarGroup1.UseCompatibleTextRendering = false; // - // rtb_motion + // btn_motion // - this.rtb_motion.Alignment = System.Drawing.ContentAlignment.MiddleCenter; - this.rtb_motion.Image = global::HexcalMC.Properties.Resources.motion; - this.rtb_motion.Name = "rtb_motion"; - this.rtb_motion.Text = "ACS调试"; - this.rtb_motion.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter; - this.rtb_motion.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText; - this.rtb_motion.TextOrientation = System.Windows.Forms.Orientation.Horizontal; - this.rtb_motion.UseCompatibleTextRendering = false; - this.rtb_motion.Click += new System.EventHandler(this.Rtb_motion_Click); + this.btn_motion.Image = global::HexcalMC.Properties.Resources.mothion_64; + this.btn_motion.Name = "btn_motion"; + this.btn_motion.Text = ""; + this.btn_motion.Click += new System.EventHandler(this.btn_motion_Click); // // radRibbonBarGroup4 // @@ -312,6 +313,28 @@ this.rtb_zPos.Text = "-50.000"; this.rtb_zPos.TextAlign = System.Windows.Forms.HorizontalAlignment.Left; // + // radRibbonBarGroup5 + // + this.radRibbonBarGroup5.Items.AddRange(new Telerik.WinControls.RadItem[] { + this.radRibbonBarButtonGroup7}); + this.radRibbonBarGroup5.Name = "radRibbonBarGroup5"; + this.radRibbonBarGroup5.Text = "演示模式"; + // + // radRibbonBarButtonGroup7 + // + this.radRibbonBarButtonGroup7.Items.AddRange(new Telerik.WinControls.RadItem[] { + this.rtb_demo}); + this.radRibbonBarButtonGroup7.Name = "radRibbonBarButtonGroup7"; + this.radRibbonBarButtonGroup7.Text = "radRibbonBarButtonGroup7"; + // + // rtb_demo + // + this.rtb_demo.Image = global::HexcalMC.Properties.Resources.demo_show; + this.rtb_demo.Name = "rtb_demo"; + this.rtb_demo.Text = ""; + this.rtb_demo.TextAlignment = System.Drawing.ContentAlignment.BottomLeft; + this.rtb_demo.Click += new System.EventHandler(this.rtb_demo_Click); + // // ribbonTab2 // this.ribbonTab2.AutoEllipsis = false; @@ -1210,6 +1233,11 @@ this.timer_RefreshUI.Interval = 1000; this.timer_RefreshUI.Tick += new System.EventHandler(this.Timer_RefreshUI_Tick); // + // radRibbonBarGroup6 + // + this.radRibbonBarGroup6.Name = "radRibbonBarGroup6"; + this.radRibbonBarGroup6.Text = "快速定位"; + // // MainFrom // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); @@ -1267,7 +1295,6 @@ private Telerik.WinControls.UI.RadTextBoxElement radTextBoxElement1; private Telerik.WinControls.UI.RibbonTab ribbonTab1; private Telerik.WinControls.UI.RadRibbonBarGroup radRibbonBarGroup1; - private Telerik.WinControls.UI.RadButtonElement rtb_motion; private Telerik.WinControls.UI.RibbonTab ribbonTab2; private Telerik.WinControls.UI.RadRibbonBarGroup radRibbonBarGroup2; private Telerik.WinControls.UI.RadButtonElement rtb_about; @@ -1367,5 +1394,10 @@ private ScottPlot.FormsPlot formsPlot1; private System.Windows.Forms.Integration.ElementHost elementHost1; private SharpGL.OpenGLControl openGLControl1; + private Telerik.WinControls.UI.RadRibbonBarGroup radRibbonBarGroup5; + private Telerik.WinControls.UI.RadRibbonBarButtonGroup radRibbonBarButtonGroup7; + private Telerik.WinControls.UI.RadButtonElement rtb_demo; + private Telerik.WinControls.UI.RadButtonElement btn_motion; + private Telerik.WinControls.UI.RadRibbonBarGroup radRibbonBarGroup6; } } diff --git a/HexcalMC/MainFrom.cs b/HexcalMC/MainFrom.cs index e73794e..66c6d35 100644 --- a/HexcalMC/MainFrom.cs +++ b/HexcalMC/MainFrom.cs @@ -85,17 +85,18 @@ namespace HexcalMC //启动界面刷新 timer_RefreshUI.Start(); - this.TopMost = true; + //TopMost = true; } private void MainFrom_Shown(object sender, EventArgs e) //窗体显示准备好接受用户输入时发生 { - //启动服务端,用于接收hexcal传来的指令 - StartServer(); + ////启动服务端,用于接收hexcal传来的指令 + //StartServer(); - Btn_ACSStart_Click(null, null); - - //Plot3D(); + //if (_enableAcs) + //{ + // Btn_ACSStart_Click(null, null); //模拟连接运动平台 + //} } private void MainFrom_FormClosed(object sender, FormClosedEventArgs e) @@ -132,16 +133,19 @@ namespace HexcalMC return; } - MOTION_SPEED = FileIni.ReadDouble(StrConfigFile, "MOTOR", "MOTION_SPEED"); //运动定位速度 + //上电使能ACS + _enableAcs = FileIni.ReadBool(StrConfigFile, "MOTOR", "ENABLE_ACS"); + + MotionSpeed = FileIni.ReadDouble(StrConfigFile, "MOTOR", "MOTION_SPEED"); //运动定位速度 //正限位 - X_MAXSTROKESW = FileIni.ReadDouble(StrConfigFile, "MOTOR", "X_MAXSTROKESW"); - Y_MAXSTROKESW = FileIni.ReadDouble(StrConfigFile, "MOTOR", "Y_MAXSTROKESW"); - Z_MAXSTROKESW = FileIni.ReadDouble(StrConfigFile, "MOTOR", "Z_MAXSTROKESW"); + XMaxstrokesw = FileIni.ReadDouble(StrConfigFile, "MOTOR", "X_MAXSTROKESW"); + YMaxstrokesw = FileIni.ReadDouble(StrConfigFile, "MOTOR", "Y_MAXSTROKESW"); + ZMaxstrokesw = FileIni.ReadDouble(StrConfigFile, "MOTOR", "Z_MAXSTROKESW"); //负限位 - X_MINSTROKESW = FileIni.ReadDouble(StrConfigFile, "MOTOR", "X_MINSTROKESW"); - Y_MINSTROKESW = FileIni.ReadDouble(StrConfigFile, "MOTOR", "Y_MINSTROKESW"); - Z_MINSTROKESW = FileIni.ReadDouble(StrConfigFile, "MOTOR", "Z_MINSTROKESW"); + XMinstrokesw = FileIni.ReadDouble(StrConfigFile, "MOTOR", "X_MINSTROKESW"); + YMinstrokesw = FileIni.ReadDouble(StrConfigFile, "MOTOR", "Y_MINSTROKESW"); + ZMinstrokesw = FileIni.ReadDouble(StrConfigFile, "MOTOR", "Z_MINSTROKESW"); } private void Plot2D(List pointCloud) @@ -180,75 +184,35 @@ namespace HexcalMC } - #region 运动平台变量区 - - private Api _acs; - - private const int MaxUiLimitCnt = 8; - private const int MaxUiIoCnt = 8; - - private readonly int _mNTotalAxis = 0; - private int _mNTotalBuffer = 0; - private Axis[] _mArrAxisList = null; - - private bool _mAcsConnected; //ACS通讯状态 - - // For update values - private MotorStates _mNMotorState; //运动状态 - - private ProgramStates _mNProgramState; //程序状态 - private object _mObjReadVar; - private Array _mArrReadVector; - private double _mLfRPos, _mLfFPos, _mLfPe, _mLfFvel; //参考位置,反馈位置 位置误差 反馈速度 double类型 - private int _mNValues, _mNOutputState; - - private Label[] _mLblLeftLimit; //左限位 - private Label[] _mLblRightLimit; //右限位 - - private HomeStates _homeStates; //回家状态 - private MotionStates _currentMotionState; //当前运动状态 - private readonly int _motionTimeout = 50000; //定义运动超时时间 - - - public static Axis[] USE_AXIS = - { Axis.ACSC_AXIS_1, Axis.ACSC_AXIS_0, Axis.ACSC_AXIS_8, Axis.ACSC_NONE }; //定义启用的轴,后面运动时会使用 - - - //定义 XYZ三个轴的左右行程范围 - public string StrConfigFile = Application.StartupPath + "\\File\\config.ini"; - public static double MOTION_SPEED = 60; - public static double X_MAXSTROKESW = 730; //正限位 - public static double Y_MAXSTROKESW = 1000; - public static double Z_MAXSTROKESW = 5; - - public static double X_MINSTROKESW = -30; //负限位 - public static double Y_MINSTROKESW = -10; - public static double Z_MINSTROKESW = -280; - - #endregion - - #region hexcal变量区 + #region hexcal软件交互 private TcpIpServer _mTcpIpServer; //创建tcpserver,用于接收hexcal传来的指令,并解析传递平台 private bool _mBHexcalConnected; - - #endregion - - - #region hexcal软件交互 + public string LISTEN_ADDRESS = "100.0.0.1"; private void StartServer() { // 对_mTcpIpServer增加判断是否已经启动且存在设备连接 - if (_mTcpIpServer != null) + if (_mTcpIpServer != null && _mTcpIpServer.ConnectStatus) { //弹窗提醒已经启动 + MyBase.TraceWriteLine("TCP服务端已经启动,请勿重复启动"); MessageBox.Show("TCP服务端已经启动,请勿重复启动", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } + //判断 要监听的IP地址是否存在 + + if (!Internet.IsIpReachable(LISTEN_ADDRESS)) + { + MyBase.TraceWriteLine("启动服务失败,请确认本地网卡是否启用且配置 " + LISTEN_ADDRESS); + MessageBox.Show("请确认本地网卡是否启用且配置 " + LISTEN_ADDRESS, "启动服务失败"); + return; + } + + //启动服务器,并获取数据,解析 - _mTcpIpServer = new TcpIpServer("100.0.0.1", Convert.ToString(1234)); + _mTcpIpServer = new TcpIpServer(LISTEN_ADDRESS, Convert.ToString(1234)); _mTcpIpServer.UseMode = 1; //设置通讯返回数据流格式 try { @@ -348,10 +312,17 @@ namespace HexcalMC private void ParseHexcalMsg(string msg) //编写一个Hexcal协议解析函数 { DebugDfn.AddLogText("正在解析 " + msg); + //去除Msg中\r\n msg = msg.Replace("\r\n", ""); + //判断是否含有故障ERROR字样 - if (msg.Contains("ERROR")) return; + if (msg.Contains("ERROR")) + { + //弹窗提醒 + MessageBox.Show("CMM错误", msg, MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } if (msg.Contains("\x02") || msg.Contains("\u0002")) { @@ -377,17 +348,18 @@ namespace HexcalMC else if (msg.Contains("SHOW MAXSTROKESW")) //最大行程,根据实际情况填写 { - //SendMsgToHexcal("MAXSTROKESW 233.200000,346.500000,15.100000,0.000000,0.000000,0.000000,0.000000"); + //MAXSTROKESW 233.200000,346.500000,15.100000,0.000000,0.000000,0.000000,0.000000 - double[] values = { X_MAXSTROKESW, Y_MAXSTROKESW, Z_MAXSTROKESW, 0.0, 0.0, 0.0, 0.0 }; + double[] values = { XMaxstrokesw, YMaxstrokesw, ZMaxstrokesw, 0.0, 0.0, 0.0, 0.0 }; string resultString = ConstructString("MAXSTROKESW", values); SendMsgToHexcal(resultString); } + else if (msg.Contains("SHOW MINSTROKESW")) //最小行程,根据实际情况填写 { - //SendMsgToHexcal("MINSTROKESW -68.800000,-55.500000,-286.900000,0.000000,0.000000,0.000000,0.000000"); + //MINSTROKESW -68.800000,-55.500000,-286.900000,0.000000,0.000000,0.000000,0.000000 - double[] values = { X_MINSTROKESW, Y_MINSTROKESW, Z_MINSTROKESW, 0.0, 0.0, 0.0, 0.0 }; + double[] values = { XMinstrokesw, YMinstrokesw, ZMinstrokesw, 0.0, 0.0, 0.0, 0.0 }; string resultString = ConstructString("MINSTROKESW", values); SendMsgToHexcal(resultString); } @@ -416,9 +388,9 @@ namespace HexcalMC { SendMsgToHexcal("Z_SENSAXIS 7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"); } - else if (msg.Contains("SHOW TEMPCOMPTYPE")) //温度补偿,温度补偿 >1 表示支持温度补偿 + else if (msg.Contains("SHOW TEMPCOMPTYPE")) //温度补偿,温度补偿 >1 表示支持温度补偿,此处不支持 { - SendMsgToHexcal("TEMPCOMPTYPE 1"); + SendMsgToHexcal("TEMPCOMPTYPE 0"); } else if (msg.Contains("READTP")) { @@ -470,6 +442,10 @@ namespace HexcalMC { SendMsgToHexcal("%"); } + else if (msg.Contains("DISABLE GEO")) + { + SendMsgToHexcal("%"); + } else if (msg.Contains("AUTZER")) //回家指令 { SendMsgToHexcal("%"); //收到并执行,同时状态改为忙碌 @@ -489,7 +465,7 @@ namespace HexcalMC } else if (msg.Contains("GETPOS")) //获取位置 { - //SendMsgToHexcal("POS 167.553898,-55.400421,-208.548678,0.000000,0.000000,0.000000,0.000000"); + //POS 167.553898,-55.400421,-208.548678,0.000000,0.000000,0.000000,0.000000 Point3D point3D = GetPositionXyz(); //获取当前位置 string resultString = ConstructPosString(point3D); SendMsgToHexcal(resultString); @@ -542,12 +518,66 @@ namespace HexcalMC #region ACS平台相关 + #region 运动平台变量区 + + public Api _acs; + + private const int MaxUiLimitCnt = 8; + private const int MaxUiIoCnt = 8; + + private readonly int _mNTotalAxis = 0; + private int _mNTotalBuffer = 0; + private Axis[] _mArrAxisList = null; + + public bool _mAcsConnected; //ACS通讯状态 + + // For update values + private MotorStates _mNMotorState; //运动状态 + + private ProgramStates _mNProgramState; //程序状态 + private object _mObjReadVar; + private Array _mArrReadVector; + private double _mLfRPos, _mLfFPos, _mLfPe, _mLfFvel; //参考位置,反馈位置 位置误差 反馈速度 double类型 + private int _mNValues, _mNOutputState; + + private Label[] _mLblLeftLimit; //左限位 + private Label[] _mLblRightLimit; //右限位 + + private HomeStates _homeStates; //回家状态 + private MotionStates _currentMotionState; //当前运动状态 + private readonly int _motionTimeout = 50000; //定义运动超时时间 + + + public static Axis[] UseAxis = + { Axis.ACSC_AXIS_1, Axis.ACSC_AXIS_0, Axis.ACSC_AXIS_8, Axis.ACSC_NONE }; //定义启用的轴,后面运动时会使用 + + //定义轴的运动状态 + private readonly bool[] axisFinished = new bool[10]; // 假设只有轴 0、1和8,数组大小为10(0到9) + + //定义 XYZ三个轴的左右行程范围 + public string StrConfigFile = Application.StartupPath + "\\File\\config.ini"; + public static double MotionSpeed = 60; + public static double XMaxstrokesw = 730; //正限位 + public static double YMaxstrokesw = 1000; + public static double ZMaxstrokesw = 5; + + public static double XMinstrokesw = -30; //负限位 + public static double YMinstrokesw = -10; + public static double ZMinstrokesw = -280; + + private bool _enableAcs; //读取配置,是否上电自动连接平台 + + private Point3D _mPoint3D; //定义一个3D点,存储当前平台位置 + private Point3D _mPoint3DLast; //存储上一周期的位置 + + #endregion + private void BtnEnable_Click(object sender, EventArgs e) //使能所有轴 { if (_mAcsConnected) { //!!!! Important !! Must insert '-1' at the last - _acs.EnableM(USE_AXIS); + _acs.EnableM(UseAxis); } else { @@ -562,6 +592,36 @@ namespace HexcalMC _acs.DisableAll(); } + private bool IsMotionInPose() + { + bool x_inpose = false, y_inpose = false, z_inpose = false; + + _mNMotorState = _acs.GetMotorState(Axis.ACSC_AXIS_1); + if ((_mNMotorState & MotorStates.ACSC_MST_INPOS) != 0) + { + x_inpose = true; + } + + _mNMotorState = _acs.GetMotorState(Axis.ACSC_AXIS_0); + if ((_mNMotorState & MotorStates.ACSC_MST_INPOS) != 0) + { + y_inpose = true; + } + + _mNMotorState = _acs.GetMotorState(Axis.ACSC_AXIS_8); + if ((_mNMotorState & MotorStates.ACSC_MST_INPOS) != 0) + { + z_inpose = true; + } + + if (x_inpose && y_inpose && z_inpose) + { + return true; + } + + return false; + } + private void TmrMonitor_Tick(object sender, EventArgs e) //用于刷新状态 { int iAxisNo = cboAxisNo.SelectedIndex; @@ -569,6 +629,9 @@ namespace HexcalMC { try { + //获取平台当前位置 + _mPoint3D = GetPositionXyz(); + // Get Motor State ACSPL+ Variable : MST (integer) _mNMotorState = _acs.GetMotorState((Axis)iAxisNo); @@ -589,7 +652,7 @@ namespace HexcalMC if ((_mNMotorState & MotorStates.ACSC_MST_INPOS) != 0) { lblInPos.Image = Resources.On; - _currentMotionState = MotionStates.InPos; + //_currentMotionState = MotionStates.InPos; } else { @@ -622,6 +685,17 @@ namespace HexcalMC MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + if (IsMotionInPose()) + { + _currentMotionState = MotionStates.InPos; + DebugDfn.AddLogText("运动到位"); + } + else + { + _currentMotionState = MotionStates.Moving; + DebugDfn.AddLogText("运动中"); + } } private void Btn_ACSStart_Click(object sender, EventArgs e) //连接 @@ -722,9 +796,9 @@ namespace HexcalMC DebugDfn.AddLogText("回家运动中"); //等待回家完成 - for (int i = 0; i < USE_AXIS.Length; i++) + for (int i = 0; i < UseAxis.Length; i++) { - _acs.WaitMotionEnd(USE_AXIS[i], _motionTimeout); //等待回家完成 + _acs.WaitMotionEnd(UseAxis[i], _motionTimeout); //等待回家完成 } _homeStates = HomeStates.Homed; @@ -759,10 +833,10 @@ namespace HexcalMC } //轴启用,加电 - _acs.EnableM(USE_AXIS); - for (int i = 0; i < USE_AXIS.Length; i++) + _acs.EnableM(UseAxis); + for (int i = 0; i < UseAxis.Length; i++) { - _acs.WaitMotorEnabled(USE_AXIS[i], 1, _motionTimeout); //等待电机使能 + _acs.WaitMotorEnabled(UseAxis[i], 1, _motionTimeout); //等待电机使能 } DebugDfn.AddLogText("电机已启用"); @@ -773,42 +847,47 @@ namespace HexcalMC SetSpeedXyz(); //注册到位事件 - _acs.PHYSICALMOTIONEND += ACS_PHYSICALMOTIONEND; + //_acs.PHYSICALMOTIONEND += ACS_PHYSICALMOTIONEND; _acs.EnableEvent(Interrupts.ACSC_INTR_PHYSICAL_MOTION_END); } private void ACS_PHYSICALMOTIONEND(AxisMasks axis) { - int bit = 0x01; - int axisNo = 0; - // Param value is bit number - // Bit Number = Axis Number - for (int i = 0; i < 64; i++) + //int bit = 0x01; + //int axisNo = 0; + + //for (int i = 0; i < 64; i++) + //{ + // if ((int)axis == bit) + // { + // axisNo = i; + // axisFinished[axisNo] = true; // 将对应轴的完成情况标记为 true + // Console.WriteLine($" %d %d",axisNo, axisFinished[axisNo]); + // break; + // } + + // bit = bit << 1; + //} + //打印数组 axisFinished + + + // 检查轴0、1和8是否全部完成 + //if (axisFinished[0] && axisFinished[1] && axisFinished[8]) { - if ((int)axis == bit) + // 三个轴均完成后的操作 + Invoke((MethodInvoker)delegate { - axisNo = i; - break; - } - - bit = bit << 1; + _currentMotionState = MotionStates.InPos; + //DebugDfn.AddLogText("运动到位"); + }); } - - // Add log to ListBox - Invoke((MethodInvoker)delegate - { - DebugDfn.AddLogText("运动到位"); - _currentMotionState = MotionStates.InPos; - DebugDfn.AddLogText("运动到位"); - - }); } private bool IsWithinStrokes(Point3D point) //判断点是否在行程范围内 { - if (point.X >= X_MINSTROKESW && point.X <= X_MAXSTROKESW && - point.Y >= Y_MINSTROKESW && point.Y <= Y_MAXSTROKESW && - point.Z >= Z_MINSTROKESW && point.Z <= Z_MAXSTROKESW) + if (point.X >= XMinstrokesw && point.X <= XMaxstrokesw && + point.Y >= YMinstrokesw && point.Y <= YMaxstrokesw && + point.Z >= ZMinstrokesw && point.Z <= ZMaxstrokesw) { return true; } @@ -841,7 +920,7 @@ namespace HexcalMC }; //执行运动指令 - _acs.ToPointM(MotionFlags.ACSC_NONE, USE_AXIS, pointsArray); //多轴运动到指定位置 + _acs.ToPointM(MotionFlags.ACSC_NONE, UseAxis, pointsArray); //多轴运动到指定位置 ////等待运动完成 //for (int i = 0; i < USE_AXIS.Length; i++) @@ -881,17 +960,17 @@ namespace HexcalMC if (positionMode == 1) { //获取反馈位置 Feedback position (Encoder value) ACSPL+ Variable : FPO (real) - xPosition = _acs.GetFPosition(USE_AXIS[0]); - yPosition = _acs.GetFPosition(USE_AXIS[1]); - zPosition = _acs.GetFPosition(USE_AXIS[2]); - DebugDfn.AddLogText("反馈位置: " + xPosition + " " + yPosition + " " + zPosition); + xPosition = _acs.GetFPosition(UseAxis[0]); + yPosition = _acs.GetFPosition(UseAxis[1]); + zPosition = _acs.GetFPosition(UseAxis[2]); + //DebugDfn.AddLogText("反馈位置: " + xPosition + " " + yPosition + " " + zPosition); } else { //获取参考位置 ACSPL+ Variable : RPOS (real) - xPosition = _acs.GetRPosition(USE_AXIS[0]); - yPosition = _acs.GetRPosition(USE_AXIS[1]); - zPosition = _acs.GetRPosition(USE_AXIS[2]); + xPosition = _acs.GetRPosition(UseAxis[0]); + yPosition = _acs.GetRPosition(UseAxis[1]); + zPosition = _acs.GetRPosition(UseAxis[2]); DebugDfn.AddLogText("参考位置: " + xPosition + " " + yPosition + " " + zPosition); } @@ -909,20 +988,19 @@ namespace HexcalMC DebugDfn.AddLogText("实际速度: " + feedbackVelocity); //设置Y轴 速度参数 - _acs.SetVelocity(Axis.ACSC_AXIS_0, MOTION_SPEED); - _acs.SetAcceleration(Axis.ACSC_AXIS_0,MOTION_SPEED*10); - _acs.SetDeceleration(Axis.ACSC_AXIS_0,MOTION_SPEED*10); + _acs.SetVelocity(Axis.ACSC_AXIS_0, MotionSpeed); + _acs.SetAcceleration(Axis.ACSC_AXIS_0, MotionSpeed * 10); + _acs.SetDeceleration(Axis.ACSC_AXIS_0, MotionSpeed * 10); //设置X轴速度参数 - _acs.SetVelocity(Axis.ACSC_AXIS_1, MOTION_SPEED); - _acs.SetAcceleration(Axis.ACSC_AXIS_1, MOTION_SPEED * 10); - _acs.SetDeceleration(Axis.ACSC_AXIS_1, MOTION_SPEED * 10); + _acs.SetVelocity(Axis.ACSC_AXIS_1, MotionSpeed); + _acs.SetAcceleration(Axis.ACSC_AXIS_1, MotionSpeed * 10); + _acs.SetDeceleration(Axis.ACSC_AXIS_1, MotionSpeed * 10); //设置Z轴速度参数 - _acs.SetVelocity(Axis.ACSC_AXIS_8, MOTION_SPEED); - _acs.SetAcceleration(Axis.ACSC_AXIS_8, MOTION_SPEED * 10); - _acs.SetDeceleration(Axis.ACSC_AXIS_8, MOTION_SPEED * 10); - + _acs.SetVelocity(Axis.ACSC_AXIS_8, MotionSpeed); + _acs.SetAcceleration(Axis.ACSC_AXIS_8, MotionSpeed * 10); + _acs.SetDeceleration(Axis.ACSC_AXIS_8, MotionSpeed * 10); } private void openGLControl1_OpenGLDraw(object sender, RenderEventArgs args) @@ -974,15 +1052,13 @@ namespace HexcalMC { } - - #endregion ACS平台相关 #region 菜单栏 - private void Rtb_motion_Click(object sender, EventArgs e) //ACS调试页面 + private void btn_motion_Click(object sender, EventArgs e) { - Motion motion = new Motion(); + Motion motion = new Motion(_acs); motion.Show(); } @@ -993,6 +1069,13 @@ namespace HexcalMC mAboutBox.Show(); } + private void rtb_demo_Click(object sender, EventArgs e) + { + DemoShow demoShow = new DemoShow(_acs); + demoShow.Show(); + demoShow.BringToFront(); + } + private void Timer_RefreshUI_Tick(object sender, EventArgs e) //UI刷新 { //状态灯刷新 @@ -1004,6 +1087,14 @@ namespace HexcalMC rle_timer.Text = "当前时间: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); Plot2D(_pointCloud); //绘图 + + //更新位置 + if (_mPoint3D != null) + { + rtb_xPos.Text = _mPoint3D.X.ToString("F3"); + rtb_yPos.Text = _mPoint3D.Y.ToString("F3"); + rtb_zPos.Text = _mPoint3D.Z.ToString("F3"); + } } #endregion 菜单栏 diff --git a/HexcalMC/Motion/Motion.Designer.cs b/HexcalMC/Motion/Motion.Designer.cs index bc1d22c..8640d51 100644 --- a/HexcalMC/Motion/Motion.Designer.cs +++ b/HexcalMC/Motion/Motion.Designer.cs @@ -37,8 +37,6 @@ this.btnOpen = new System.Windows.Forms.Button(); this.label2 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); - this.rdoTCP = new System.Windows.Forms.RadioButton(); - this.rdoSimu = new System.Windows.Forms.RadioButton(); this.tmrMonitor = new System.Windows.Forms.Timer(this.components); this.grpMotionTest = new System.Windows.Forms.GroupBox(); this.btnHallAll = new System.Windows.Forms.Button(); @@ -185,7 +183,7 @@ this.label49 = new System.Windows.Forms.Label(); this.label47 = new System.Windows.Forms.Label(); this.groupBox8 = new System.Windows.Forms.GroupBox(); - this.button8 = new System.Windows.Forms.Button(); + this.btn_movepose = new System.Windows.Forms.Button(); this.checkBox1 = new System.Windows.Forms.CheckBox(); this.textBox3 = new System.Windows.Forms.TextBox(); this.textBox2 = new System.Windows.Forms.TextBox(); @@ -194,19 +192,19 @@ this.label45 = new System.Windows.Forms.Label(); this.label44 = new System.Windows.Forms.Label(); this.groupBox7 = new System.Windows.Forms.GroupBox(); - this.button7 = new System.Windows.Forms.Button(); - this.button6 = new System.Windows.Forms.Button(); - this.button5 = new System.Windows.Forms.Button(); - this.button4 = new System.Windows.Forms.Button(); + this.btn_Y_Back = new System.Windows.Forms.Button(); + this.btn_X_right = new System.Windows.Forms.Button(); + this.btn_X_left = new System.Windows.Forms.Button(); + this.btn_Y_Forward = new System.Windows.Forms.Button(); this.groupBox6 = new System.Windows.Forms.GroupBox(); - this.button3 = new System.Windows.Forms.Button(); - this.button2 = new System.Windows.Forms.Button(); - this.button1 = new System.Windows.Forms.Button(); + this.btn_home = new System.Windows.Forms.Button(); + this.btn_stop = new System.Windows.Forms.Button(); + this.btn_start = new System.Windows.Forms.Button(); this.groupBox10 = new System.Windows.Forms.GroupBox(); this.label48 = new System.Windows.Forms.Label(); this.textBox4 = new System.Windows.Forms.TextBox(); - this.button10 = new System.Windows.Forms.Button(); - this.button9 = new System.Windows.Forms.Button(); + this.btn_halt = new System.Windows.Forms.Button(); + this.btn_run = new System.Windows.Forms.Button(); this.checkBox4 = new System.Windows.Forms.CheckBox(); this.checkBox3 = new System.Windows.Forms.CheckBox(); this.checkBox2 = new System.Windows.Forms.CheckBox(); @@ -238,8 +236,6 @@ this.groupBox1.Controls.Add(this.btnOpen); this.groupBox1.Controls.Add(this.label2); this.groupBox1.Controls.Add(this.label1); - this.groupBox1.Controls.Add(this.rdoTCP); - this.groupBox1.Controls.Add(this.rdoSimu); this.groupBox1.Location = new System.Drawing.Point(12, 12); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(273, 94); @@ -249,7 +245,7 @@ // // txtPort // - this.txtPort.Location = new System.Drawing.Point(171, 40); + this.txtPort.Location = new System.Drawing.Point(103, 37); this.txtPort.Name = "txtPort"; this.txtPort.Size = new System.Drawing.Size(91, 21); this.txtPort.TabIndex = 15; @@ -257,15 +253,15 @@ // // txtIP // - this.txtIP.Location = new System.Drawing.Point(171, 17); + this.txtIP.Location = new System.Drawing.Point(103, 14); this.txtIP.Name = "txtIP"; this.txtIP.Size = new System.Drawing.Size(91, 21); this.txtIP.TabIndex = 16; - this.txtIP.Text = "10.0.0.100"; + this.txtIP.Text = "100.0.0.100"; // // btnClose // - this.btnClose.Location = new System.Drawing.Point(181, 65); + this.btnClose.Location = new System.Drawing.Point(113, 62); this.btnClose.Name = "btnClose"; this.btnClose.Size = new System.Drawing.Size(81, 23); this.btnClose.TabIndex = 14; @@ -275,7 +271,7 @@ // // btnOpen // - this.btnOpen.Location = new System.Drawing.Point(94, 65); + this.btnOpen.Location = new System.Drawing.Point(7, 62); this.btnOpen.Name = "btnOpen"; this.btnOpen.Size = new System.Drawing.Size(81, 23); this.btnOpen.TabIndex = 13; @@ -286,7 +282,7 @@ // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(102, 44); + this.label2.Location = new System.Drawing.Point(15, 41); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(29, 12); this.label2.TabIndex = 11; @@ -295,36 +291,12 @@ // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(102, 21); + this.label1.Location = new System.Drawing.Point(15, 18); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(71, 12); this.label1.TabIndex = 12; this.label1.Text = "目标设备 IP"; // - // rdoTCP - // - this.rdoTCP.AutoSize = true; - this.rdoTCP.Location = new System.Drawing.Point(6, 19); - this.rdoTCP.Name = "rdoTCP"; - this.rdoTCP.Size = new System.Drawing.Size(41, 16); - this.rdoTCP.TabIndex = 10; - this.rdoTCP.TabStop = true; - this.rdoTCP.Text = "TCP"; - this.rdoTCP.UseVisualStyleBackColor = true; - this.rdoTCP.CheckedChanged += new System.EventHandler(this.RdoTCP_CheckedChanged); - // - // rdoSimu - // - this.rdoSimu.AutoSize = true; - this.rdoSimu.Location = new System.Drawing.Point(6, 42); - this.rdoSimu.Name = "rdoSimu"; - this.rdoSimu.Size = new System.Drawing.Size(59, 16); - this.rdoSimu.TabIndex = 9; - this.rdoSimu.TabStop = true; - this.rdoSimu.Text = "模拟器"; - this.rdoSimu.UseVisualStyleBackColor = true; - this.rdoSimu.CheckedChanged += new System.EventHandler(this.RdoSimu_CheckedChanged); - // // tmrMonitor // this.tmrMonitor.Interval = 50; @@ -584,6 +556,10 @@ // this.cboAxisNo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cboAxisNo.FormattingEnabled = true; + this.cboAxisNo.Items.AddRange(new object[] { + "1", + "0", + "8"}); this.cboAxisNo.Location = new System.Drawing.Point(115, 20); this.cboAxisNo.Name = "cboAxisNo"; this.cboAxisNo.Size = new System.Drawing.Size(60, 20); @@ -1814,7 +1790,7 @@ // // groupBox8 // - this.groupBox8.Controls.Add(this.button8); + this.groupBox8.Controls.Add(this.btn_movepose); this.groupBox8.Controls.Add(this.checkBox1); this.groupBox8.Controls.Add(this.textBox3); this.groupBox8.Controls.Add(this.textBox2); @@ -1829,14 +1805,15 @@ this.groupBox8.TabStop = false; this.groupBox8.Text = "定位"; // - // button8 + // btn_movepose // - this.button8.Location = new System.Drawing.Point(129, 122); - this.button8.Name = "button8"; - this.button8.Size = new System.Drawing.Size(120, 37); - this.button8.TabIndex = 7; - this.button8.Text = "移动到目标位置"; - this.button8.UseVisualStyleBackColor = true; + this.btn_movepose.Location = new System.Drawing.Point(129, 122); + this.btn_movepose.Name = "btn_movepose"; + this.btn_movepose.Size = new System.Drawing.Size(120, 37); + this.btn_movepose.TabIndex = 7; + this.btn_movepose.Text = "移动到目标位置"; + this.btn_movepose.UseVisualStyleBackColor = true; + this.btn_movepose.Click += new System.EventHandler(this.btn_movepose_Click); // // checkBox1 // @@ -1898,10 +1875,10 @@ // // groupBox7 // - this.groupBox7.Controls.Add(this.button7); - this.groupBox7.Controls.Add(this.button6); - this.groupBox7.Controls.Add(this.button5); - this.groupBox7.Controls.Add(this.button4); + this.groupBox7.Controls.Add(this.btn_Y_Back); + this.groupBox7.Controls.Add(this.btn_X_right); + this.groupBox7.Controls.Add(this.btn_X_left); + this.groupBox7.Controls.Add(this.btn_Y_Forward); this.groupBox7.Location = new System.Drawing.Point(6, 100); this.groupBox7.Name = "groupBox7"; this.groupBox7.Size = new System.Drawing.Size(283, 160); @@ -1909,47 +1886,51 @@ this.groupBox7.TabStop = false; this.groupBox7.Text = "Jog"; // - // button7 + // btn_Y_Back // - this.button7.Location = new System.Drawing.Point(104, 107); - this.button7.Name = "button7"; - this.button7.Size = new System.Drawing.Size(75, 35); - this.button7.TabIndex = 3; - this.button7.Text = "Y后退"; - this.button7.UseVisualStyleBackColor = true; + this.btn_Y_Back.Location = new System.Drawing.Point(104, 107); + this.btn_Y_Back.Name = "btn_Y_Back"; + this.btn_Y_Back.Size = new System.Drawing.Size(75, 35); + this.btn_Y_Back.TabIndex = 3; + this.btn_Y_Back.Text = "Y后退"; + this.btn_Y_Back.UseVisualStyleBackColor = true; + this.btn_Y_Back.Click += new System.EventHandler(this.btn_Y_Back_Click); // - // button6 + // btn_X_right // - this.button6.Location = new System.Drawing.Point(198, 61); - this.button6.Name = "button6"; - this.button6.Size = new System.Drawing.Size(75, 35); - this.button6.TabIndex = 2; - this.button6.Text = "X右移"; - this.button6.UseVisualStyleBackColor = true; + this.btn_X_right.Location = new System.Drawing.Point(198, 61); + this.btn_X_right.Name = "btn_X_right"; + this.btn_X_right.Size = new System.Drawing.Size(75, 35); + this.btn_X_right.TabIndex = 2; + this.btn_X_right.Text = "X右移"; + this.btn_X_right.UseVisualStyleBackColor = true; + this.btn_X_right.Click += new System.EventHandler(this.btn_X_right_Click); // - // button5 + // btn_X_left // - this.button5.Location = new System.Drawing.Point(10, 61); - this.button5.Name = "button5"; - this.button5.Size = new System.Drawing.Size(75, 35); - this.button5.TabIndex = 1; - this.button5.Text = "X左移"; - this.button5.UseVisualStyleBackColor = true; + this.btn_X_left.Location = new System.Drawing.Point(10, 61); + this.btn_X_left.Name = "btn_X_left"; + this.btn_X_left.Size = new System.Drawing.Size(75, 35); + this.btn_X_left.TabIndex = 1; + this.btn_X_left.Text = "X左移"; + this.btn_X_left.UseVisualStyleBackColor = true; + this.btn_X_left.Click += new System.EventHandler(this.btn_X_left_Click); // - // button4 + // btn_Y_Forward // - this.button4.Location = new System.Drawing.Point(104, 12); - this.button4.Name = "button4"; - this.button4.Size = new System.Drawing.Size(75, 35); - this.button4.TabIndex = 0; - this.button4.Text = "Y前进"; - this.button4.UseVisualStyleBackColor = true; + this.btn_Y_Forward.Location = new System.Drawing.Point(104, 12); + this.btn_Y_Forward.Name = "btn_Y_Forward"; + this.btn_Y_Forward.Size = new System.Drawing.Size(75, 35); + this.btn_Y_Forward.TabIndex = 0; + this.btn_Y_Forward.Text = "Y前进"; + this.btn_Y_Forward.UseVisualStyleBackColor = true; + this.btn_Y_Forward.Click += new System.EventHandler(this.btn_Y_Forward_Click); // // groupBox6 // - this.groupBox6.Controls.Add(this.button3); - this.groupBox6.Controls.Add(this.button2); - this.groupBox6.Controls.Add(this.button1); + this.groupBox6.Controls.Add(this.btn_home); + this.groupBox6.Controls.Add(this.btn_stop); + this.groupBox6.Controls.Add(this.btn_start); this.groupBox6.Location = new System.Drawing.Point(6, 24); this.groupBox6.Name = "groupBox6"; this.groupBox6.Size = new System.Drawing.Size(283, 70); @@ -1957,39 +1938,42 @@ this.groupBox6.TabStop = false; this.groupBox6.Text = "动作"; // - // button3 + // btn_home // - this.button3.Location = new System.Drawing.Point(198, 24); - this.button3.Name = "button3"; - this.button3.Size = new System.Drawing.Size(75, 30); - this.button3.TabIndex = 2; - this.button3.Text = "回原点"; - this.button3.UseVisualStyleBackColor = true; + this.btn_home.Location = new System.Drawing.Point(198, 24); + this.btn_home.Name = "btn_home"; + this.btn_home.Size = new System.Drawing.Size(75, 30); + this.btn_home.TabIndex = 2; + this.btn_home.Text = "回原点"; + this.btn_home.UseVisualStyleBackColor = true; + this.btn_home.Click += new System.EventHandler(this.btn_home_Click); // - // button2 + // btn_stop // - this.button2.Location = new System.Drawing.Point(104, 24); - this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(75, 30); - this.button2.TabIndex = 1; - this.button2.Text = "停止"; - this.button2.UseVisualStyleBackColor = true; + this.btn_stop.Location = new System.Drawing.Point(104, 24); + this.btn_stop.Name = "btn_stop"; + this.btn_stop.Size = new System.Drawing.Size(75, 30); + this.btn_stop.TabIndex = 1; + this.btn_stop.Text = "停止"; + this.btn_stop.UseVisualStyleBackColor = true; + this.btn_stop.Click += new System.EventHandler(this.btn_stop_Click); // - // button1 + // btn_start // - this.button1.Location = new System.Drawing.Point(10, 24); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(75, 30); - this.button1.TabIndex = 0; - this.button1.Text = "开始"; - this.button1.UseVisualStyleBackColor = true; + this.btn_start.Location = new System.Drawing.Point(10, 24); + this.btn_start.Name = "btn_start"; + this.btn_start.Size = new System.Drawing.Size(75, 30); + this.btn_start.TabIndex = 0; + this.btn_start.Text = "开始"; + this.btn_start.UseVisualStyleBackColor = true; + this.btn_start.Click += new System.EventHandler(this.btn_start_Click); // // groupBox10 // this.groupBox10.Controls.Add(this.label48); this.groupBox10.Controls.Add(this.textBox4); - this.groupBox10.Controls.Add(this.button10); - this.groupBox10.Controls.Add(this.button9); + this.groupBox10.Controls.Add(this.btn_halt); + this.groupBox10.Controls.Add(this.btn_run); this.groupBox10.Controls.Add(this.checkBox4); this.groupBox10.Controls.Add(this.checkBox3); this.groupBox10.Controls.Add(this.checkBox2); @@ -2016,23 +2000,25 @@ this.textBox4.Size = new System.Drawing.Size(35, 21); this.textBox4.TabIndex = 5; // - // button10 + // btn_halt // - this.button10.Location = new System.Drawing.Point(94, 60); - this.button10.Name = "button10"; - this.button10.Size = new System.Drawing.Size(60, 23); - this.button10.TabIndex = 4; - this.button10.Text = "停止"; - this.button10.UseVisualStyleBackColor = true; + this.btn_halt.Location = new System.Drawing.Point(94, 60); + this.btn_halt.Name = "btn_halt"; + this.btn_halt.Size = new System.Drawing.Size(60, 23); + this.btn_halt.TabIndex = 4; + this.btn_halt.Text = "停止"; + this.btn_halt.UseVisualStyleBackColor = true; + this.btn_halt.Click += new System.EventHandler(this.btn_halt_Click); // - // button9 + // btn_run // - this.button9.Location = new System.Drawing.Point(13, 60); - this.button9.Name = "button9"; - this.button9.Size = new System.Drawing.Size(60, 23); - this.button9.TabIndex = 3; - this.button9.Text = "运行"; - this.button9.UseVisualStyleBackColor = true; + this.btn_run.Location = new System.Drawing.Point(13, 60); + this.btn_run.Name = "btn_run"; + this.btn_run.Size = new System.Drawing.Size(60, 23); + this.btn_run.TabIndex = 3; + this.btn_run.Text = "运行"; + this.btn_run.UseVisualStyleBackColor = true; + this.btn_run.Click += new System.EventHandler(this.btn_run_Click); // // checkBox4 // @@ -2154,8 +2140,6 @@ private System.Windows.Forms.Button btnOpen; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label1; - private System.Windows.Forms.RadioButton rdoTCP; - private System.Windows.Forms.RadioButton rdoSimu; private System.Windows.Forms.Button btnHalt; private System.Windows.Forms.GroupBox grpMst; private System.Windows.Forms.Label label16; @@ -2266,7 +2250,7 @@ private System.Windows.Forms.GroupBox groupBox5; private System.Windows.Forms.GroupBox groupBox9; private System.Windows.Forms.GroupBox groupBox8; - private System.Windows.Forms.Button button8; + private System.Windows.Forms.Button btn_movepose; private System.Windows.Forms.CheckBox checkBox1; private System.Windows.Forms.TextBox textBox3; private System.Windows.Forms.TextBox textBox2; @@ -2275,19 +2259,19 @@ private System.Windows.Forms.Label label45; private System.Windows.Forms.Label label44; private System.Windows.Forms.GroupBox groupBox7; - private System.Windows.Forms.Button button7; - private System.Windows.Forms.Button button6; - private System.Windows.Forms.Button button5; - private System.Windows.Forms.Button button4; + private System.Windows.Forms.Button btn_Y_Back; + private System.Windows.Forms.Button btn_X_right; + private System.Windows.Forms.Button btn_X_left; + private System.Windows.Forms.Button btn_Y_Forward; private System.Windows.Forms.GroupBox groupBox6; - private System.Windows.Forms.Button button3; - private System.Windows.Forms.Button button2; - private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button btn_home; + private System.Windows.Forms.Button btn_stop; + private System.Windows.Forms.Button btn_start; private System.Windows.Forms.GroupBox groupBox10; private System.Windows.Forms.Label label48; private System.Windows.Forms.TextBox textBox4; - private System.Windows.Forms.Button button10; - private System.Windows.Forms.Button button9; + private System.Windows.Forms.Button btn_halt; + private System.Windows.Forms.Button btn_run; private System.Windows.Forms.CheckBox checkBox4; private System.Windows.Forms.CheckBox checkBox3; private System.Windows.Forms.CheckBox checkBox2; diff --git a/HexcalMC/Motion/Motion.cs b/HexcalMC/Motion/Motion.cs index 814fb71..4452fdf 100644 --- a/HexcalMC/Motion/Motion.cs +++ b/HexcalMC/Motion/Motion.cs @@ -3,7 +3,9 @@ using System.Diagnostics; using System.Runtime.InteropServices; using System.Windows.Forms; using ACS.SPiiPlusNET; +using HexcalMC.Base; using HexcalMC.Properties; + // ACS .NET Library namespace HexcalMC @@ -38,11 +40,11 @@ namespace HexcalMC private int _mNValues, _mNOutputState; private object _mObjReadVar; - public Motion() + public Motion(Api api) { InitializeComponent(); - _acs = new Api(); //初始化 ACS运动控制类 + _acs = api; //初始化 ACS运动控制类 // Register Event 注册时间 _acs.PHYSICALMOTIONEND += ACS_PHYSICALMOTIONEND; @@ -129,7 +131,6 @@ namespace HexcalMC private void Form1_Load(object sender, EventArgs e) { - rdoTCP.Checked = true; btnOpen.Enabled = true; btnClose.Enabled = false; @@ -237,18 +238,17 @@ namespace HexcalMC try { - if (rdoTCP.Checked) + if (_acs.IsConnected) + { + DebugDfn.AddLogText("运动平台已连接"); + } + else { // TCP/IP (Ethernet) _acs.OpenCommEthernetTCP( txtIP.Text, // IP Address (Default : 10.0.0.100) Convert.ToInt32(txtPort.Text.Trim())); // TCP/IP Port nubmer (default : 701) } - else if (rdoSimu.Checked) - { - // Simmulation mode - _acs.OpenCommSimulator(); - } _mBConnected = true; @@ -263,11 +263,11 @@ namespace HexcalMC // When we are using multi axes command (ex) ToPointM, HaltM, ...), we need to allocate the array size more 1. // Because of the last delimeter (-1) _mArrAxisList = new Axis[_mNTotalAxis + 1]; - for (i = 0; i < _mNTotalAxis; i++) - { - cboAxisNo.Items.Add(i.ToString()); - _mArrAxisList[i] = (Axis)i; - } + //for (i = 0; i < _mNTotalAxis; i++) + //{ + // cboAxisNo.Items.Add(i.ToString()); + // _mArrAxisList[i] = (Axis)i; + //} // Insert '-1' at the last _mArrAxisList[_mNTotalAxis] = Axis.ACSC_NONE; @@ -664,7 +664,7 @@ namespace HexcalMC } } - // 정방향 이동 동작 + private void BtnJogPos_MouseDown(object sender, MouseEventArgs e) { double lfVelocity = 0.0f; @@ -852,7 +852,7 @@ namespace HexcalMC private void BtnEventMotionEnd_Click(object sender, EventArgs e) { - _acs.PHYSICALMOTIONEND +=ACS_PHYSICALMOTIONEND; + _acs.PHYSICALMOTIONEND += ACS_PHYSICALMOTIONEND; _acs.EnableEvent(Interrupts.ACSC_INTR_PHYSICAL_MOTION_END); lstLog.Items.Add("PHYSICAL_MOTION_END event enabled"); } @@ -889,6 +889,47 @@ namespace HexcalMC lstLog.Items.Add("PROGRAM_END event enabled"); } + + private void btn_movepose_Click(object sender, EventArgs e) + { + } + + private void btn_start_Click(object sender, EventArgs e) + { + } + + private void btn_stop_Click(object sender, EventArgs e) + { + } + + private void btn_home_Click(object sender, EventArgs e) + { + } + + private void btn_X_left_Click(object sender, EventArgs e) + { + } + + private void btn_X_right_Click(object sender, EventArgs e) + { + } + + private void btn_Y_Forward_Click(object sender, EventArgs e) + { + } + + private void btn_Y_Back_Click(object sender, EventArgs e) + { + } + + private void btn_run_Click(object sender, EventArgs e) + { + } + + private void btn_halt_Click(object sender, EventArgs e) + { + } + private void ACS_PROGRAMEND(BufferMasks buffer) { int bit = 0x01; diff --git a/HexcalMC/Motion/Motion.resx b/HexcalMC/Motion/Motion.resx index 460b4af..7f7481b 100644 --- a/HexcalMC/Motion/Motion.resx +++ b/HexcalMC/Motion/Motion.resx @@ -1148,7 +1148,7 @@ - 176 + 77 diff --git a/HexcalMC/Program.cs b/HexcalMC/Program.cs index 63bfdb3..1efdc84 100644 --- a/HexcalMC/Program.cs +++ b/HexcalMC/Program.cs @@ -9,18 +9,21 @@ using static Telerik.WinControls.UI.Export.ExportSettings; // // //开发说明 -// V0.1 2023/04/10 +// V0.1 2024/03/1 //--------------------------------------- //1、初版构建 //2、调用流程: 开启TCP服务端、连接到平台轴启用—》hexcal软件连接,开启校准通讯流程—》移动至到位后反馈—》hexcal逻辑处理—》hexcal校准完成关系—》软件关闭 // +// V0.2 2024/03/7 +//--------------------------------------- +//1、取消上电自动连接 +//2、优化运动窗体间传递 运动平台对象 +//3、增加平台位置动态显示 +//4、修复运动到位判断逻辑 +//5、增加演示模式按钮 // // -// -// -// -// -// +//6、点击停止报错,运动测试界面问题? // // // diff --git a/HexcalMC/Properties/AssemblyInfo.cs b/HexcalMC/Properties/AssemblyInfo.cs index 071efda..a09cf31 100644 --- a/HexcalMC/Properties/AssemblyInfo.cs +++ b/HexcalMC/Properties/AssemblyInfo.cs @@ -8,7 +8,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Hexagon HMI")] [assembly: AssemblyProduct("直线电机平台补偿软件(HexcalMC)")] -[assembly: AssemblyCopyright("Copyright © 2023 Hexagon,Inc")] +[assembly: AssemblyCopyright("Copyright © 2024 Hexagon,Inc")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -19,5 +19,5 @@ using System.Runtime.InteropServices; [assembly: Guid("6215eb36-92d3-4f96-9331-1e8cbda161f4")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("0.0.2")] +[assembly: AssemblyFileVersion("0.0.2")] diff --git a/HexcalMC/Properties/Resources.Designer.cs b/HexcalMC/Properties/Resources.Designer.cs index fc8b746..b6749f8 100644 --- a/HexcalMC/Properties/Resources.Designer.cs +++ b/HexcalMC/Properties/Resources.Designer.cs @@ -70,6 +70,26 @@ namespace HexcalMC.Properties { } } + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap demo_show { + get { + object obj = ResourceManager.GetObject("demo_show", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap demo_show_128 { + get { + object obj = ResourceManager.GetObject("demo_show_128", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// @@ -110,6 +130,16 @@ namespace HexcalMC.Properties { } } + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap mothion_64 { + get { + object obj = ResourceManager.GetObject("mothion_64", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// diff --git a/HexcalMC/Properties/Resources.resx b/HexcalMC/Properties/Resources.resx index b3ff302..8e82715 100644 --- a/HexcalMC/Properties/Resources.resx +++ b/HexcalMC/Properties/Resources.resx @@ -112,35 +112,43 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\Images\HexagonNew.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\about.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Images\On.bmp;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 - ..\Images\Error.bmp;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\Hexagon.ico;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\demo_show_128.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Images\Off.bmp;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\motion.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\about.png;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\Hexagon.ico;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\demo_show.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\mothion_64.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a \ No newline at end of file