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

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
+1
View File
@@ -282,6 +282,7 @@
<None Include="Resources\mothion_64.png" />
<None Include="Resources\quick_location.png" />
<None Include="Resources\quick_location_64.png" />
<None Include="Resources\stop.png" />
<Content Include="SharpGL.ico" />
<Content Include="SharpGL.png" />
</ItemGroup>
+20 -1
View File
@@ -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;
}
}
+32 -8
View File
@@ -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<Point3D> 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();
}
+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); //等待回家完成
}
+10
View File
@@ -189,5 +189,15 @@ namespace HexcalMC.Properties {
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap stop {
get {
object obj = ResourceManager.GetObject("stop", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}
+6 -3
View File
@@ -136,9 +136,6 @@
<data name="Hexagon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Hexagon.ico;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="help" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\help.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="quick_location" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\quick_location.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
@@ -157,4 +154,10 @@
<data name="demo_show" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\demo_show.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="help" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\help.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="stop" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\stop.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>