diff --git a/HexcalMC/Base/BaseFunction.cs b/HexcalMC/Base/BaseFunction.cs index 3677fac..d2b61b5 100644 --- a/HexcalMC/Base/BaseFunction.cs +++ b/HexcalMC/Base/BaseFunction.cs @@ -19,28 +19,28 @@ namespace HexcalMC.Base //通用功能类 public class RichTextUnit { - public static float m_Size = 16; - public static void SetFont(RichTextBox m_RichTextBox, Color m_Color, bool bBold = false, float Size = 16) + public static float MSize = 16; + public static void SetFont(RichTextBox mRichTextBox, Color mColor, bool bBold = false, float size = 16) { - m_RichTextBox.SelectionColor = m_Color; + mRichTextBox.SelectionColor = mColor; if (bBold) - m_RichTextBox.SelectionFont = new System.Drawing.Font("微软雅黑", Size, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel, ((byte)(134))); + mRichTextBox.SelectionFont = new System.Drawing.Font("微软雅黑", size, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel, ((byte)(134))); else - m_RichTextBox.SelectionFont = new System.Drawing.Font("微软雅黑", Size, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134))); + mRichTextBox.SelectionFont = new System.Drawing.Font("微软雅黑", size, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134))); } - public static void SetText(RichTextBox m_RichTextBox, string strText, Color m_Color, bool bBold = false, float Size = 16) + public static void SetText(RichTextBox mRichTextBox, string strText, Color mColor, bool bBold = false, float size = 16) { - m_RichTextBox.Invoke(((EventHandler)delegate + mRichTextBox.Invoke(((EventHandler)delegate { - RichTextUnit.SetFont(m_RichTextBox, m_Color, bBold, Size); - m_RichTextBox.SelectedText = strText; + RichTextUnit.SetFont(mRichTextBox, mColor, bBold, size); + mRichTextBox.SelectedText = strText; })); } - public static void SetXmlText(RichTextBox m_RichTextBox, string strText, float Size = 16) + public static void SetXmlText(RichTextBox mRichTextBox, string strText, float size = 16) { - m_RichTextBox.Invoke(((EventHandler)delegate + mRichTextBox.Invoke(((EventHandler)delegate { int iFirstInx = strText.IndexOf(""); @@ -50,8 +50,8 @@ namespace HexcalMC.Base { if (i >= iFirstInx && i <= iSecondInx + 1) { - RichTextUnit.SetFont(m_RichTextBox, Color.Blue, false, Size); - m_RichTextBox.SelectedText = strText[i].ToString(); + RichTextUnit.SetFont(mRichTextBox, Color.Blue, false, size); + mRichTextBox.SelectedText = strText[i].ToString(); } else { @@ -59,79 +59,79 @@ namespace HexcalMC.Base { case '<': { - RichTextUnit.SetFont(m_RichTextBox, Color.Blue, false, Size); - m_RichTextBox.SelectedText = strText[i].ToString(); + RichTextUnit.SetFont(mRichTextBox, Color.Blue, false, size); + mRichTextBox.SelectedText = strText[i].ToString(); if (strText[i + 1] == '/') { - m_RichTextBox.SelectedText = strText[i + 1].ToString(); + mRichTextBox.SelectedText = strText[i + 1].ToString(); i++; } - RichTextUnit.SetFont(m_RichTextBox, Color.DarkRed, false, Size); + RichTextUnit.SetFont(mRichTextBox, Color.DarkRed, false, size); } break; case '>': { - RichTextUnit.SetFont(m_RichTextBox, Color.Blue, false, Size); - m_RichTextBox.SelectedText = strText[i].ToString(); - RichTextUnit.SetFont(m_RichTextBox, Color.Black, false, Size); + RichTextUnit.SetFont(mRichTextBox, Color.Blue, false, size); + mRichTextBox.SelectedText = strText[i].ToString(); + RichTextUnit.SetFont(mRichTextBox, Color.Black, false, size); } break; case '/': { - RichTextUnit.SetFont(m_RichTextBox, Color.Blue, false, Size); - m_RichTextBox.SelectedText = strText[i].ToString(); + RichTextUnit.SetFont(mRichTextBox, Color.Blue, false, size); + mRichTextBox.SelectedText = strText[i].ToString(); } break; case '=': { if (strText[i + 1] == '"') { - RichTextUnit.SetFont(m_RichTextBox, Color.Black, true, Size); - m_RichTextBox.SelectedText = "=" + '"'.ToString(); + RichTextUnit.SetFont(mRichTextBox, Color.Black, true, size); + mRichTextBox.SelectedText = "=" + '"'.ToString(); i++; } } break; case '"': { - RichTextUnit.SetFont(m_RichTextBox, Color.Blue, false, Size); - m_RichTextBox.SelectedText = strText[i].ToString(); + RichTextUnit.SetFont(mRichTextBox, Color.Blue, false, size); + mRichTextBox.SelectedText = strText[i].ToString(); if (strText[i - 1] == '=') - RichTextUnit.SetFont(m_RichTextBox, Color.Black, true, Size); + RichTextUnit.SetFont(mRichTextBox, Color.Black, true, size); else - RichTextUnit.SetFont(m_RichTextBox, Color.DarkRed, false, Size); + RichTextUnit.SetFont(mRichTextBox, Color.DarkRed, false, size); } break; case '!': { - RichTextUnit.SetFont(m_RichTextBox, Color.Green, false, Size); - m_RichTextBox.SelectedText = strText[i].ToString(); + RichTextUnit.SetFont(mRichTextBox, Color.Green, false, size); + mRichTextBox.SelectedText = strText[i].ToString(); } break; case '\r': { if (strText[i + 1] == '\n') { - m_RichTextBox.SelectedText = "\r\n"; + mRichTextBox.SelectedText = "\r\n"; i++; } } break; default: - m_RichTextBox.SelectedText = strText[i].ToString(); + mRichTextBox.SelectedText = strText[i].ToString(); break; } } } #endregion - m_RichTextBox.SelectedText = Environment.NewLine; + mRichTextBox.SelectedText = Environment.NewLine; })); } - public static void SetCNCText(RichTextBox m_RichTextBox, string strText, float Size = 16) + public static void SetCncText(RichTextBox mRichTextBox, string strText, float size = 16) { - m_RichTextBox.Invoke(((EventHandler)delegate + mRichTextBox.Invoke(((EventHandler)delegate { #region PARSE THROUGH TEXT DATA for (int i = 0; i < strText.Length; i++) @@ -139,8 +139,8 @@ namespace HexcalMC.Base switch (strText[i]) { case '%': - RichTextUnit.SetFont(m_RichTextBox, Color.Red, false, Size); - m_RichTextBox.SelectedText = strText[i].ToString(); + RichTextUnit.SetFont(mRichTextBox, Color.Red, false, size); + mRichTextBox.SelectedText = strText[i].ToString(); break; case '0': case '1': @@ -152,12 +152,12 @@ namespace HexcalMC.Base case '7': case '8': case '9': - RichTextUnit.SetFont(m_RichTextBox, Color.DeepSkyBlue, false, Size); - m_RichTextBox.SelectedText = strText[i].ToString(); + RichTextUnit.SetFont(mRichTextBox, Color.DeepSkyBlue, false, size); + mRichTextBox.SelectedText = strText[i].ToString(); break; default: - RichTextUnit.SetFont(m_RichTextBox, Color.White, false, Size); - m_RichTextBox.SelectedText = strText[i].ToString(); + RichTextUnit.SetFont(mRichTextBox, Color.White, false, size); + mRichTextBox.SelectedText = strText[i].ToString(); break; } } @@ -187,12 +187,12 @@ namespace HexcalMC.Base public static void ClearMemory_PCDMIS() { - Process[] m_Process = Process.GetProcessesByName("PCDLRN"); - for (int i = 0; i < m_Process.Length; i++) + Process[] mProcess = Process.GetProcessesByName("PCDLRN"); + for (int i = 0; i < mProcess.Length; i++) { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { - SetProcessWorkingSetSize(m_Process[i].Handle, -1, -1); + SetProcessWorkingSetSize(mProcess[i].Handle, -1, -1); } } } @@ -228,21 +228,21 @@ namespace HexcalMC.Base /// 控件 public static object GetControlInstance(object obj, string strControlName, System.Windows.Forms.Form mainForm) { - IEnumerator Controls = null; //所有控件 + IEnumerator controls = null; //所有控件 Control c = null; //当前控件 Object cResult = null; //查找结果 if (obj.GetType() == mainForm.GetType()) //窗体 { - Controls = mainForm.Controls.GetEnumerator(); + controls = mainForm.Controls.GetEnumerator(); } else //控件 { - Controls = ((Control)obj).Controls.GetEnumerator(); + controls = ((Control)obj).Controls.GetEnumerator(); } - while (Controls.MoveNext()) //遍历操作 + while (controls.MoveNext()) //遍历操作 { - c = (Control)Controls.Current; //当前控件 + c = (Control)controls.Current; //当前控件 if (c.HasChildren) //当前控件是个容器 { cResult = GetControlInstance(c, strControlName, mainForm); //递归查找 @@ -262,15 +262,15 @@ namespace HexcalMC.Base public static object GetChildControl(object obj, string strControlName) { - Control m_Ctrl = null; //当前控件 - IEnumerator Controls = ((Control)obj).Controls.GetEnumerator(); + Control mCtrl = null; //当前控件 + IEnumerator controls = ((Control)obj).Controls.GetEnumerator(); - while (Controls.MoveNext()) + while (controls.MoveNext()) { - m_Ctrl = (Control)Controls.Current; //当前控件 - if (m_Ctrl.Name == strControlName) + mCtrl = (Control)controls.Current; //当前控件 + if (mCtrl.Name == strControlName) { - return m_Ctrl; + return mCtrl; } } @@ -301,49 +301,49 @@ namespace HexcalMC.Base /// /// 向RichTextBox控件中添加文本信息 /// - /// RichTextBox控件类 + /// RichTextBox控件类 /// 要显示的文本信息内容 - /// 文本显示的颜色 - public static void AddDebugTextToRTB(RichTextBox RTB, string str, Color m_Color = new Color()) + /// 文本显示的颜色 + public static void AddDebugTextToRtb(RichTextBox rtb, string str, Color mColor = new Color()) { try { TraceWriteLine(str); //将文本信息同步到debug.txt文件中 - RTB.BeginInvoke((EventHandler)delegate + rtb.BeginInvoke((EventHandler)delegate { - Color SetColor = Color.Black; - if (m_Color == new Color()) + Color setColor = Color.Black; + if (mColor == new Color()) { if (str.ToUpper().Contains("ERROR") || str.ToUpper().Contains("错误") || str.ToUpper().Contains("出错") || str.ToUpper().Contains("EXCEPTION") || str.ToUpper().Contains("异常") || str.ToUpper().Contains("失败")) { - SetColor = Color.Red; + setColor = Color.Red; } else if (str.ToUpper().Contains("WARNING") || str.ToUpper().Contains("警告")) { - SetColor = Color.DarkOrange; + setColor = Color.DarkOrange; } } else { - SetColor = m_Color; + setColor = mColor; } string strText = str + Environment.NewLine; //DateTime.Now.ToString("HH:mm:ss.fff") + "--" + - RTB.SelectionStart = RTB.TextLength; + rtb.SelectionStart = rtb.TextLength; if (string.IsNullOrEmpty(str)) - RichTextUnit.SetText(RTB, " " + Environment.NewLine, SetColor, false, 14); + RichTextUnit.SetText(rtb, " " + Environment.NewLine, setColor, false, 14); else - RichTextUnit.SetText(RTB, strText, SetColor, false, 14); + RichTextUnit.SetText(rtb, strText, setColor, false, 14); - if (RTB.Lines.Length > 2000) + if (rtb.Lines.Length > 2000) { - RTB.Select(0, RTB.TextLength / 2); - RTB.Cut(); + rtb.Select(0, rtb.TextLength / 2); + rtb.Cut(); } - RTB.ScrollToCaret(); + rtb.ScrollToCaret(); }); } catch @@ -369,56 +369,56 @@ namespace HexcalMC.Base } - public static string InputBox(string Caption, string Hint, string DefaultTxt, string btn1 = "OK", - string btn2 = "Cancel", char Strstyle = '*', bool bShowData = false) + public static string InputBox(string caption, string hint, string defaultTxt, string btn1 = "OK", + string btn2 = "Cancel", char strstyle = '*', bool bShowData = false) { - if (Strstyle == '\0') - Strstyle = '*'; - System.Windows.Forms.Form InputForm = new System.Windows.Forms.Form(); - InputForm.MinimizeBox = false; - InputForm.MaximizeBox = false; - InputForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; - InputForm.StartPosition = FormStartPosition.CenterScreen; - InputForm.Width = 230; - InputForm.Height = 170; - InputForm.Text = Caption; - InputForm.Font = new System.Drawing.Font("宋体", 16F, System.Drawing.FontStyle.Regular, + if (strstyle == '\0') + strstyle = '*'; + System.Windows.Forms.Form inputForm = new System.Windows.Forms.Form(); + inputForm.MinimizeBox = false; + inputForm.MaximizeBox = false; + inputForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + inputForm.StartPosition = FormStartPosition.CenterScreen; + inputForm.Width = 230; + inputForm.Height = 170; + inputForm.Text = caption; + inputForm.Font = new System.Drawing.Font("宋体", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134))); Label lbl = new Label(); - lbl.Text = Hint; + lbl.Text = hint; lbl.Left = 10; lbl.Top = 20; - lbl.Parent = InputForm; + lbl.Parent = inputForm; lbl.AutoSize = true; TextBox tb = new TextBox(); tb.Left = 30; tb.Top = 45; tb.Width = 165; - tb.Parent = InputForm; - tb.Text = DefaultTxt; + tb.Parent = inputForm; + tb.Text = defaultTxt; if (bShowData == false) - tb.PasswordChar = Strstyle; + tb.PasswordChar = strstyle; tb.SelectAll(); Button btnok = new Button(); btnok.Left = 30; btnok.Top = 80; btnok.Height = 30; - btnok.Parent = InputForm; + btnok.Parent = inputForm; btnok.Text = btn1; - InputForm.AcceptButton = btnok; //回车响应 + inputForm.AcceptButton = btnok; //回车响应 btnok.DialogResult = DialogResult.OK; Button btncancal = new Button(); btncancal.Left = 120; btncancal.Top = 80; btncancal.Height = 30; - btncancal.Parent = InputForm; + btncancal.Parent = inputForm; btncancal.Text = btn2; btncancal.DialogResult = DialogResult.Cancel; try { - if (InputForm.ShowDialog() == DialogResult.OK) + if (inputForm.ShowDialog() == DialogResult.OK) { return tb.Text; } @@ -429,7 +429,7 @@ namespace HexcalMC.Base } finally { - InputForm.Dispose(); + inputForm.Dispose(); } } @@ -437,28 +437,28 @@ namespace HexcalMC.Base /// 操作提示框,0 = 取消; 1 = 第一个按钮; 2 = 第二个按钮 /// /// 错误信息 - /// 标题 + /// 标题 /// 第一个按钮名字 /// 第二个按钮名字 /// 第三个按钮名字 /// 背景颜色,默认无色,1=红色 /// - public static int MessageBox(string strError, string Caption, string btnName1 = "YES", string btnName2 = "NO", + public static int MessageBox(string strError, string caption, string btnName1 = "YES", string btnName2 = "NO", string btnName3 = "Cancel", int iColor = 0) { - System.Windows.Forms.Form ErrorForm = new System.Windows.Forms.Form(); - ErrorForm.MinimizeBox = false; - ErrorForm.MaximizeBox = false; - ErrorForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; - ErrorForm.StartPosition = FormStartPosition.CenterScreen; - ErrorForm.Width = 480; - ErrorForm.Height = 300; - ErrorForm.Text = Caption; - ErrorForm.Font = new System.Drawing.Font("宋体", 16F, System.Drawing.FontStyle.Regular, + System.Windows.Forms.Form errorForm = new System.Windows.Forms.Form(); + errorForm.MinimizeBox = false; + errorForm.MaximizeBox = false; + errorForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + errorForm.StartPosition = FormStartPosition.CenterScreen; + errorForm.Width = 480; + errorForm.Height = 300; + errorForm.Text = caption; + errorForm.Font = new System.Drawing.Font("宋体", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134))); TextBox tb = new TextBox(); - tb.Parent = ErrorForm; + tb.Parent = errorForm; tb.Text = strError; tb.Multiline = true; tb.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; @@ -472,31 +472,31 @@ namespace HexcalMC.Base Button btnYes = new Button(); btnYes.Location = new System.Drawing.Point(30, 210); btnYes.Size = new System.Drawing.Size(100, 40); - btnYes.Parent = ErrorForm; + btnYes.Parent = errorForm; btnYes.Text = btnName1; btnYes.DialogResult = DialogResult.Yes; - ErrorForm.AcceptButton = btnYes; //回车响应 + errorForm.AcceptButton = btnYes; //回车响应 - Button btnNO = new Button(); - btnNO.Location = new System.Drawing.Point(190, 210); - btnNO.Size = new System.Drawing.Size(100, 40); - btnNO.Parent = ErrorForm; - btnNO.Text = btnName2; - btnNO.DialogResult = DialogResult.No; - ErrorForm.AcceptButton = btnNO; //回车响应 + Button btnNo = new Button(); + btnNo.Location = new System.Drawing.Point(190, 210); + btnNo.Size = new System.Drawing.Size(100, 40); + btnNo.Parent = errorForm; + btnNo.Text = btnName2; + btnNo.DialogResult = DialogResult.No; + errorForm.AcceptButton = btnNo; //回车响应 Button btncancal = new Button(); btncancal.Location = new System.Drawing.Point(350, 210); btncancal.Size = new System.Drawing.Size(100, 40); - btncancal.Parent = ErrorForm; + btncancal.Parent = errorForm; btncancal.Text = btnName3; btncancal.DialogResult = DialogResult.Cancel; - ErrorForm.AcceptButton = btncancal; //回车响应 + errorForm.AcceptButton = btncancal; //回车响应 try { btnYes.Select(); - switch (ErrorForm.ShowDialog()) + switch (errorForm.ShowDialog()) { case DialogResult.Yes: return 1; case DialogResult.No: return 2; @@ -505,19 +505,19 @@ namespace HexcalMC.Base } finally { - ErrorForm.Dispose(); + errorForm.Dispose(); } } [DllImport("User32.dll")] private static extern bool SetCursorPos(int x, int y); - static public void SetCursorPosXY(int dx, int dy) + static public void SetCursorPosXy(int dx, int dy) { SetCursorPos(dx, dy); } - static public void SetCursorPosXY(Point point) + static public void SetCursorPosXy(Point point) { System.Windows.Forms.Cursor.Position = point; } @@ -563,14 +563,14 @@ namespace HexcalMC.Base public class HardwareInfoBase { /// 获取指定驱动器的空间总大小(单位为B) ,只需输入代表驱动器的字母即可 - public static long GetHardDiskSpace(string str_HardDiskName) + public static long GetHardDiskSpace(string strHardDiskName) { long totalSize = new long(); - str_HardDiskName = str_HardDiskName + ":\\"; + strHardDiskName = strHardDiskName + ":\\"; System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives(); foreach (System.IO.DriveInfo drive in drives) { - if (drive.Name == str_HardDiskName) + if (drive.Name == strHardDiskName) { totalSize = drive.TotalSize; break; @@ -581,14 +581,14 @@ namespace HexcalMC.Base } /// 获取指定驱动器的剩余空间总大小(单位为B) ,只需输入代表驱动器的字母即可 - public static long GetHardDiskFreeSpace(string str_HardDiskName) + public static long GetHardDiskFreeSpace(string strHardDiskName) { long freeSpace = new long(); - str_HardDiskName = str_HardDiskName + ":\\"; + strHardDiskName = strHardDiskName + ":\\"; System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives(); foreach (System.IO.DriveInfo drive in drives) { - if (drive.Name == str_HardDiskName) + if (drive.Name == strHardDiskName) { freeSpace = drive.TotalFreeSpace; break; @@ -599,21 +599,21 @@ namespace HexcalMC.Base } /// 获取指定驱动器的剩余空间总大小(单位为K) ,只需输入代表驱动器的字母即可 - public static long GetHardDiskFreeSpace_K(string str_HardDiskName) + public static long GetHardDiskFreeSpace_K(string strHardDiskName) { - return GetHardDiskFreeSpace(str_HardDiskName) / 1024; + return GetHardDiskFreeSpace(strHardDiskName) / 1024; } /// 获取指定驱动器的剩余空间总大小(单位为M) ,只需输入代表驱动器的字母即可 - public static long GetHardDiskFreeSpace_M(string str_HardDiskName) + public static long GetHardDiskFreeSpace_M(string strHardDiskName) { - return GetHardDiskFreeSpace_K(str_HardDiskName) / 1024; + return GetHardDiskFreeSpace_K(strHardDiskName) / 1024; } /// 获取指定驱动器的剩余空间总大小(单位为G) ,只需输入代表驱动器的字母即可 - public static long GetHardDiskFreeSpace_G(string str_HardDiskName) + public static long GetHardDiskFreeSpace_G(string strHardDiskName) { - return GetHardDiskFreeSpace_M(str_HardDiskName) / 1024; + return GetHardDiskFreeSpace_M(strHardDiskName) / 1024; } } @@ -627,17 +627,17 @@ namespace HexcalMC.Base [DllImport("kernel32.dll")] public static extern bool CloseHandle(IntPtr hObject); - public const int OF_READWRITE = 2; - public const int OF_SHARE_DENY_NONE = 0x40; - public static readonly IntPtr HFILE_ERROR = new IntPtr(-1); + public const int OfReadwrite = 2; + public const int OfShareDenyNone = 0x40; + public static readonly IntPtr HfileError = new IntPtr(-1); //判断文件是否被占用 占用=true 未占用 = false - public static bool isFileOccupied(string path) + public static bool IsFileOccupied(string path) { if (!File.Exists(path)) return true; - IntPtr vHandle = _lopen(path, OF_READWRITE | OF_SHARE_DENY_NONE); - if (vHandle == HFILE_ERROR) + IntPtr vHandle = _lopen(path, OfReadwrite | OfShareDenyNone); + if (vHandle == HfileError) return true; CloseHandle(vHandle); return false; @@ -654,7 +654,7 @@ namespace HexcalMC.Base [DllImport("kernel32")] private static extern int GetPrivateProfileInt(string section, string key, int def, string filePath); - public static bool isFileExists(string path) + public static bool IsFileExists(string path) { if (!(File.Exists(path))) { @@ -791,17 +791,17 @@ namespace HexcalMC.Base GetPrivateProfileString(section, key, defValue.ToString(), temp, 255, path); String str = temp.ToString(); string[] strArr = str.Split(new char[] { ';' }); - double ReData; + double reData; if (strArr.Length > 0) { - ReData = Convert.ToDouble(strArr[0]); + reData = Convert.ToDouble(strArr[0]); } else { - ReData = defValue; + reData = defValue; } - return ReData; + return reData; } public static bool ReadBool(string path, string section, string key, int defValue = 0) @@ -876,21 +876,21 @@ namespace HexcalMC.Base //} //方法 2 - public static void sndPlayerPlay(string FileName) + public static void SndPlayerPlay(string fileName) { - if (!System.IO.File.Exists(FileName)) + if (!System.IO.File.Exists(fileName)) { MessageBox.Show("File does not exist!"); return; } - System.Media.SoundPlayer sndPlayer = new System.Media.SoundPlayer(FileName); + System.Media.SoundPlayer sndPlayer = new System.Media.SoundPlayer(fileName); sndPlayer.Load(); sndPlayer.Play(); } //方法 3 - public static void SpVoicePlay(string FileName) + public static void SpVoicePlay(string fileName) { //if (!System.IO.File.Exists(FileName)) //{ @@ -926,11 +926,11 @@ namespace HexcalMC.Base /// 输入字符串 /// 长度 /// 输出字符串 - /// 检测结果 - public static void FormatChecking16(string strInput, int length, out string strOutput, out Boolean Valid) + /// 检测结果 + public static void FormatChecking16(string strInput, int length, out string strOutput, out Boolean valid) { strOutput = ""; - Valid = true; + valid = true; byte temp; if ((strInput.Length <= length) & (strInput.Length > 0)) { @@ -942,7 +942,7 @@ namespace HexcalMC.Base } catch { - Valid = false; + valid = false; strOutput = ""; break; } @@ -950,7 +950,7 @@ namespace HexcalMC.Base strOutput += strInput[i]; } - if (Valid & (strInput.Length < length)) + if (valid & (strInput.Length < length)) { for (int j = 0; j < length - strInput.Length; j++) { @@ -960,7 +960,7 @@ namespace HexcalMC.Base } else { - Valid = false; + valid = false; strOutput = ""; } } @@ -1025,9 +1025,9 @@ namespace HexcalMC.Base /// 源字符串 /// 间隔字符数 /// 待插入值 - /// 待补充值,最后不足间隔字符数时,用此字符补齐;Supplement=""时,不补任何字符。 + /// 待补充值,最后不足间隔字符数时,用此字符补齐;Supplement=""时,不补任何字符。 /// 返回新生成字符串 - public static string InsertFormat(bool isRight, string input, int interval, string value, string Supplement) + public static string InsertFormat(bool isRight, string input, int interval, string value, string supplement) { if (!isRight) //从左边开始插入 { @@ -1036,13 +1036,13 @@ namespace HexcalMC.Base input = input.Insert(i, value); } - if (Supplement != "") + if (supplement != "") { do { if ((input.Length + 1) % (interval + 1) != 0) { - input = input + Supplement; + input = input + supplement; } } while ((input.Length + 1) % (interval + 1) != 0); } @@ -1054,13 +1054,13 @@ namespace HexcalMC.Base input = input.Insert(i, value); } - if (Supplement != "") + if (supplement != "") { do { if ((input.Length + 1) % (interval + 1) != 0) { - input = Supplement + input; + input = supplement + input; } } while ((input.Length + 1) % (interval + 1) != 0); } @@ -1074,15 +1074,15 @@ namespace HexcalMC.Base /// /// 待校验字符串 /// 返回结果 - public static string GetBCC(string strCmd) + public static string GetBcc(string strCmd) { if (strCmd.Length >= 2) { - byte[] Buffer = Encoding.Default.GetBytes(strCmd); - byte byteBCC = Buffer[0]; - for (int i = 1; i < Buffer.Length; i++) - byteBCC ^= Buffer[i]; - return Convert.ToChar(byteBCC).ToString(); + byte[] buffer = Encoding.Default.GetBytes(strCmd); + byte byteBcc = buffer[0]; + for (int i = 1; i < buffer.Length; i++) + byteBcc ^= buffer[i]; + return Convert.ToChar(byteBcc).ToString(); } else { @@ -1095,16 +1095,16 @@ namespace HexcalMC.Base /// /// 待校验数组 /// 返回结果 - public static byte[] GetBCC(byte[] byteData) + public static byte[] GetBcc(byte[] byteData) { byte[] byteWrite = new byte[byteData.Length + 1]; if (byteData.Length >= 2) { byteData.CopyTo(byteWrite, 0); - byte byteBCC = byteData[0]; + byte byteBcc = byteData[0]; for (int i = 1; i < byteData.Length; i++) - byteBCC ^= byteData[i]; - byteWrite[byteWrite.Length - 1] = byteBCC; + byteBcc ^= byteData[i]; + byteWrite[byteWrite.Length - 1] = byteBcc; return byteWrite; } else @@ -1116,15 +1116,15 @@ namespace HexcalMC.Base /// /// CRC16校验函数 /// - public class CRC16Check + public class Crc16Check { - private const int CRC_LEN = 0; + private const int CrcLen = 0; // Table of CRC values for high-order byte #region - static readonly byte[] _auchCRCHi = new byte[] + static readonly byte[] AuchCrcHi = new byte[] { 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, @@ -1160,7 +1160,7 @@ namespace HexcalMC.Base #region - static readonly byte[] _auchCRCLo = new byte[] + static readonly byte[] AuchCrcLo = new byte[] { 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD, @@ -1204,12 +1204,12 @@ namespace HexcalMC.Base crcHi = 0xff; // high crc byte initialized crcLo = 0xff; // low crc byte initialized - for (int i = 0; i < buffer.Length - CRC_LEN; i++) + for (int i = 0; i < buffer.Length - CrcLen; i++) { int crcIndex = crcHi ^ buffer[i]; // calculate the crc lookup index - crcHi = (byte)(crcLo ^ _auchCRCHi[crcIndex]); - crcLo = _auchCRCLo[crcIndex]; + crcHi = (byte)(crcLo ^ AuchCrcHi[crcIndex]); + crcLo = AuchCrcLo[crcIndex]; } return (ushort)(crcHi << 8 | crcLo); @@ -1229,17 +1229,17 @@ namespace HexcalMC.Base /// /// 图像转换为Byte数组 /// - static public byte[] ImageToByteArray(Image ImageIn) + static public byte[] ImageToByteArray(Image imageIn) { MemoryStream ms = new MemoryStream(); - ImageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Png); + imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Png); return ms.ToArray(); } /// /// Byte数组转换为图像 /// - static public Image byteArrayToImage(byte[] byteArrayIn) + static public Image ByteArrayToImage(byte[] byteArrayIn) { MemoryStream ms = new MemoryStream(byteArrayIn); Image returnImage = Image.FromStream(ms); @@ -1370,12 +1370,12 @@ namespace HexcalMC.Base return strings; } - public static void AddStringsToListView(ListView m_ListView, string[] strings) + public static void AddStringsToListView(ListView mListView, string[] strings) { - m_ListView.Items.Clear(); + mListView.Items.Clear(); for (int i = 0; i < strings.Length; i++) { - m_ListView.Items.Add(strings[i]); + mListView.Items.Add(strings[i]); } } @@ -1405,18 +1405,18 @@ namespace HexcalMC.Base //将字节数组形式的mac地址转化为对应的字符串 public static string MacToString(byte[] mac) { - string MacString = ""; + string macString = ""; for (int i = 0; i < 6; i++) { - MacString += ByteToHexString(mac[i]); + macString += ByteToHexString(mac[i]); if (i < 5) { - MacString += ":"; + macString += ":"; } } - return MacString; + return macString; } //将字符串形式的mac地址转化为对应的字节数组 @@ -1506,7 +1506,7 @@ namespace HexcalMC.Base return data; } - public static string bytes2String(byte[] data, int offset, int len) + public static string Bytes2String(byte[] data, int offset, int len) { string outString = ""; @@ -1617,7 +1617,7 @@ namespace HexcalMC.Base } //将ushort类型的数据转化为十六进制字符串 - public static string ushortToHexString(ushort[] data, int pos, int length) + public static string UshortToHexString(ushort[] data, int pos, int length) { string outString = ""; @@ -1729,7 +1729,7 @@ namespace HexcalMC.Base string x = ""; if (d < 16) { - x = chang(d); + x = Chang(d); } else { @@ -1748,11 +1748,11 @@ namespace HexcalMC.Base do { c = d / 16; - m[i++] = chang(d % 16); //判断是否大于10,如果大于10,则转换为A~F的格式 + m[i++] = Chang(d % 16); //判断是否大于10,如果大于10,则转换为A~F的格式 d = c; } while (c >= 16); - x = chang(d); + x = Chang(d); for (int j = m.Length - 1; j >= 0; j--) { x += m[j]; @@ -1763,7 +1763,7 @@ namespace HexcalMC.Base } //判断是否为10~15之间的数,如果是则进行转换 - public static string chang(int d) + public static string Chang(int d) { string x = ""; switch (d) @@ -1857,16 +1857,16 @@ namespace HexcalMC.Base /// class MyMath { - public static double GetMax(double[] Datas) + public static double GetMax(double[] datas) { - double Max = -9999; + double max = -9999; try { - if (Datas.Length == 1) - return Datas[0]; - for (int i = 0; i < Datas.Length; i++) + if (datas.Length == 1) + return datas[0]; + for (int i = 0; i < datas.Length; i++) { - Max = Math.Max(Datas[i], Max); + max = Math.Max(datas[i], max); } } catch (Exception ex) @@ -1874,19 +1874,19 @@ namespace HexcalMC.Base MessageBox.Show(ex.Message); } - return Max; + return max; } - public static double GetMin(double[] Datas) + public static double GetMin(double[] datas) { - double Min = 9999; + double min = 9999; try { - if (Datas.Length == 1) - return Datas[0]; - for (int i = 0; i < Datas.Length; i++) + if (datas.Length == 1) + return datas[0]; + for (int i = 0; i < datas.Length; i++) { - Min = Math.Min(Datas[i], Min); + min = Math.Min(datas[i], min); } } catch (Exception ex) @@ -1894,16 +1894,16 @@ namespace HexcalMC.Base MessageBox.Show(ex.Message); } - return Min; + return min; } /// /// 获取PLC读取地址数据(从起始地址偏移) /// /// 数据数组 - /// PLC读取地址,从0开始 + /// PLC读取地址,从0开始 /// 返回整形数据或-1 - public static int GetPlcData(byte[] byteData, int DataAddr) + public static int GetPlcData(byte[] byteData, int dataAddr) { try { @@ -1912,14 +1912,14 @@ namespace HexcalMC.Base return -1; } - if (byteData.Length < 10 + DataAddr * 2) + if (byteData.Length < 10 + dataAddr * 2) { return -1; } else { - int bitH = DataAddr * 2 + 9; - int bitL = DataAddr * 2 + 10; + int bitH = dataAddr * 2 + 9; + int bitL = dataAddr * 2 + 10; return byteData[bitH] * 256 + byteData[bitL]; } } @@ -1933,10 +1933,10 @@ namespace HexcalMC.Base /// 获取PLC读取地址数据(从起始地址偏移) /// /// 数据数组 - /// PLC读取地址 + /// PLC读取地址 /// PLC读取起始地址 /// 返回整形数据或-1 - public static int GetPlcData(byte[] byteData, int DataAddr, int startAddr) + public static int GetPlcData(byte[] byteData, int dataAddr, int startAddr) { try { @@ -1945,20 +1945,20 @@ namespace HexcalMC.Base return -1; } - if (startAddr > DataAddr) + if (startAddr > dataAddr) { //MessageBox.Show("错误:要读取的数据小于起始地址"); return -1; } - if (byteData.Length < 9 + (DataAddr - startAddr) * 2) + if (byteData.Length < 9 + (dataAddr - startAddr) * 2) { return -1; } else { - int bitH = (DataAddr - startAddr) * 2 + 9; - int bitL = (DataAddr - startAddr) * 2 + 10; + int bitH = (dataAddr - startAddr) * 2 + 9; + int bitL = (dataAddr - startAddr) * 2 + 10; return byteData[bitH] * 256 + byteData[bitL]; } } @@ -2062,17 +2062,17 @@ namespace HexcalMC.Base /// /// 从0开始 /// - public static bool GetPlcBit(byte[] byteData, int DataAddr, int index, int startAddr) + public static bool GetPlcBit(byte[] byteData, int dataAddr, int index, int startAddr) { - int Value = GetPlcData(byteData, DataAddr, startAddr); - bool bResult = GetPlcBit(Value, index); + int value = GetPlcData(byteData, dataAddr, startAddr); + bool bResult = GetPlcBit(value, index); return bResult; } - public static bool GetPlcBitH2Low(byte[] byteData, int DataAddr, int index, int startAddr) + public static bool GetPlcBitH2Low(byte[] byteData, int dataAddr, int index, int startAddr) { - int Value = GetPlcData(byteData, DataAddr, startAddr); - bool bResult = GetPlcBitH2Low(Value, index); + int value = GetPlcData(byteData, dataAddr, startAddr); + bool bResult = GetPlcBitH2Low(value, index); return bResult; } @@ -2081,11 +2081,11 @@ namespace HexcalMC.Base /// 获取单精度浮点数(float)数据 /// /// PLC读取总数据 - /// 获取数据的地址 + /// 获取数据的地址 /// PLC起始地址 - /// 数据正反序 + /// 数据正反序 /// - public static float GetPlcSingle(byte[] byteData, int DataAddr, int startAddr, bool PositiveSequence = true) + public static float GetPlcSingle(byte[] byteData, int dataAddr, int startAddr, bool positiveSequence = true) { try { @@ -2094,19 +2094,19 @@ namespace HexcalMC.Base return -1; } - if (startAddr > DataAddr) + if (startAddr > dataAddr) { return -1; } - if (byteData.Length < 9 + (DataAddr - startAddr) * 2) + if (byteData.Length < 9 + (dataAddr - startAddr) * 2) { return -1; } else { - float Result = -1; - int startBit = (DataAddr - startAddr) * 2 + 9; + float result = -1; + int startBit = (dataAddr - startAddr) * 2 + 9; byte[] arrLength = new byte[4]; arrLength[0] = byteData[startBit + 0]; @@ -2114,17 +2114,17 @@ namespace HexcalMC.Base arrLength[2] = byteData[startBit + 2]; arrLength[3] = byteData[startBit + 3]; - if (PositiveSequence) + if (positiveSequence) { - Result = BitConverter.ToSingle(arrLength, 0); + result = BitConverter.ToSingle(arrLength, 0); } else { - Result = BitConverter.ToSingle(arrLength.Reverse().ToArray(), 0); + result = BitConverter.ToSingle(arrLength.Reverse().ToArray(), 0); } - Result = Convert.ToSingle(Math.Round(Result, 3)); - return Result; + result = Convert.ToSingle(Math.Round(result, 3)); + return result; } } catch @@ -2137,42 +2137,42 @@ namespace HexcalMC.Base /// 获取字符串(string) /// /// PLC读取总数据 - /// 获取数据的地址 + /// 获取数据的地址 /// PLC起始地址 - /// 读取的地址数量(单位16) - /// 数据正反序 + /// 读取的地址数量(单位16) + /// 数据正反序 /// 转换为字符串类型,2=二进制,10=十进制,16=十六进制,其他=char字符串 /// - public static string GetPlcString(byte[] byteData, int DataAddr, int startAddr, int DataNum, - bool PositiveSequence = true, int strType = 0) + public static string GetPlcString(byte[] byteData, int dataAddr, int startAddr, int dataNum, + bool positiveSequence = true, int strType = 0) { - string Result = ""; + string result = ""; try { if (byteData == null) { - return Result; + return result; } - if (startAddr > DataAddr + DataNum) + if (startAddr > dataAddr + dataNum) { - return Result; + return result; } - if (byteData.Length < 9 + (DataAddr - startAddr) * 2) + if (byteData.Length < 9 + (dataAddr - startAddr) * 2) { - return Result; + return result; } else { - int startBit = (DataAddr - startAddr) * 2 + 9; - byte[] arrLength = new byte[DataNum * 2]; - for (int i = 0; i < DataNum * 2; i++) + int startBit = (dataAddr - startAddr) * 2 + 9; + byte[] arrLength = new byte[dataNum * 2]; + for (int i = 0; i < dataNum * 2; i++) { arrLength[i] = byteData[startBit + i]; } - if (!PositiveSequence) + if (!positiveSequence) { arrLength = (byte[])arrLength.Reverse(); } @@ -2182,21 +2182,21 @@ namespace HexcalMC.Base case 2: foreach (byte b in arrLength) { - Result += ConvertBase.MyConvert.DtoB(b); + result += ConvertBase.MyConvert.DtoB(b); } break; case 10: foreach (byte b in arrLength) { - Result += b.ToString(); + result += b.ToString(); } break; case 16: foreach (byte b in arrLength) { - Result += b.ToString("X2"); + result += b.ToString("X2"); } break; @@ -2204,18 +2204,18 @@ namespace HexcalMC.Base default: foreach (byte b in arrLength) { - Result += Convert.ToChar(b).ToString(); + result += Convert.ToChar(b).ToString(); } break; } - return Result.Trim(); + return result.Trim(); } } catch { - return Result; + return result; } } @@ -2224,14 +2224,14 @@ namespace HexcalMC.Base /// /// 字节数组(byte 8位)转化为ushort(16位)数组 /// - public static ushort[] GetushortsFromValue(byte[] Value) + public static ushort[] GetushortsFromValue(byte[] value) { ushort[] rtnValues; - byte[] bytes = Value; - int Length = bytes.Length / 2; + byte[] bytes = value; + int length = bytes.Length / 2; if (bytes.Length % 2 == 0) { - rtnValues = new ushort[Length]; + rtnValues = new ushort[length]; for (int i = 0; i < bytes.Length; i += 2) { rtnValues[i / 2] = BitConverter.ToUInt16(bytes, i); @@ -2254,9 +2254,9 @@ namespace HexcalMC.Base /// /// 字符串(string)转化为ushort(16位)数组 /// - public static ushort[] GetushortsFromValue(string Value) + public static ushort[] GetushortsFromValue(string value) { - byte[] bytes = System.Text.Encoding.Default.GetBytes(Value); + byte[] bytes = System.Text.Encoding.Default.GetBytes(value); ushort[] ushorts = GetushortsFromValue(bytes); return ushorts; } @@ -2264,9 +2264,9 @@ namespace HexcalMC.Base /// /// 单精度小数(float 32位)转化为ushort(16位)数组 /// - public static ushort[] GetushortsFromValue(float Value) + public static ushort[] GetushortsFromValue(float value) { - byte[] bytes = BitConverter.GetBytes(Value); + byte[] bytes = BitConverter.GetBytes(value); ushort[] ushorts = GetushortsFromValue(bytes); return ushorts; } @@ -2274,9 +2274,9 @@ namespace HexcalMC.Base /// /// 双精度小数(double 64位)转化为ushort(16位)数组 /// - public static ushort[] GetushortsFromValue(double Value) + public static ushort[] GetushortsFromValue(double value) { - byte[] bytes = BitConverter.GetBytes(Value); + byte[] bytes = BitConverter.GetBytes(value); ushort[] ushorts = GetushortsFromValue(bytes); return ushorts; } @@ -2286,14 +2286,14 @@ namespace HexcalMC.Base /// /// 字节数组(byte 8位)转化为short(16位)数组 /// - public static short[] GetshortsFromValue(byte[] Value) + public static short[] GetshortsFromValue(byte[] value) { short[] rtnValues; - byte[] bytes = Value; - int Length = bytes.Length / 2; + byte[] bytes = value; + int length = bytes.Length / 2; if (bytes.Length % 2 == 0) { - rtnValues = new short[Length]; + rtnValues = new short[length]; for (int i = 0; i < bytes.Length; i += 2) { rtnValues[i / 2] = BitConverter.ToInt16(bytes, i); @@ -2316,9 +2316,9 @@ namespace HexcalMC.Base /// /// 字符串(string)转化为short(16位)数组 /// - public static short[] GetshortsFromValue(string Value) + public static short[] GetshortsFromValue(string value) { - byte[] bytes = System.Text.Encoding.Default.GetBytes(Value); + byte[] bytes = System.Text.Encoding.Default.GetBytes(value); short[] shorts = GetshortsFromValue(bytes); return shorts; } @@ -2326,9 +2326,9 @@ namespace HexcalMC.Base /// /// 整形(int 32位)转化为short(16位)数组 /// - public static short[] GetshortsFromValue(int Value) + public static short[] GetshortsFromValue(int value) { - byte[] bytes = BitConverter.GetBytes(Value); + byte[] bytes = BitConverter.GetBytes(value); short[] shorts = GetshortsFromValue(bytes); return shorts; } @@ -2336,9 +2336,9 @@ namespace HexcalMC.Base /// /// 单精度小数(float 32位)转化为short(16位)数组 /// - public static short[] GetshortsFromValue(float Value) + public static short[] GetshortsFromValue(float value) { - byte[] bytes = BitConverter.GetBytes(Value); + byte[] bytes = BitConverter.GetBytes(value); short[] shorts = GetshortsFromValue(bytes); return shorts; } @@ -2346,9 +2346,9 @@ namespace HexcalMC.Base /// /// 双精度小数(double 64位)转化为ushort(16位)数组 /// - public static short[] GetshortsFromValue(double Value) + public static short[] GetshortsFromValue(double value) { - byte[] bytes = BitConverter.GetBytes(Value); + byte[] bytes = BitConverter.GetBytes(value); short[] shorts = GetshortsFromValue(bytes); return shorts; } @@ -2357,7 +2357,7 @@ namespace HexcalMC.Base class CodeDfn { public const string BlankSpace = " "; - public const string strEnter = "\r\n"; + public const string StrEnter = "\r\n"; } class PlcMath @@ -2380,9 +2380,9 @@ namespace HexcalMC.Base } } - public static bool GetS7BoolData(byte[] byteData, int DataAddr, int startAddr, int index) + public static bool GetS7BoolData(byte[] byteData, int dataAddr, int startAddr, int index) { - byte data = GetS7ByteData(byteData, DataAddr, startAddr); + byte data = GetS7ByteData(byteData, dataAddr, startAddr); return GetS7BoolBit(data, index); } @@ -2390,10 +2390,10 @@ namespace HexcalMC.Base /// 获取PLC读取地址数据(从起始地址偏移) /// /// 数据数组 - /// PLC读取地址 + /// PLC读取地址 /// PLC读取起始地址 /// 返回整形数据或-1 - public static byte GetS7ByteData(byte[] byteData, int DataAddr, int startAddr) + public static byte GetS7ByteData(byte[] byteData, int dataAddr, int startAddr) { try { @@ -2402,21 +2402,21 @@ namespace HexcalMC.Base return 0; } - if (startAddr > DataAddr) + if (startAddr > dataAddr) { MessageBox.Show("错误:获取S7字节数据, 要读取的数据小于起始地址"); return 0; } - if (byteData.Length < (DataAddr - startAddr)) + if (byteData.Length < (dataAddr - startAddr)) { - MessageBox.Show("错误:获取S7字节数据, 要读取的偏移地址超出数组长度,偏移=" + (DataAddr - startAddr) + ", 数组长度=" + + MessageBox.Show("错误:获取S7字节数据, 要读取的偏移地址超出数组长度,偏移=" + (dataAddr - startAddr) + ", 数组长度=" + byteData.Length); return 0; } else { - int bit = DataAddr - startAddr; + int bit = dataAddr - startAddr; return byteData[bit]; } } @@ -2431,10 +2431,10 @@ namespace HexcalMC.Base /// 获取PLC读取地址数据(从起始地址偏移) /// /// 数据数组 - /// PLC读取地址 + /// PLC读取地址 /// PLC读取起始地址 /// 返回整形数据或-1 - public static byte GetS7ByteData(byte[] byteData, int DataAddr) + public static byte GetS7ByteData(byte[] byteData, int dataAddr) { try { @@ -2449,7 +2449,7 @@ namespace HexcalMC.Base return 0; } - return byteData[DataAddr]; + return byteData[dataAddr]; } catch (Exception ex) { @@ -2458,7 +2458,7 @@ namespace HexcalMC.Base } } - public static int GetS7WordData(byte[] byteData, int DataAddr, int startAddr) + public static int GetS7WordData(byte[] byteData, int dataAddr, int startAddr) { try { @@ -2467,13 +2467,13 @@ namespace HexcalMC.Base return -1; } - if (startAddr > DataAddr) + if (startAddr > dataAddr) { //MessageBox.Show("错误:要读取的数据小于起始地址"); return -1; } - if (byteData.Length < (DataAddr - startAddr) * 2) + if (byteData.Length < (dataAddr - startAddr) * 2) { return -1; } @@ -2481,8 +2481,8 @@ namespace HexcalMC.Base { //int bitH = (DataAddr - startAddr) * 2; //int bitL = (DataAddr - startAddr) * 2 + 1; - int bitH = (DataAddr - startAddr); - int bitL = (DataAddr - startAddr) + 1; + int bitH = (dataAddr - startAddr); + int bitL = (dataAddr - startAddr) + 1; return byteData[bitH] * 256 + byteData[bitL]; } } @@ -2497,42 +2497,42 @@ namespace HexcalMC.Base /// 获取字符串(string) /// /// PLC读取总数据 - /// 获取数据的地址 + /// 获取数据的地址 /// PLC起始地址 - /// 读取的地址数量(单位16) - /// 数据正反序 + /// 读取的地址数量(单位16) + /// 数据正反序 /// 转换为字符串类型,2=二进制,10=十进制,16=十六进制,其他=char字符串 /// - public static string GetS7StringData(byte[] byteData, int DataAddr, int startAddr, int DataNum, int strType = 0, - bool PositiveSequence = true) + public static string GetS7StringData(byte[] byteData, int dataAddr, int startAddr, int dataNum, int strType = 0, + bool positiveSequence = true) { - string Result = ""; + string result = ""; try { if (byteData == null) { - return Result; + return result; } - if (startAddr > DataAddr + DataNum) + if (startAddr > dataAddr + dataNum) { - return Result; + return result; } - if (byteData.Length < (DataAddr - startAddr)) + if (byteData.Length < (dataAddr - startAddr)) { - return Result; + return result; } else { - int startBit = (DataAddr - startAddr); - byte[] arrLength = new byte[DataNum]; - for (int i = 0; i < DataNum; i++) + int startBit = (dataAddr - startAddr); + byte[] arrLength = new byte[dataNum]; + for (int i = 0; i < dataNum; i++) { arrLength[i] = byteData[startBit + i]; } - if (!PositiveSequence) + if (!positiveSequence) { arrLength = (byte[])arrLength.Reverse(); } @@ -2542,21 +2542,21 @@ namespace HexcalMC.Base case 2: foreach (byte b in arrLength) { - Result += ConvertBase.MyConvert.DtoB(b); + result += ConvertBase.MyConvert.DtoB(b); } break; case 10: foreach (byte b in arrLength) { - Result += b.ToString(); + result += b.ToString(); } break; case 16: foreach (byte b in arrLength) { - Result += b.ToString("X2"); + result += b.ToString("X2"); } break; @@ -2564,18 +2564,18 @@ namespace HexcalMC.Base foreach (byte b in arrLength) { if (b >= 32) - Result += Convert.ToChar(b).ToString(); + result += Convert.ToChar(b).ToString(); } break; } - return Result.Trim(); + return result.Trim(); } } catch { - return Result; + return result; } } @@ -2588,9 +2588,9 @@ namespace HexcalMC.Base /// 获取PLC读取地址数据(从起始地址偏移) /// /// 数据数组 - /// PLC读取地址,从0开始 + /// PLC读取地址,从0开始 /// 返回整形数据或-1 - public static int GetPlcData(byte[] byteData, int DataAddr) + public static int GetPlcData(byte[] byteData, int dataAddr) { try { @@ -2599,14 +2599,14 @@ namespace HexcalMC.Base return -1; } - if (byteData.Length < DataAddr * 2) + if (byteData.Length < dataAddr * 2) { return -1; } else { - int bitH = DataAddr * 2; - int bitL = DataAddr * 2 + 1; + int bitH = dataAddr * 2; + int bitL = dataAddr * 2 + 1; return byteData[bitH] * 256 + byteData[bitL]; } } @@ -2620,10 +2620,10 @@ namespace HexcalMC.Base /// 获取PLC读取地址数据(从起始地址偏移) /// /// 数据数组 - /// PLC读取地址 + /// PLC读取地址 /// PLC读取起始地址 /// 返回整形数据或-1 - public static byte GetPlcByteData(byte[] byteData, int DataAddr, int startAddr) + public static byte GetPlcByteData(byte[] byteData, int dataAddr, int startAddr) { try { @@ -2632,20 +2632,20 @@ namespace HexcalMC.Base return 0; } - if (startAddr > DataAddr) + if (startAddr > dataAddr) { //MessageBox.Show("错误:要读取的数据小于起始地址"); return 0; } //if (byteData.Length < (DataAddr - startAddr) * 2) - if (byteData.Length < (DataAddr - startAddr)) + if (byteData.Length < (dataAddr - startAddr)) { return 0; } else { - int bit = DataAddr - startAddr; + int bit = dataAddr - startAddr; return byteData[bit]; } } @@ -2660,10 +2660,10 @@ namespace HexcalMC.Base /// 获取PLC读取地址数据(从起始地址偏移) /// /// 数据数组 - /// PLC读取地址 + /// PLC读取地址 /// PLC读取起始地址 /// 返回整形数据或-1 - public static int GetPlcData(byte[] byteData, int DataAddr, int startAddr) + public static int GetPlcData(byte[] byteData, int dataAddr, int startAddr) { try { @@ -2672,20 +2672,20 @@ namespace HexcalMC.Base return -1; } - if (startAddr > DataAddr) + if (startAddr > dataAddr) { //MessageBox.Show("错误:要读取的数据小于起始地址"); return -1; } - if (byteData.Length < (DataAddr - startAddr) * 2) + if (byteData.Length < (dataAddr - startAddr) * 2) { return -1; } else { - int bitH = (DataAddr - startAddr) * 2; - int bitL = (DataAddr - startAddr) * 2 + 1; + int bitH = (dataAddr - startAddr) * 2; + int bitL = (dataAddr - startAddr) * 2 + 1; return byteData[bitH] * 256 + byteData[bitL]; } } @@ -2789,17 +2789,17 @@ namespace HexcalMC.Base /// /// 从0开始 /// - public static bool GetPlcBit(byte[] byteData, int DataAddr, int index, int startAddr) + public static bool GetPlcBit(byte[] byteData, int dataAddr, int index, int startAddr) { - int Value = GetPlcData(byteData, DataAddr, startAddr); - bool bResult = GetPlcBit(Value, index); + int value = GetPlcData(byteData, dataAddr, startAddr); + bool bResult = GetPlcBit(value, index); return bResult; } - public static bool GetPlcBitH2Low(byte[] byteData, int DataAddr, int index, int startAddr) + public static bool GetPlcBitH2Low(byte[] byteData, int dataAddr, int index, int startAddr) { - int Value = GetPlcData(byteData, DataAddr, startAddr); - bool bResult = GetPlcBitH2Low(Value, index); + int value = GetPlcData(byteData, dataAddr, startAddr); + bool bResult = GetPlcBitH2Low(value, index); return bResult; } @@ -2807,11 +2807,11 @@ namespace HexcalMC.Base /// 获取单精度浮点数(float)数据 /// /// PLC读取总数据 - /// 获取数据的地址 + /// 获取数据的地址 /// PLC起始地址 - /// 数据正反序 + /// 数据正反序 /// - public static float GetPlcSingle(byte[] byteData, int DataAddr, int startAddr, bool PositiveSequence) + public static float GetPlcSingle(byte[] byteData, int dataAddr, int startAddr, bool positiveSequence) { try { @@ -2820,19 +2820,19 @@ namespace HexcalMC.Base return -1; } - if (startAddr > DataAddr) + if (startAddr > dataAddr) { return -1; } - if (byteData.Length < (DataAddr - startAddr)) + if (byteData.Length < (dataAddr - startAddr)) { return -1; } else { - float Result = -1; - int startBit = (DataAddr - startAddr); + float result = -1; + int startBit = (dataAddr - startAddr); byte[] arrLength = new byte[4]; arrLength[0] = byteData[startBit + 0]; @@ -2840,17 +2840,17 @@ namespace HexcalMC.Base arrLength[2] = byteData[startBit + 2]; arrLength[3] = byteData[startBit + 3]; - if (PositiveSequence) + if (positiveSequence) { - Result = BitConverter.ToSingle(arrLength, 0); + result = BitConverter.ToSingle(arrLength, 0); } else { - Result = BitConverter.ToSingle(arrLength.Reverse().ToArray(), 0); + result = BitConverter.ToSingle(arrLength.Reverse().ToArray(), 0); } - Result = Convert.ToSingle(Math.Round(Result, 3)); - return Result; + result = Convert.ToSingle(Math.Round(result, 3)); + return result; } } catch @@ -2863,42 +2863,42 @@ namespace HexcalMC.Base /// 获取字符串(string) /// /// PLC读取总数据 - /// 获取数据的地址 + /// 获取数据的地址 /// PLC起始地址 - /// 读取的地址数量(单位16) - /// 数据正反序 + /// 读取的地址数量(单位16) + /// 数据正反序 /// 转换为字符串类型,2=二进制,10=十进制,16=十六进制,其他=char字符串 /// - public static string GetPlcString(byte[] byteData, int DataAddr, int startAddr, int DataNum, int strType = 0, - bool PositiveSequence = true) + public static string GetPlcString(byte[] byteData, int dataAddr, int startAddr, int dataNum, int strType = 0, + bool positiveSequence = true) { - string Result = ""; + string result = ""; try { if (byteData == null) { - return Result; + return result; } - if (startAddr > DataAddr + DataNum) + if (startAddr > dataAddr + dataNum) { - return Result; + return result; } - if (byteData.Length < (DataAddr - startAddr) * 2) + if (byteData.Length < (dataAddr - startAddr) * 2) { - return Result; + return result; } else { - int startBit = (DataAddr - startAddr) * 2; - byte[] arrLength = new byte[DataNum * 2]; - for (int i = 0; i < DataNum * 2; i++) + int startBit = (dataAddr - startAddr) * 2; + byte[] arrLength = new byte[dataNum * 2]; + for (int i = 0; i < dataNum * 2; i++) { arrLength[i] = byteData[startBit + i]; } - if (!PositiveSequence) + if (!positiveSequence) { arrLength = (byte[])arrLength.Reverse(); } @@ -2908,21 +2908,21 @@ namespace HexcalMC.Base case 2: foreach (byte b in arrLength) { - Result += ConvertBase.MyConvert.DtoB(b); + result += ConvertBase.MyConvert.DtoB(b); } break; case 10: foreach (byte b in arrLength) { - Result += b.ToString(); + result += b.ToString(); } break; case 16: foreach (byte b in arrLength) { - Result += b.ToString("X2"); + result += b.ToString("X2"); } break; @@ -2930,27 +2930,27 @@ namespace HexcalMC.Base foreach (byte b in arrLength) { if (b >= 32) - Result += Convert.ToChar(b).ToString(); + result += Convert.ToChar(b).ToString(); } break; } - return Result.Trim(); + return result.Trim(); } } catch { - return Result; + return result; } } #endregion } - public class IPAddressValidator + public class IpAddressValidator { - public static bool IsIPAddressValid(string ipAddress) + 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]?)$"; return Regex.IsMatch(ipAddress, pattern); diff --git a/HexcalMC/Base/DebugDfn.cs b/HexcalMC/Base/DebugDfn.cs index 88ea8e1..abe9951 100644 --- a/HexcalMC/Base/DebugDfn.cs +++ b/HexcalMC/Base/DebugDfn.cs @@ -12,32 +12,32 @@ namespace HexcalMC.Base { public class DebugDfn { - public static string strDebugFile = Application.StartupPath + "\\File\\Debug.txt"; - public static string strDebugSavePath = Application.StartupPath + "\\File\\DebugFiles"; - public static string strDebugFileTemp = Application.StartupPath + "\\File\\DebugTemp.txt"; //临时存储,用于菜单查看 - static string strStartTime = ""; //程序启动时间 - static string strEndTime = ""; //程序关闭时间 + public static string StrDebugFile = Application.StartupPath + "\\File\\Debug.txt"; + public static string StrDebugSavePath = Application.StartupPath + "\\File\\DebugFiles"; + public static string StrDebugFileTemp = Application.StartupPath + "\\File\\DebugTemp.txt"; //临时存储,用于菜单查看 + static string _strStartTime = ""; //程序启动时间 + static string _strEndTime = ""; //程序关闭时间 - public static RichTextBox textBox_Msg; + public static RichTextBox TextBoxMsg; //================================================================= public static void StartDebugObj() { - System.IO.TextWriter log = new System.IO.StreamWriter(DebugDfn.strDebugFile); + System.IO.TextWriter log = new System.IO.StreamWriter(DebugDfn.StrDebugFile); TextWriterTraceListener logger = new TextWriterTraceListener(log); Trace.Listeners.Add(logger); - strStartTime = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"); + _strStartTime = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"); } public static void SaveDebugFile() { AddLog("软件关闭!"); - strEndTime = DateTime.Now.ToString("yyyy.MM.dd HH-mm-ss"); - string CopyFileName = strDebugSavePath + "\\DebugFiles\\" + "Debug(" + strStartTime + " To " + - strEndTime + ")" + ".txt"; - if (File.Exists(strDebugFile)) - File.Copy(strDebugFile, CopyFileName, true); + _strEndTime = DateTime.Now.ToString("yyyy.MM.dd HH-mm-ss"); + string copyFileName = StrDebugSavePath + "\\DebugFiles\\" + "Debug(" + _strStartTime + " To " + + _strEndTime + ")" + ".txt"; + if (File.Exists(StrDebugFile)) + File.Copy(StrDebugFile, copyFileName, true); } //================================================================= @@ -49,45 +49,45 @@ namespace HexcalMC.Base MyBase.TraceWriteLine(str); } - public static void AddLogText(string str, Color m_Color = new Color()) + public static void AddLogText(string str, Color mColor = new Color()) { MyBase.TraceWriteLine(str); try { - textBox_Msg.BeginInvoke((EventHandler)delegate + TextBoxMsg.BeginInvoke((EventHandler)delegate { - Color SetColor = Color.White; - if (m_Color == new Color()) + Color setColor = Color.White; + if (mColor == new Color()) { if (str.ToUpper().Contains("ERROR") || str.ToUpper().Contains("错误") || str.ToUpper().Contains("出错") || str.ToUpper().Contains("EXCEPTION") || str.ToUpper().Contains("异常") || str.ToUpper().Contains("失败")) { - SetColor = Color.Red; + setColor = Color.Red; } else if (str.ToUpper().Contains("WARNING") || str.ToUpper().Contains("警告")) { - SetColor = Color.DarkOrange; + setColor = Color.DarkOrange; } } else { - SetColor = m_Color; + setColor = mColor; } string strText = DateTime.Now.ToString("HH:mm:ss.ff") + "--" + str + Environment.NewLine; - textBox_Msg.SelectionStart = textBox_Msg.TextLength; + TextBoxMsg.SelectionStart = TextBoxMsg.TextLength; if (string.IsNullOrEmpty(str)) - SetText(textBox_Msg, str, SetColor, false, 16); + SetText(TextBoxMsg, str, setColor, false, 16); else - SetText(textBox_Msg, strText, SetColor, false, 16); - if (textBox_Msg.Lines.Length > 800) + SetText(TextBoxMsg, strText, setColor, false, 16); + if (TextBoxMsg.Lines.Length > 800) { - textBox_Msg.Select(0, textBox_Msg.TextLength / 2); - textBox_Msg.Cut(); + TextBoxMsg.Select(0, TextBoxMsg.TextLength / 2); + TextBoxMsg.Cut(); } - textBox_Msg.ScrollToCaret(); + TextBoxMsg.ScrollToCaret(); }); } catch @@ -95,32 +95,32 @@ namespace HexcalMC.Base } } - public static void SetText(RichTextBox m_RichTextBox, string strText, Color m_Color, bool bBold = false, - float Size = 16) + public static void SetText(RichTextBox mRichTextBox, string strText, Color mColor, bool bBold = false, + float size = 16) { - m_RichTextBox.Invoke(((EventHandler)delegate + mRichTextBox.Invoke(((EventHandler)delegate { - SetFont(m_RichTextBox, m_Color, bBold, Size); - m_RichTextBox.SelectedText = strText; + SetFont(mRichTextBox, mColor, bBold, size); + mRichTextBox.SelectedText = strText; })); } - public static void SetFont(RichTextBox m_RichTextBox, Color m_Color, bool bBold = false, float Size = 16) + public static void SetFont(RichTextBox mRichTextBox, Color mColor, bool bBold = false, float size = 16) { - m_RichTextBox.SelectionColor = m_Color; + mRichTextBox.SelectionColor = mColor; if (bBold) - m_RichTextBox.SelectionFont = new System.Drawing.Font("Segoe UI", Size, System.Drawing.FontStyle.Bold, + mRichTextBox.SelectionFont = new System.Drawing.Font("Segoe UI", size, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel, ((byte)(134))); else - m_RichTextBox.SelectionFont = new System.Drawing.Font("Segoe UI", Size, + mRichTextBox.SelectionFont = new System.Drawing.Font("Segoe UI", size, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134))); } - public static void SetErrorColor(Color InColor) + public static void SetErrorColor(Color inColor) { - if (textBox_Msg != null) + if (TextBoxMsg != null) { - textBox_Msg.BeginInvoke((EventHandler)delegate { textBox_Msg.BackColor = InColor; }); + TextBoxMsg.BeginInvoke((EventHandler)delegate { TextBoxMsg.BackColor = inColor; }); } } diff --git a/HexcalMC/Hexcal/TcpIpServer.cs b/HexcalMC/Hexcal/TcpIpServer.cs index befcb7f..d52857c 100644 --- a/HexcalMC/Hexcal/TcpIpServer.cs +++ b/HexcalMC/Hexcal/TcpIpServer.cs @@ -1,25 +1,22 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Net.Sockets; using System.Net; +using System.Net.Sockets; using System.Text; using System.Threading; -using System.Threading.Tasks; using System.Windows.Forms; +using Timer = System.Windows.Forms.Timer; namespace HexcalMC.Hexcal { public class TcpIpServer { - /// - /// 使用模式,默认=1,接收任意数据显示;2=前两个字节为数据长度 - /// - public int UseMode = 1; + public delegate void EventHandlerRaisedMessage(string clientIp, string msg); - string strServerIP = "127.0.0.1"; //服务器的IP地址 - string strServerPort = "8080"; //端口号 - public enum EnumTcpIpServer : int + public delegate void EventHandlerRaisedStatus(EnumTcpIpServer type, string msg); + + public enum EnumTcpIpServer { StartListen = 1, ClientConnect = 2, @@ -28,68 +25,55 @@ namespace HexcalMC.Hexcal Exception = -1 } - #region 510,增加时钟,判断是否有断掉的连接。 + private readonly Dictionary _dictSocket = new Dictionary(); + private readonly Dictionary _dictThread = new Dictionary(); + private Socket _mWatchSocket; - System.Windows.Forms.Timer ServerTimer = new System.Windows.Forms.Timer(); + private Thread _mWatchThread; // 负责监听客户端连接请求的线程; - private void ServerTimerLoop(object sender, EventArgs e) + private readonly string _strServerIp = "127.0.0.1"; //服务器的IP地址 + private readonly string _strServerPort = "8080"; //端口号 + + /// + /// 使用模式,默认=1,接收任意数据显示;2=前两个字节为数据长度 + /// + public int UseMode = 1; + + //========================================================================= + public TcpIpServer(string serverIp, string serverPort) { - ServerTimer.Interval = 20000; //监听timer的间隔 - if (DictSocket != null) - { - if (DictSocket.Count != 0) - { - DictSocket.Values.ToArray(); - for (int i = DictSocket.Values.ToArray().Length - 1; i >= 0; i--) - { - if (DictSocket.Values.ToArray()[i].Poll(10, SelectMode.SelectRead)) //10毫秒,检查套接字状态, SelectMode 参数指定要监视的套接字的类别。 - { - // DictSocket.Remove(DictSocket.Keys.ToArray()[i]); + _strServerIp = serverIp; + _strServerPort = serverPort; + } - RaisedStatus(EnumTcpIpServer.ConnectException, - "连接已断开:" + DictSocket.Keys.ToArray()[i]); //刷新界面显示,触发一个连接异常状态枚举,并将消息传递为异常的状态 - RemoveSocketClient(DictSocket.Keys.ToArray()[i]); - } - } - } + public string[] SocketNames => _dictSocket.Keys.ToArray(); + + public bool ConnectStatus + { + get + { + if (_mWatchSocket == null) + return false; + return _mWatchSocket.Connected && _mWatchThread != null; } } - #endregion - - - Thread m_WatchThread = null; // 负责监听客户端连接请求的线程; - Socket m_WatchSocket = null; - Dictionary DictThread = new Dictionary(); - Dictionary DictSocket = new Dictionary(); - bool bStartListen = false; - - public string[] SocketNames - { - get { return (string[])DictSocket.Keys.ToArray(); } - } - - //========================================================================= - public TcpIpServer(string ServerIP, string ServerPort) - { - strServerIP = ServerIP; - strServerPort = ServerPort; - } + public bool WatchStatus { get; private set; } public bool StartListen() { try { - ServerTimer.Tick += new EventHandler(ServerTimerLoop); //510,增加时钟,判断是否有断掉的连接。 - ServerTimer.Start(); + _serverTimer.Tick += ServerTimerLoop; //510,增加时钟,判断是否有断掉的连接。 + _serverTimer.Start(); - m_WatchSocket = + _mWatchSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //创建负责监听的套接字,注意其中的参数; - IPAddress m_IpAddr = IPAddress.Parse(strServerIP); //获得文本框中的IP对象; - IPEndPoint m_EndPoint = new IPEndPoint(m_IpAddr, int.Parse(strServerPort)); //创建包含ip和端口号的网络节点对象; + IPAddress mIpAddr = IPAddress.Parse(_strServerIp); //获得文本框中的IP对象; + IPEndPoint mEndPoint = new IPEndPoint(mIpAddr, int.Parse(_strServerPort)); //创建包含ip和端口号的网络节点对象; try { - m_WatchSocket.Bind(m_EndPoint); // 将负责监听的套接字绑定到唯一的ip和端口上; + _mWatchSocket.Bind(mEndPoint); // 将负责监听的套接字绑定到唯一的ip和端口上; } catch (SocketException se) { @@ -97,12 +81,12 @@ namespace HexcalMC.Hexcal return false; } - bStartListen = true; - m_WatchSocket.Listen(10); // 设置监听队列的长度 - m_WatchThread = new Thread(WatchThread); // 创建负责监听的线程 - m_WatchThread.IsBackground = true; - m_WatchThread.Start(); - RaisedStatus(EnumTcpIpServer.StartListen, "服务器启动监听成功!IP=" + strServerIP + ", Port=" + strServerPort); + WatchStatus = true; + _mWatchSocket.Listen(10); // 设置监听队列的长度 + _mWatchThread = new Thread(WatchThread); // 创建负责监听的线程 + _mWatchThread.IsBackground = true; + _mWatchThread.Start(); + RaisedStatus(EnumTcpIpServer.StartListen, "服务器启动监听成功!IP=" + _strServerIp + ", Port=" + _strServerPort); return true; } catch (Exception ex) @@ -116,75 +100,58 @@ namespace HexcalMC.Hexcal { try { - bStartListen = false; - m_WatchSocket.Close(); - m_WatchSocket.Dispose(); - m_WatchSocket = null; + WatchStatus = false; + _mWatchSocket.Close(); + _mWatchSocket.Dispose(); + _mWatchSocket = null; - DictThread.Clear(); - DictSocket.Clear(); + _dictThread.Clear(); + _dictSocket.Clear(); } catch { } } - public bool ConnectStatus - { - get - { - if (m_WatchSocket == null) - return false; - return m_WatchSocket.Connected && m_WatchThread != null; - } - } - - public bool WatchStatus - { - get { return bStartListen; } - } - //监听线程 - void WatchThread() + private void WatchThread() { try { - while (bStartListen) // 持续不断的监听客户端的连接请求; + while (WatchStatus) // 持续不断的监听客户端的连接请求; { // 开始监听客户端连接请求,Accept方法会阻断当前的线程; - Socket sokClient = m_WatchSocket.Accept(); // 一旦监听到一个客户端的请求,就返回一个与该客户端通信的套接字; + Socket sokClient = _mWatchSocket.Accept(); // 一旦监听到一个客户端的请求,就返回一个与该客户端通信的套接字; + #region 在新建连接时,判断以前的连接是否正常存在。 - #region 510,在新建连接时,判断以前的连接是否正常存在。 - - if (DictSocket != null) + if (_dictSocket != null) { - if (DictSocket.Count != 0) + if (_dictSocket.Count != 0) { - DictSocket.Values.ToArray(); - for (int i = DictSocket.Values.ToArray().Length - 1; i >= 0; i--) + _dictSocket.Values.ToArray(); + for (int i = _dictSocket.Values.ToArray().Length - 1; i >= 0; i--) { - if (DictSocket.Values.ToArray()[i].Poll(10, SelectMode.SelectRead)) + if (_dictSocket.Values.ToArray()[i].Poll(10, SelectMode.SelectRead)) { //DictSocket.Remove(DictSocket.Keys.ToArray()[i]); - RemoveSocketClient(DictSocket.Keys.ToArray()[i]); + RemoveSocketClient(_dictSocket.Keys.ToArray()[i]); } } } } - #endregion + #endregion 在新建连接时,判断以前的连接是否正常存在。 - - DictSocket.Add(sokClient.RemoteEndPoint.ToString(), sokClient); // 将与客户端连接的套接字对象添加到集合中; + _dictSocket.Add(sokClient.RemoteEndPoint.ToString(), sokClient); // 将与客户端连接的套接字对象添加到集合中; RaisedStatus(EnumTcpIpServer.ClientConnect, - "客户端连接成功!RemoteEndPoint=" + sokClient.RemoteEndPoint.ToString()); + "客户端连接成功!RemoteEndPoint=" + sokClient.RemoteEndPoint); Thread thread = new Thread(ReceiveThread); thread.IsBackground = true; thread.Start(sokClient); - DictThread.Add(sokClient.RemoteEndPoint.ToString(), thread); // 将新建的线程 添加 到线程的集合中去。 + _dictThread.Add(sokClient.RemoteEndPoint.ToString(), thread); // 将新建的线程 添加 到线程的集合中去。 } } catch @@ -193,10 +160,10 @@ namespace HexcalMC.Hexcal } //接收线程 - void ReceiveThread(object sokObj) + private void ReceiveThread(object sokObj) { Socket sokClient = sokObj as Socket; - while (bStartListen) + while (WatchStatus) { // 定义一个2M的缓存区; byte[] arrMsgRec = new byte[sokClient.Available]; @@ -226,9 +193,9 @@ namespace HexcalMC.Hexcal if (length > 0) { // TcpIpDfn.SongLiang_arrMsgRec = arrMsgRec; //510 - string strData = System.Text.Encoding.Default.GetString(arrMsgRec); // 将接受到的字节数据转化成字符串; - //strData = strData.Substring(0, length); - //RaisedMessage(sokClient.RemoteEndPoint.ToString(), strData.Replace("\0", "<0>")); + string strData = Encoding.Default.GetString(arrMsgRec); // 将接受到的字节数据转化成字符串; + //strData = strData.Substring(0, length); + //RaisedMessage(sokClient.RemoteEndPoint.ToString(), strData.Replace("\0", "<0>")); RaisedMessage(sokClient.RemoteEndPoint.ToString(), strData.Replace("\0", ".")); } } @@ -238,7 +205,7 @@ namespace HexcalMC.Hexcal { // TcpIpDfn.SongLiang_arrMsgRec = arrMsgRec; //510 string strData = - System.Text.Encoding.Default.GetString(arrMsgRec, 2, + Encoding.Default.GetString(arrMsgRec, 2, arrMsgRec.Length - 2); // 将接受到的字节数据转化成字符串; RaisedMessage(sokClient.RemoteEndPoint.ToString(), strData); @@ -253,40 +220,42 @@ namespace HexcalMC.Hexcal } //删除客户端对象 - void RemoveSocketClient(string strRemoteEndPoint) + private void RemoveSocketClient(string strRemoteEndPoint) { // 从通信套接字集合中 删除被中断连接的通信套接字; - DictSocket.Remove(strRemoteEndPoint); + _dictSocket.Remove(strRemoteEndPoint); // 从通信线程集合中 删除被中断连接的通信线程对象; - DictThread.Remove(strRemoteEndPoint); + _dictThread.Remove(strRemoteEndPoint); } //发送消息 public void SendMessage(string strSocketKey, string strMsg) { - byte[] arrMsg = System.Text.Encoding.Default.GetBytes(strMsg); - DictSocket[strSocketKey].Send(arrMsg); + byte[] arrMsg = Encoding.Default.GetBytes(strMsg); + _dictSocket[strSocketKey].Send(arrMsg); } public void SendMessage(string strSocketKey, byte[] arrMsg) { - DictSocket[strSocketKey].Send(arrMsg); + _dictSocket[strSocketKey].Send(arrMsg); } - /// 发送数据函数(字符串, 自动添加长度(byte格式)) + /// + /// 发送数据函数(字符串, 自动添加长度(byte格式)) + /// public string SendMessage2(string strSocketKey, string strMsg) { try { - if (DictSocket[strSocketKey].Connected) + if (_dictSocket[strSocketKey].Connected) { byte[] arrLength = new byte[2]; arrLength = BitConverter.GetBytes(Convert.ToInt16(strMsg.Length)); - byte[] WriteBuffer = Encoding.Default.GetBytes(strMsg); - WriteBuffer = arrLength.Concat(WriteBuffer).ToArray(); + byte[] writeBuffer = Encoding.Default.GetBytes(strMsg); + writeBuffer = arrLength.Concat(writeBuffer).ToArray(); - DictSocket[strSocketKey].Send(WriteBuffer); + _dictSocket[strSocketKey].Send(writeBuffer); return ""; } @@ -300,8 +269,8 @@ namespace HexcalMC.Hexcal public void SendMessageToAllClients(string strMsg) { - byte[] arrMsg = System.Text.Encoding.Default.GetBytes(strMsg); - foreach (Socket soc in DictSocket.Values) + byte[] arrMsg = Encoding.Default.GetBytes(strMsg); + foreach (Socket soc in _dictSocket.Values) { soc.Send(arrMsg); } @@ -309,31 +278,29 @@ namespace HexcalMC.Hexcal public void SendMessageToAllClients(byte[] arrMsg) { - foreach (Socket soc in DictSocket.Values) + foreach (Socket soc in _dictSocket.Values) { soc.Send(arrMsg); } } - public delegate void EventHandler_RaisedStatus(EnumTcpIpServer Type, string Msg); - - public event EventHandler_RaisedStatus OnRaisedStatus; + public event EventHandlerRaisedStatus OnRaisedStatus; // 异步或同步触发自定义事件,并在目标控件是 Windows Forms 控件的情况下添加到目标控件的消息队列中。它主要的目的是使得自定义事件处理程序在UI线程上执行,以避免线程上的卡顿或UI更新问题。 - private void RaisedStatus(EnumTcpIpServer ReturnType, string Msg) + private void RaisedStatus(EnumTcpIpServer returnType, string msg) { try { if (OnRaisedStatus != null) { - if (OnRaisedStatus.Target is System.Windows.Forms.Control) + if (OnRaisedStatus.Target is Control) { - Control targetForm = OnRaisedStatus.Target as System.Windows.Forms.Control; - targetForm.BeginInvoke(OnRaisedStatus, new object[] { ReturnType, Msg }); + Control targetForm = OnRaisedStatus.Target as Control; + targetForm.BeginInvoke(OnRaisedStatus, returnType, msg); } else { - OnRaisedStatus(ReturnType, Msg); + OnRaisedStatus(returnType, msg); } } } @@ -342,24 +309,22 @@ namespace HexcalMC.Hexcal } } - public delegate void EventHandler_RaisedMessage(string ClientIP, string Msg); + public event EventHandlerRaisedMessage OnRaisedMessage; - public event EventHandler_RaisedMessage OnRaisedMessage; - - private void RaisedMessage(string ClientIP, string Msg) + private void RaisedMessage(string clientIp, string msg) { try { if (OnRaisedMessage != null) { - if (OnRaisedMessage.Target is System.Windows.Forms.Control) + if (OnRaisedMessage.Target is Control) { - Control targetForm = OnRaisedMessage.Target as System.Windows.Forms.Control; - targetForm.BeginInvoke(OnRaisedMessage, new object[] { ClientIP, Msg }); + Control targetForm = OnRaisedMessage.Target as Control; + targetForm.BeginInvoke(OnRaisedMessage, clientIp, msg); } else { - OnRaisedMessage(ClientIP, Msg); + OnRaisedMessage(clientIp, msg); } } } @@ -367,5 +332,35 @@ namespace HexcalMC.Hexcal { } } + + #region 增加时钟,判断是否有断掉的连接。 + + private readonly Timer _serverTimer = new Timer(); + + private void ServerTimerLoop(object sender, EventArgs e) + { + _serverTimer.Interval = 20000; //监听timer的间隔 + if (_dictSocket != null) + { + if (_dictSocket.Count != 0) + { + _dictSocket.Values.ToArray(); + for (int i = _dictSocket.Values.ToArray().Length - 1; i >= 0; i--) + { + if (_dictSocket.Values.ToArray()[i] + .Poll(10, SelectMode.SelectRead)) //10毫秒,检查套接字状态, SelectMode 参数指定要监视的套接字的类别。 + { + // DictSocket.Remove(DictSocket.Keys.ToArray()[i]); + + RaisedStatus(EnumTcpIpServer.ConnectException, + "连接已断开:" + _dictSocket.Keys.ToArray()[i]); //刷新界面显示,触发一个连接异常状态枚举,并将消息传递为异常的状态 + RemoveSocketClient(_dictSocket.Keys.ToArray()[i]); + } + } + } + } + } + + #endregion 增加时钟,判断是否有断掉的连接。 } -} +} \ No newline at end of file diff --git a/HexcalMC/HexcalMC.csproj b/HexcalMC/HexcalMC.csproj index 939fe72..86ff110 100644 --- a/HexcalMC/HexcalMC.csproj +++ b/HexcalMC/HexcalMC.csproj @@ -66,11 +66,11 @@ bin\Debug\ACS.SPiiPlusNET.dll - - packages\ScottPlot.4.1.68\lib\net462\ScottPlot.dll + + packages\ScottPlot.4.1.67\lib\net462\ScottPlot.dll - - packages\ScottPlot.WinForms.4.1.68\lib\net461\ScottPlot.WinForms.dll + + packages\ScottPlot.WinForms.4.1.67\lib\net461\ScottPlot.WinForms.dll diff --git a/HexcalMC/HexcalMC.sln b/HexcalMC/HexcalMC.sln index e9e3331..5d54756 100644 --- a/HexcalMC/HexcalMC.sln +++ b/HexcalMC/HexcalMC.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 -VisualStudioVersion = 17.7.34031.279 +VisualStudioVersion = 17.7.34221.43 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HexcalMC", "HexcalMC.csproj", "{19741897-37D8-43EE-94A2-637975035CEA}" EndProject diff --git a/HexcalMC/MainFrom.Designer.cs b/HexcalMC/MainFrom.Designer.cs index 77658a1..afe440d 100644 --- a/HexcalMC/MainFrom.Designer.cs +++ b/HexcalMC/MainFrom.Designer.cs @@ -78,6 +78,7 @@ this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.groupBox7 = new System.Windows.Forms.GroupBox(); this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.lamp_hexcal = new HexcalMC.Lamp(); this.textBox2 = new System.Windows.Forms.TextBox(); this.textBox3 = new System.Windows.Forms.TextBox(); this.btn_HexcalStop = new System.Windows.Forms.Button(); @@ -121,6 +122,7 @@ this.btnEnable = new System.Windows.Forms.Button(); this.btnDisable = new System.Windows.Forms.Button(); this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.lamp_acs = new HexcalMC.Lamp(); this.txtPort = new System.Windows.Forms.TextBox(); this.txtIP = new System.Windows.Forms.TextBox(); this.btn_ACSStop = new System.Windows.Forms.Button(); @@ -133,8 +135,6 @@ this.textBox_Msg = new System.Windows.Forms.TextBox(); this.tmrMonitor = new System.Windows.Forms.Timer(this.components); this.timer_RefreshUI = new System.Windows.Forms.Timer(this.components); - this.lamp_hexcal = new HexcalMC.Lamp(); - this.lamp_acs = new HexcalMC.Lamp(); ((System.ComponentModel.ISupportInitialize)(this.radRibbonBar1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.radRibbonBarBackstageView1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.radStatusStrip1)).BeginInit(); @@ -377,12 +377,12 @@ // this.radRibbonBar1.RootElement.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.WrapAroundChildren; this.radRibbonBar1.ShowExpandButton = false; - this.radRibbonBar1.Size = new System.Drawing.Size(1192, 173); + this.radRibbonBar1.Size = new System.Drawing.Size(1192, 176); this.radRibbonBar1.StartButtonImage = global::HexcalMC.Properties.Resources.Hexagon; this.radRibbonBar1.StartMenuItems.AddRange(new Telerik.WinControls.RadItem[] { this.radMenuItem2}); this.radRibbonBar1.TabIndex = 0; - this.radRibbonBar1.Text = "直线电机平台运动补偿"; + this.radRibbonBar1.Text = "运动补偿中间件"; // // radRibbonBarBackstageView1 // @@ -583,7 +583,7 @@ // splitContainer1 // this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; - this.splitContainer1.Location = new System.Drawing.Point(0, 173); + this.splitContainer1.Location = new System.Drawing.Point(0, 176); this.splitContainer1.Name = "splitContainer1"; // // splitContainer1.Panel1 @@ -597,7 +597,7 @@ // this.splitContainer1.Panel2.BackColor = System.Drawing.SystemColors.Control; this.splitContainer1.Panel2.Controls.Add(this.groupBox3); - this.splitContainer1.Size = new System.Drawing.Size(1192, 696); + this.splitContainer1.Size = new System.Drawing.Size(1192, 693); this.splitContainer1.SplitterDistance = 760; this.splitContainer1.TabIndex = 2; // @@ -627,6 +627,18 @@ this.groupBox1.TabStop = false; this.groupBox1.Text = "Hexcal通讯设置"; // + // lamp_hexcal + // + this.lamp_hexcal.Font = new System.Drawing.Font("宋体", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134))); + this.lamp_hexcal.Location = new System.Drawing.Point(57, 49); + this.lamp_hexcal.LText = ""; + this.lamp_hexcal.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.lamp_hexcal.Name = "lamp_hexcal"; + this.lamp_hexcal.Shadow = false; + this.lamp_hexcal.Size = new System.Drawing.Size(24, 24); + this.lamp_hexcal.State = -1; + this.lamp_hexcal.TabIndex = 29; + // // textBox2 // this.textBox2.Location = new System.Drawing.Point(103, 52); @@ -660,6 +672,7 @@ this.btn_HexcalStart.TabIndex = 25; this.btn_HexcalStart.Text = "启动"; this.btn_HexcalStart.UseVisualStyleBackColor = true; + this.btn_HexcalStart.Click += new System.EventHandler(this.btn_HexcalStart_Click); // // label3 // @@ -1056,6 +1069,18 @@ this.groupBox2.TabStop = false; this.groupBox2.Text = "ACS通讯设置"; // + // lamp_acs + // + this.lamp_acs.Font = new System.Drawing.Font("宋体", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134))); + this.lamp_acs.Location = new System.Drawing.Point(57, 50); + this.lamp_acs.LText = ""; + this.lamp_acs.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.lamp_acs.Name = "lamp_acs"; + this.lamp_acs.Shadow = false; + this.lamp_acs.Size = new System.Drawing.Size(24, 24); + this.lamp_acs.State = -1; + this.lamp_acs.TabIndex = 30; + // // txtPort // this.txtPort.Location = new System.Drawing.Point(103, 52); @@ -1160,30 +1185,6 @@ this.timer_RefreshUI.Interval = 1000; this.timer_RefreshUI.Tick += new System.EventHandler(this.timer_RefreshUI_Tick); // - // lamp_hexcal - // - this.lamp_hexcal.Font = new System.Drawing.Font("宋体", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134))); - this.lamp_hexcal.Location = new System.Drawing.Point(57, 49); - this.lamp_hexcal.LText = ""; - this.lamp_hexcal.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.lamp_hexcal.Name = "lamp_hexcal"; - this.lamp_hexcal.Shadow = false; - this.lamp_hexcal.Size = new System.Drawing.Size(24, 24); - this.lamp_hexcal.State = -1; - this.lamp_hexcal.TabIndex = 29; - // - // lamp_acs - // - this.lamp_acs.Font = new System.Drawing.Font("宋体", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134))); - this.lamp_acs.Location = new System.Drawing.Point(57, 50); - this.lamp_acs.LText = ""; - this.lamp_acs.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.lamp_acs.Name = "lamp_acs"; - this.lamp_acs.Shadow = false; - this.lamp_acs.Size = new System.Drawing.Size(24, 24); - this.lamp_acs.State = -1; - this.lamp_acs.TabIndex = 30; - // // MainFrom // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); @@ -1201,7 +1202,7 @@ // this.RootElement.ApplyShapeToControl = true; this.ShowIcon = false; - this.Text = "直线电机平台运动补偿 "; + this.Text = "运动补偿中间件"; this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.MainFrom_FormClosed); this.Load += new System.EventHandler(this.MainFrom_Load); ((System.ComponentModel.ISupportInitialize)(this.radRibbonBar1)).EndInit(); diff --git a/HexcalMC/MainFrom.cs b/HexcalMC/MainFrom.cs index f99f959..720d277 100644 --- a/HexcalMC/MainFrom.cs +++ b/HexcalMC/MainFrom.cs @@ -1,67 +1,63 @@ using ACS.SPiiPlusNET; -using HexcalMC.Hexcal; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; using HexcalMC.Base; using HexcalMC.Form; +using HexcalMC.Hexcal; +using HexcalMC.Properties; +using System; +using System.Diagnostics; +using System.Windows.Forms; +using Telerik.WinControls.UI; namespace HexcalMC { - public partial class MainFrom : Telerik.WinControls.UI.RadRibbonForm + public partial class MainFrom : RadRibbonForm { #region hexcal变量区 - private TcpIpServer m_tcpIpServer; //创建tcpserver,用于接收hexcal传来的指令,并解析传递平台 - private bool m_bHexcalConnected = false; + private TcpIpServer _mTcpIpServer; //创建tcpserver,用于接收hexcal传来的指令,并解析传递平台 + private readonly bool _mBHexcalConnected = false; - #endregion + #endregion hexcal变量区 #region 运动平台变量区 - private Api _ACS; + private Api _acs; - private const int MAX_UI_LIMIT_CNT = 8; - private const int MAX_UI_IO_CNT = 8; + private const int MaxUiLimitCnt = 8; + private const int MaxUiIoCnt = 8; - private int m_nTotalAxis = 0; - private int m_nTotalBuffer = 0; - private Axis[] m_arrAxisList = null; + private readonly int _mNTotalAxis = 0; + private int _mNTotalBuffer = 0; + private Axis[] _mArrAxisList = null; - private bool m_bConnected = false; + private readonly bool _mBConnected = false; // For update values - private MotorStates m_nMotorState; //运动状态 - private ProgramStates m_nProgramState; //程序状态 - private object m_objReadVar = null; - private Array m_arrReadVector = null; - private double m_lfRPos, m_lfFPos, m_lfPE, m_lfFVEL; //参考位置,反馈位置 位置误差 反馈速度 double类型 - private int m_nValues, m_nOutputState; + 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[] m_lblLeftLimit; //左限位 - private Label[] m_lblRightLimit; //右限位 + private Label[] _mLblLeftLimit; //左限位 + private Label[] _mLblRightLimit; //右限位 - #endregion + #endregion 运动平台变量区 public MainFrom() { InitializeComponent(); } - private void MainFrom_Load(object sender, EventArgs e) { - this.FormBorderStyle = FormBorderStyle.FixedSingle; // 设置窗体边框样式为固定大小 - this.MaximizeBox = false; // 禁用窗体的最大化按钮 + FormBorderStyle = FormBorderStyle.FixedSingle; // 设置窗体边框样式为固定大小 + MaximizeBox = false; // 禁用窗体的最大化按钮 - - double[] dataX = new double[] { 1, 2, 3, 4, 5 }; - double[] dataY = new double[] { 1, 4, 9, 16, 25 }; + double[] dataX = { 1, 2, 3, 4, 5 }; + double[] dataY = { 1, 4, 9, 16, 25 }; formsPlot1.Plot.AddScatter(dataX, dataY); formsPlot1.Refresh(); @@ -70,20 +66,22 @@ namespace HexcalMC timer_RefreshUI.Start(); } + + #region hexcal软件相关 private void StartServer() { //启动服务器,并获取数据,解析 - m_tcpIpServer = new TcpIpServer("100.0.0.1", Convert.ToString(1234)); + _mTcpIpServer = new TcpIpServer("100.0.0.1", Convert.ToString(1234)); try { //启动监听 - if (m_tcpIpServer.StartListen()) + if (_mTcpIpServer.StartListen()) { //绑定两个事件 OnRaisedStatus 和OnRaisedMessage - m_tcpIpServer.OnRaisedMessage += ReceiveMessage; - m_tcpIpServer.OnRaisedStatus += ReceiveStatus; + _mTcpIpServer.OnRaisedMessage += ReceiveMessage; + _mTcpIpServer.OnRaisedStatus += ReceiveStatus; DebugDfn.AddLogText("TCP服务端启动成功 "); } else @@ -93,259 +91,255 @@ namespace HexcalMC } catch (Exception ex) { - DebugDfn.AddLogText("启动TCP服务端异常" + ex.ToString()); + DebugDfn.AddLogText("启动TCP服务端异常" + ex); } } - private void ReceiveMessage(string ClientIP, string Msg) //接收的内容 + private void ReceiveMessage(string clientIp, string msg) //接收的内容 { //打印ClientIP 和 Msg - DebugDfn.AddLogText("接收到" + ClientIP + ": " + Msg); + DebugDfn.AddLogText("接收到" + clientIp + ": " + msg); //根据源地址的不同,执行不同处理 //如果 ClientIP 来自L2系统的话,执行解析 - switch (ClientIP) + switch (clientIp) { case "172.19.153.80": //L2系统 //解析处理数据 - ParseHexcalPacket(Msg); + ParseHexcalPacket(msg); break; + case "127.0.0.1": //模拟长宽系统 break; } } - private void ParseHexcalPacket(string Msg) //编写一个Hexcal协议解析函数 + private void ParseHexcalPacket(string msg) //编写一个Hexcal协议解析函数 { //根据不同的指令进行解析,3个层次,不合法,故障,最后是正常 //判断Msg的长度,如果不是指定长度,直接返回 - - if (Msg.Length != 8) return; + if (msg.Length != 8) return; //判断是否含有故障ERROR字样 - if (Msg.Contains("ERROR")) return; + if (msg.Contains("ERROR")) return; //指令解析 - string[] tokens = Msg.Split(','); + string[] tokens = msg.Split(','); foreach (string token in tokens) { Console.WriteLine(token); } //可能涉及到 将指令提取并单独处理的问题 - if (string.Equals("CMMTYP", Msg)) + if (string.Equals("CMMTYP", msg)) { SendMsgToHexcal("CMMTYP MA 19617, FDC V15.00, 6 6 2 , 0"); } - else if (string.Equals("VERSION", Msg)) //版本号 + else if (string.Equals("VERSION", msg)) //版本号 { SendMsgToHexcal("00-000-000-00000 FDC V51.04.0000 DATE: 12/21/22 TIME: 12:50:55"); } - else if (string.Equals("^B", Msg)) //查询状态 + else if (string.Equals("^B", msg)) //查询状态 { //todo 启动指令 } - else if (string.Equals("SHOW MAXSTROKESW", Msg)) //最大行程 + else if (string.Equals("SHOW MAXSTROKESW", msg)) //最大行程 { SendMsgToHexcal("MAXSTROKESW 233.200000,346.500000,15.100000,0.000000,0.000000,0.000000,0.000000"); } - else if (string.Equals("00000003", Msg)) //最小行程 + else if (string.Equals("00000003", msg)) //最小行程 { SendMsgToHexcal("MINSTROKESW -68.800000,-55.500000,-286.900000,0.000000,0.000000,0.000000,0.000000"); } - else if (string.Equals("SHOW MAXVEL", Msg)) //最大速度 + else if (string.Equals("SHOW MAXVEL", msg)) //最大速度 { SendMsgToHexcal("MAXVEL 300.000000,300.000000,300.000000,0.000000,0.000000,0.000000,0.000000,0.000000"); } - else if (string.Equals("SHOW MAXACC", Msg)) //最大加速度 + else if (string.Equals("SHOW MAXACC", msg)) //最大加速度 { SendMsgToHexcal( "MAXACC 300.000000,300.000000,300.000000,0.000000,0.000000,0.000000,0.000000,0.000000"); } - else if (string.Equals("SHOW TEMPCOMPTYPE", Msg)) //温度补偿,温度补偿 >1 表示支持温度补偿 + else if (string.Equals("SHOW TEMPCOMPTYPE", msg)) //温度补偿,温度补偿 >1 表示支持温度补偿 { SendMsgToHexcal("TEMPCOMPTYPE 1"); } - else if (string.Equals("READTP", Msg)) + else if (string.Equals("READTP", msg)) { SendMsgToHexcal("READTP 0.000000"); } - else if (string.Equals("SHOW SENSWKP", Msg)) + else if (string.Equals("SHOW SENSWKP", msg)) { SendMsgToHexcal("X_ SENSWKP 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"); } - else if (string.Equals("SHOW X_SENSAXIS", Msg)) + else if (string.Equals("SHOW X_SENSAXIS", msg)) { SendMsgToHexcal("X_SENSAXIS 6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"); } - else if (string.Equals("SHOW Y_SENSAXIS", Msg)) + else if (string.Equals("SHOW Y_SENSAXIS", msg)) { SendMsgToHexcal("Y_SENSAXIS 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"); } - else if (string.Equals("SHOW Z_SENSAXIS", Msg)) + else if (string.Equals("SHOW Z_SENSAXIS", msg)) { SendMsgToHexcal("Z_SENSAXIS 7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"); } - else if (string.Equals("SHOW MOVPAR", Msg)) //获取速度 + else if (string.Equals("SHOW MOVPAR", msg)) //获取速度 { SendMsgToHexcal( "MOVPAR 300.000000,300.000000,300.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.00000 0,0.000000"); } - else if (string.Equals("MOVPAR 300.0,300.0,300.0,0.0,0.0,0.0", Msg)) //设置速度 xyz 轴的速度 + else if (string.Equals("MOVPAR 300.0,300.0,300.0,0.0,0.0,0.0", msg)) //设置速度 xyz 轴的速度 { SendMsgToHexcal("%"); } - else if (string.Equals("SHOW MAXVEL", Msg)) + else if (string.Equals("SHOW MAXVEL", msg)) { SendMsgToHexcal("MAXVEL 300.000000,300.000000,300.000000,0.000000,0.000000,0.000000,0.000000,0.000000"); } - else if (string.Equals("SHOW ACCEL", Msg)) //获取加速 + else if (string.Equals("SHOW ACCEL", msg)) //获取加速 { SendMsgToHexcal( "ACCEL 1000.000000,1000.000000,1000.000000,0.000000,0.000000,0.000000,0.000000,0.000000"); } - else if (string.Equals("ACCEL 1000.0,1000.0,1000.0", Msg)) //设置加速度 + else if (string.Equals("ACCEL 1000.0,1000.0,1000.0", msg)) //设置加速度 { SendMsgToHexcal("%"); } else if (string.Equals( - "PRBPIN 0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000", - Msg)) + "PRBPIN 0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000", + msg)) { SendMsgToHexcal("%"); } - else if (string.Equals("ENABLE TEMP", Msg)) + else if (string.Equals("ENABLE TEMP", msg)) { SendMsgToHexcal(""); } - else if (string.Equals("WKPPAR 20,0.0000115,20", Msg)) + else if (string.Equals("WKPPAR 20,0.0000115,20", msg)) { SendMsgToHexcal(""); } - else if (string.Equals("SCLTMP", Msg)) + else if (string.Equals("SCLTMP", msg)) { SendMsgToHexcal(""); } - else if (string.Equals("MOVABS 167.553848,-55.400002,-208.548203,0.000000", Msg)) //移动指令 + else if (string.Equals("MOVABS 167.553848,-55.400002,-208.548203,0.000000", msg)) //移动指令 { SendMsgToHexcal("%"); } - else if (string.Equals("GETPOS", Msg)) //获取位置 + else if (string.Equals("GETPOS", msg)) //获取位置 { SendMsgToHexcal("POS 167.553898,-55.400421,-208.548678,0.000000,0.000000,0.000000,0.000000"); } - else if (string.Equals("SHOW ESTOP", Msg)) + else if (string.Equals("SHOW ESTOP", msg)) { SendMsgToHexcal("ESTOP FALSE"); } - else if (string.Equals("", Msg)) + else if (string.Equals("", msg)) { } - else - { - //todo 未知指令 - } + //todo 未知指令 } - private void ReceiveStatus(TcpIpServer.EnumTcpIpServer iType, string Msg) + private void ReceiveStatus(TcpIpServer.EnumTcpIpServer iType, string msg) { //记录到日志 - DebugDfn.AddLogText(iType + " : " + Msg); + DebugDfn.AddLogText(iType + " : " + msg); } - private void SendMsgToHexcal(string Msg) + private void SendMsgToHexcal(string msg) { //发送数据 - m_tcpIpServer.SendMessageToAllClients(Msg); + _mTcpIpServer.SendMessageToAllClients(msg); } - #endregion + #endregion hexcal软件相关 #region ACS平台相关 private void btnEnable_Click(object sender, EventArgs e) //使能所有轴 { - Axis[] AxisList = new Axis[] + Axis[] axisList = { Axis.ACSC_AXIS_0, Axis.ACSC_AXIS_1, Axis.ACSC_AXIS_4, Axis.ACSC_NONE }; //!!!! Important !! Must insert '-1' at the last - _ACS.EnableM(AxisList); + _acs.EnableM(axisList); } private void btnDisable_Click(object sender, EventArgs e) //轴取消 { // Disable all of axes - _ACS.DisableAll(); + _acs.DisableAll(); } private void tmrMonitor_Tick(object sender, EventArgs e) //用于刷新状态 { int iAxisNo = cboAxisNo.SelectedIndex; - if (m_bConnected) + if (_mBConnected) { try { - // Instruction 1. Using library functions - acsc_GetFPosition, acsc_GetRPosition, .... - // Instruction 2. Read ACS variable - Already defined almost things (FPOS, RPOS, ...) - // Motion parameters and state is array (Max length is total number of axes) + // Instruction 1. Using library functions - acsc_GetFPosition, + // acsc_GetRPosition, .... Instruction 2. Read ACS variable - Already defined + // almost things (FPOS, RPOS, ...) Motion parameters and state is array (Max + // length is total number of axes) // - // * Library function can read only 1 axis information, so if you want to read several axes, you have to call the function many times. - // (This may cause communication delay.) - // Recommand (if you want to read many axes) : read/write variable using ReadVariable, ReadVariableScalar, ReadVariableVector, ReadVariableMatrix + // * Library function can read only 1 axis information, so if you want to read + // several axes, you have to call the function many times. (This may cause + // communication delay.) Recommand (if you want to read many axes) : read/write + // variable using ReadVariable, ReadVariableScalar, ReadVariableVector, ReadVariableMatrix - // - // Get Motor State - // ACSPL+ Variable : MST (integer) - m_nMotorState = _ACS.GetMotorState((Axis)iAxisNo); + // Get Motor State ACSPL+ Variable : MST (integer) + _mNMotorState = _acs.GetMotorState((Axis)iAxisNo); - // Returned value is integer, you need to use bitmaks - if ((m_nMotorState & MotorStates.ACSC_MST_MOVE) != 0) lblMoving.Image = Properties.Resources.On; - else lblMoving.Image = Properties.Resources.Off; // 运动中 - if ((m_nMotorState & MotorStates.ACSC_MST_INPOS) != 0) lblInPos.Image = Properties.Resources.On; - else lblInPos.Image = Properties.Resources.Off; // 就位 - if ((m_nMotorState & MotorStates.ACSC_MST_ACC) != 0) lblAcc.Image = Properties.Resources.On; - else lblAcc.Image = Properties.Resources.Off; // 加速 - if ((m_nMotorState & MotorStates.ACSC_MST_ENABLE) != 0) lblEnable.Image = Properties.Resources.On; - else lblEnable.Image = Properties.Resources.Off; // 使能 + // Returned value is integer, you need to use bitmaks + if ((_mNMotorState & MotorStates.ACSC_MST_MOVE) != 0) lblMoving.Image = Resources.On; + else lblMoving.Image = Resources.Off; // 运动中 + if ((_mNMotorState & MotorStates.ACSC_MST_INPOS) != 0) lblInPos.Image = Resources.On; + else lblInPos.Image = Resources.Off; // 就位 + if ((_mNMotorState & MotorStates.ACSC_MST_ACC) != 0) lblAcc.Image = Resources.On; + else lblAcc.Image = Resources.Off; // 加速 + if ((_mNMotorState & MotorStates.ACSC_MST_ENABLE) != 0) lblEnable.Image = Resources.On; + else lblEnable.Image = Resources.Off; // 使能 - // Reference position - // ACSPL+ Variable : RPOS (real) - m_lfRPos = _ACS.GetRPosition((Axis)iAxisNo); // 参考位置 + // Reference position ACSPL+ Variable : RPOS (real) + _mLfRPos = _acs.GetRPosition((Axis)iAxisNo); // 参考位置 - // Feedback position (Encoder value) - // ACSPL+ Variable : FPO (real) - m_lfFPos = _ACS.GetFPosition((Axis)iAxisNo); //反馈位置 + // Feedback position (Encoder value) ACSPL+ Variable : FPO (real) + _mLfFPos = _acs.GetFPosition((Axis)iAxisNo); //反馈位置 - // PE (Position Error) - // There is no function in library. We need to use ReadVariable function - m_lfPE = (double)_ACS.ReadVariable("PE", ProgramBuffer.ACSC_NONE, iAxisNo, iAxisNo); //位置误差 + // PE (Position Error) There is no function in library. We need to use + // ReadVariable function + _mLfPe = (double)_acs.ReadVariable("PE", ProgramBuffer.ACSC_NONE, iAxisNo, iAxisNo); //位置误差 // Feedback Velocity - m_lfFVEL = (double)_ACS.ReadVariable("FVEL", ProgramBuffer.ACSC_NONE, iAxisNo, iAxisNo); //实际速度 + _mLfFvel = (double)_acs.ReadVariable("FVEL", ProgramBuffer.ACSC_NONE, iAxisNo, iAxisNo); //实际速度 // txtRPOS.Text = String.Format("{0:0.0000}", m_lfRPos); //参考位置 - rtb_xPos.Text = String.Format("{0:0.0000}", m_lfFPos); //反馈位置 - // txtPE.Text = String.Format("{0:0.0000}", m_lfPE); //实际速度 - // txtFVEL.Text = String.Format("{0:0.0000}", m_lfFVEL);//位置误差 + rtb_xPos.Text = string.Format("{0:0.0000}", _mLfFPos); //反馈位置 + // txtPE.Text = + // String.Format("{0:0.0000}", + // m_lfPE); //实际速度 + // txtFVEL.Text = + // String.Format("{0:0.0000}", m_lfFVEL);//位置误差 - - // Read left/right hardware limits state - // ACSPL+ Variable : FAULT (integer) - m_objReadVar = - _ACS.ReadVariableAsVector("FAULT", ProgramBuffer.ACSC_NONE, 0, m_nTotalAxis - 1, -1, -1); - if (m_objReadVar != null) + // Read left/right hardware limits state ACSPL+ Variable : FAULT (integer) + _mObjReadVar = + _acs.ReadVariableAsVector("FAULT", ProgramBuffer.ACSC_NONE, 0, _mNTotalAxis - 1); + if (_mObjReadVar != null) { - m_arrReadVector = m_objReadVar as Array; - if (m_arrReadVector != null) + _mArrReadVector = _mObjReadVar as Array; + if (_mArrReadVector != null) { - for (int i = 0; i < m_nTotalAxis; i++) + for (int i = 0; i < _mNTotalAxis; i++) { - UpdateLimitState(i, (int)m_arrReadVector.GetValue(i)); + UpdateLimitState(i, (int)_mArrReadVector.GetValue(i)); } } } @@ -353,18 +347,16 @@ namespace HexcalMC catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); - System.Diagnostics.Debug.WriteLine(ex.Message); + Debug.WriteLine(ex.Message); } } } - private void btn_ACSStart_Click(object sender, EventArgs e) //连接 { btn_ACSStart.Enabled = false; btn_ACSStop.Enabled = true; - // Set updating timer tmrMonitor.Interval = 50; tmrMonitor.Start(); @@ -372,7 +364,7 @@ namespace HexcalMC private void btn_ACSStop_Click(object sender, EventArgs e) //断开连接 { - if (m_bConnected) _ACS.CloseComm(); + if (_mBConnected) _acs.CloseComm(); tmrMonitor.Stop(); @@ -385,20 +377,24 @@ namespace HexcalMC timer_RefreshUI.Stop(); } + private void btn_HexcalStart_Click(object sender, EventArgs e) + { + } + private void UpdateLimitState(int axisNo, int fault) //刷新限位 { - if (axisNo < MAX_UI_LIMIT_CNT) + if (axisNo < MaxUiLimitCnt) { if ((fault & (int)SafetyControlMasks.ACSC_SAFETY_LL) != 0) - m_lblLeftLimit[axisNo].Image = Properties.Resources.Error; - else m_lblLeftLimit[axisNo].Image = Properties.Resources.Off; + _mLblLeftLimit[axisNo].Image = Resources.Error; + else _mLblLeftLimit[axisNo].Image = Resources.Off; if ((fault & (int)SafetyControlMasks.ACSC_SAFETY_RL) != 0) - m_lblRightLimit[axisNo].Image = Properties.Resources.Error; - else m_lblRightLimit[axisNo].Image = Properties.Resources.Off; + _mLblRightLimit[axisNo].Image = Resources.Error; + else _mLblRightLimit[axisNo].Image = Resources.Off; } } - #endregion + #endregion ACS平台相关 #region 菜单栏 @@ -418,14 +414,14 @@ namespace HexcalMC private void timer_RefreshUI_Tick(object sender, EventArgs e) //UI刷新 { //状态灯刷新 - lamp_acs.State = m_bConnected ? LampColor.Green : LampColor.Silver; - lamp_hexcal.State = m_bHexcalConnected ? LampColor.Green : LampColor.Silver; + lamp_acs.State = _mBConnected ? LampColor.Green : LampColor.Silver; + lamp_hexcal.State = _mBHexcalConnected ? LampColor.Green : LampColor.Silver; - //时间栏 + //时间栏 //获取当前时间,构造形如 精确到秒,例如 2023-10-08 16:01:23 rle_timer.Text = "当前时间: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } - #endregion + #endregion 菜单栏 } } \ No newline at end of file diff --git a/HexcalMC/Motion/Motion.Designer.cs b/HexcalMC/Motion/Motion.Designer.cs index c5f2c90..7deaab5 100644 --- a/HexcalMC/Motion/Motion.Designer.cs +++ b/HexcalMC/Motion/Motion.Designer.cs @@ -271,7 +271,7 @@ this.btnClose.TabIndex = 14; this.btnClose.Text = "断开"; this.btnClose.UseVisualStyleBackColor = true; - this.btnClose.Click += new System.EventHandler(this.btnClose_Click); + this.btnClose.Click += new System.EventHandler(this.BtnClose_Click); // // btnOpen // @@ -281,7 +281,7 @@ this.btnOpen.TabIndex = 13; this.btnOpen.Text = "连接"; this.btnOpen.UseVisualStyleBackColor = true; - this.btnOpen.Click += new System.EventHandler(this.btnOpen_Click); + this.btnOpen.Click += new System.EventHandler(this.BtnOpen_Click); // // label2 // @@ -311,7 +311,7 @@ this.rdoTCP.TabStop = true; this.rdoTCP.Text = "TCP"; this.rdoTCP.UseVisualStyleBackColor = true; - this.rdoTCP.CheckedChanged += new System.EventHandler(this.rdoTCP_CheckedChanged); + this.rdoTCP.CheckedChanged += new System.EventHandler(this.RdoTCP_CheckedChanged); // // rdoSimu // @@ -323,12 +323,12 @@ this.rdoSimu.TabStop = true; this.rdoSimu.Text = "模拟器"; this.rdoSimu.UseVisualStyleBackColor = true; - this.rdoSimu.CheckedChanged += new System.EventHandler(this.rdoSimu_CheckedChanged); + this.rdoSimu.CheckedChanged += new System.EventHandler(this.RdoSimu_CheckedChanged); // // tmrMonitor // this.tmrMonitor.Interval = 50; - this.tmrMonitor.Tick += new System.EventHandler(this.tmrMonitor_Tick); + this.tmrMonitor.Tick += new System.EventHandler(this.TmrMonitor_Tick); // // grpMotionTest // @@ -359,7 +359,7 @@ this.btnHallAll.TabIndex = 10; this.btnHallAll.Text = "停止全部"; this.btnHallAll.UseVisualStyleBackColor = true; - this.btnHallAll.Click += new System.EventHandler(this.btnHallAll_Click); + this.btnHallAll.Click += new System.EventHandler(this.BtnHallAll_Click); // // btnHalt // @@ -369,7 +369,7 @@ this.btnHalt.TabIndex = 10; this.btnHalt.Text = "停止"; this.btnHalt.UseVisualStyleBackColor = true; - this.btnHalt.Click += new System.EventHandler(this.btnHalt_Click); + this.btnHalt.Click += new System.EventHandler(this.BtnHalt_Click); // // grpMst // @@ -482,7 +482,7 @@ this.btnSetZero.TabIndex = 7; this.btnSetZero.Text = "设置零位"; this.btnSetZero.UseVisualStyleBackColor = true; - this.btnSetZero.Click += new System.EventHandler(this.btnSetZero_Click); + this.btnSetZero.Click += new System.EventHandler(this.BtnSetZero_Click); // // txtFVEL // @@ -568,7 +568,7 @@ this.btnDisableAll.TabIndex = 7; this.btnDisableAll.Text = "取消全部"; this.btnDisableAll.UseVisualStyleBackColor = true; - this.btnDisableAll.Click += new System.EventHandler(this.btnDisableAll_Click); + this.btnDisableAll.Click += new System.EventHandler(this.BtnDisableAll_Click); // // btnDisable // @@ -578,7 +578,7 @@ this.btnDisable.TabIndex = 7; this.btnDisable.Text = "单轴取消"; this.btnDisable.UseVisualStyleBackColor = true; - this.btnDisable.Click += new System.EventHandler(this.btnDisable_Click); + this.btnDisable.Click += new System.EventHandler(this.BtnDisable_Click); // // cboAxisNo // @@ -588,7 +588,7 @@ this.cboAxisNo.Name = "cboAxisNo"; this.cboAxisNo.Size = new System.Drawing.Size(60, 20); this.cboAxisNo.TabIndex = 0; - this.cboAxisNo.SelectedIndexChanged += new System.EventHandler(this.cboAxisNo_SelectedIndexChanged); + this.cboAxisNo.SelectedIndexChanged += new System.EventHandler(this.CboAxisNo_SelectedIndexChanged); // // btnEnable // @@ -598,7 +598,7 @@ this.btnEnable.TabIndex = 7; this.btnEnable.Text = "单轴使能"; this.btnEnable.UseVisualStyleBackColor = true; - this.btnEnable.Click += new System.EventHandler(this.btnEnable_Click); + this.btnEnable.Click += new System.EventHandler(this.BtnEnable_Click); // // grpJog // @@ -621,8 +621,8 @@ this.btnJogPos.TabIndex = 8; this.btnJogPos.Text = "正向 >>"; this.btnJogPos.UseVisualStyleBackColor = true; - this.btnJogPos.MouseDown += new System.Windows.Forms.MouseEventHandler(this.btnJogPos_MouseDown); - this.btnJogPos.MouseUp += new System.Windows.Forms.MouseEventHandler(this.btnJog_MouseUp); + this.btnJogPos.MouseDown += new System.Windows.Forms.MouseEventHandler(this.BtnJogPos_MouseDown); + this.btnJogPos.MouseUp += new System.Windows.Forms.MouseEventHandler(this.BtnJog_MouseUp); // // btnJogNeg // @@ -632,8 +632,8 @@ this.btnJogNeg.TabIndex = 8; this.btnJogNeg.Text = "<< 负向"; this.btnJogNeg.UseVisualStyleBackColor = true; - this.btnJogNeg.MouseDown += new System.Windows.Forms.MouseEventHandler(this.btnJogNeg_MouseDown); - this.btnJogNeg.MouseUp += new System.Windows.Forms.MouseEventHandler(this.btnJog_MouseUp); + this.btnJogNeg.MouseDown += new System.Windows.Forms.MouseEventHandler(this.BtnJogNeg_MouseDown); + this.btnJogNeg.MouseUp += new System.Windows.Forms.MouseEventHandler(this.BtnJog_MouseUp); // // txtJogVel // @@ -800,7 +800,7 @@ this.btnPTP_R_Pos.TabIndex = 7; this.btnPTP_R_Pos.Text = "相对位置 (+)"; this.btnPTP_R_Pos.UseVisualStyleBackColor = true; - this.btnPTP_R_Pos.Click += new System.EventHandler(this.btnPTP_R_Pos_Click); + this.btnPTP_R_Pos.Click += new System.EventHandler(this.BtnPTP_R_Pos_Click); // // btnPTP_R_Neg // @@ -810,7 +810,7 @@ this.btnPTP_R_Neg.TabIndex = 7; this.btnPTP_R_Neg.Text = "相对位置 (-)"; this.btnPTP_R_Neg.UseVisualStyleBackColor = true; - this.btnPTP_R_Neg.Click += new System.EventHandler(this.btnPTP_R_Neg_Click); + this.btnPTP_R_Neg.Click += new System.EventHandler(this.BtnPTP_R_Neg_Click); // // btnPTP // @@ -820,7 +820,7 @@ this.btnPTP.TabIndex = 7; this.btnPTP.Text = "移动到绝对位置"; this.btnPTP.UseVisualStyleBackColor = true; - this.btnPTP.Click += new System.EventHandler(this.btnPTP_Click); + this.btnPTP.Click += new System.EventHandler(this.BtnPTP_Click); // // txtPTP_Pos // @@ -1191,7 +1191,7 @@ this.btnStopBuffer.TabIndex = 8; this.btnStopBuffer.Text = "停止"; this.btnStopBuffer.UseVisualStyleBackColor = true; - this.btnStopBuffer.Click += new System.EventHandler(this.btnStopBuffer_Click); + this.btnStopBuffer.Click += new System.EventHandler(this.BtnStopBuffer_Click); // // btnRunBuffer // @@ -1201,7 +1201,7 @@ this.btnRunBuffer.TabIndex = 8; this.btnRunBuffer.Text = "启动"; this.btnRunBuffer.UseVisualStyleBackColor = true; - this.btnRunBuffer.Click += new System.EventHandler(this.btnRunBuffer_Click); + this.btnRunBuffer.Click += new System.EventHandler(this.BtnRunBuffer_Click); // // txtLabelName // @@ -1308,7 +1308,7 @@ this.btnSW7.TabIndex = 7; this.btnSW7.Text = "OFF"; this.btnSW7.UseVisualStyleBackColor = true; - this.btnSW7.Click += new System.EventHandler(this.btnSW_Click); + this.btnSW7.Click += new System.EventHandler(this.BtnSW_Click); // // btnSW6 // @@ -1319,7 +1319,7 @@ this.btnSW6.TabIndex = 6; this.btnSW6.Text = "OFF"; this.btnSW6.UseVisualStyleBackColor = true; - this.btnSW6.Click += new System.EventHandler(this.btnSW_Click); + this.btnSW6.Click += new System.EventHandler(this.BtnSW_Click); // // btnSW5 // @@ -1330,7 +1330,7 @@ this.btnSW5.TabIndex = 5; this.btnSW5.Text = "OFF"; this.btnSW5.UseVisualStyleBackColor = true; - this.btnSW5.Click += new System.EventHandler(this.btnSW_Click); + this.btnSW5.Click += new System.EventHandler(this.BtnSW_Click); // // btnSW4 // @@ -1341,7 +1341,7 @@ this.btnSW4.TabIndex = 4; this.btnSW4.Text = "OFF"; this.btnSW4.UseVisualStyleBackColor = true; - this.btnSW4.Click += new System.EventHandler(this.btnSW_Click); + this.btnSW4.Click += new System.EventHandler(this.BtnSW_Click); // // btnSW3 // @@ -1352,7 +1352,7 @@ this.btnSW3.TabIndex = 3; this.btnSW3.Text = "OFF"; this.btnSW3.UseVisualStyleBackColor = true; - this.btnSW3.Click += new System.EventHandler(this.btnSW_Click); + this.btnSW3.Click += new System.EventHandler(this.BtnSW_Click); // // btnSW2 // @@ -1363,7 +1363,7 @@ this.btnSW2.TabIndex = 2; this.btnSW2.Text = "OFF"; this.btnSW2.UseVisualStyleBackColor = true; - this.btnSW2.Click += new System.EventHandler(this.btnSW_Click); + this.btnSW2.Click += new System.EventHandler(this.BtnSW_Click); // // btnSW0 // @@ -1374,7 +1374,7 @@ this.btnSW0.TabIndex = 0; this.btnSW0.Text = "OFF"; this.btnSW0.UseVisualStyleBackColor = true; - this.btnSW0.Click += new System.EventHandler(this.btnSW_Click); + this.btnSW0.Click += new System.EventHandler(this.BtnSW_Click); // // btnSW1 // @@ -1385,7 +1385,7 @@ this.btnSW1.TabIndex = 1; this.btnSW1.Text = "OFF"; this.btnSW1.UseVisualStyleBackColor = true; - this.btnSW1.Click += new System.EventHandler(this.btnSW_Click); + this.btnSW1.Click += new System.EventHandler(this.BtnSW_Click); // // label29 // @@ -1650,7 +1650,7 @@ this.btnEventProgramEnd.TabIndex = 0; this.btnEventProgramEnd.Text = "程序结束"; this.btnEventProgramEnd.UseVisualStyleBackColor = true; - this.btnEventProgramEnd.Click += new System.EventHandler(this.btnEventProgramEnd_Click); + this.btnEventProgramEnd.Click += new System.EventHandler(this.BtnEventProgramEnd_Click); // // btnEventMotionEnd // @@ -1660,7 +1660,7 @@ this.btnEventMotionEnd.TabIndex = 0; this.btnEventMotionEnd.Text = "运动结束"; this.btnEventMotionEnd.UseVisualStyleBackColor = true; - this.btnEventMotionEnd.Click += new System.EventHandler(this.btnEventMotionEnd_Click); + this.btnEventMotionEnd.Click += new System.EventHandler(this.BtnEventMotionEnd_Click); // // rtxtTerminal // @@ -1690,7 +1690,7 @@ this.btnSend.TabIndex = 8; this.btnSend.Text = "发送"; this.btnSend.UseVisualStyleBackColor = true; - this.btnSend.Click += new System.EventHandler(this.btnSend_Click); + this.btnSend.Click += new System.EventHandler(this.BtnSend_Click); // // txtCommand // @@ -1698,7 +1698,7 @@ this.txtCommand.Name = "txtCommand"; this.txtCommand.Size = new System.Drawing.Size(769, 21); this.txtCommand.TabIndex = 7; - this.txtCommand.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtCommand_KeyPress); + this.txtCommand.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TxtCommand_KeyPress); // // groupBox5 // diff --git a/HexcalMC/Motion/Motion.cs b/HexcalMC/Motion/Motion.cs index 78328af..6cf3bf2 100644 --- a/HexcalMC/Motion/Motion.cs +++ b/HexcalMC/Motion/Motion.cs @@ -1,59 +1,130 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; -using System.Threading; -using System.IO; -using ACS.SPiiPlusNET; // ACS .NET Library +using System.Diagnostics; using System.Runtime.InteropServices; +using System.Windows.Forms; +using ACS.SPiiPlusNET; +using HexcalMC.Properties; +// ACS .NET Library namespace HexcalMC { public partial class Motion : System.Windows.Forms.Form { - private Api _ACS; + private const int MaxAxisCount = 32; + private const int MaxBufferCnt = 64; - private const int MAX_AXIS_COUNT = 32; - private const int MAX_BUFFER_CNT = 64; + private const int MaxUiLimitCnt = 8; + private const int MaxUiIoCnt = 8; + private readonly Api _acs; + private Axis[] _mArrAxisList; + private Array _mArrReadVector; - private const int MAX_UI_LIMIT_CNT = 8; - private const int MAX_UI_IO_CNT = 8; + private bool _mBConnected; + private Button[] _mBtnOutput; + private Label[] _mLblInput; - private int m_nTotalAxis = 0; - private int m_nTotalBuffer = 0; - private Axis[] m_arrAxisList = null; - private bool m_bConnected = false; + private Label[] _mLblLeftLimit; //左限位 + private Label[] _mLblOutput; + private Label[] _mLblRightLimit; //右限位 + private double _mLfRPos, _mLfFPos, _mLfPe, _mLfFvel; //参考位置,反馈位置 位置误差 反馈速度 double类型 // For update values - private MotorStates m_nMotorState; //运动状态 - private ProgramStates m_nProgramState; //程序状态 - private object m_objReadVar = null; - private Array m_arrReadVector = null; - private double m_lfRPos, m_lfFPos, m_lfPE, m_lfFVEL; //参考位置,反馈位置 位置误差 反馈速度 double类型 - private int m_nValues, m_nOutputState; + private MotorStates _mNMotorState; //运动状态 + private ProgramStates _mNProgramState; //程序状态 - - private Label[] m_lblLeftLimit; //左限位 - private Label[] m_lblRightLimit; //右限位 - private Label[] m_lblInput; - private Label[] m_lblOutput; - private Button[] m_btnOutput; + private int _mNTotalAxis; + private int _mNTotalBuffer; + private int _mNValues, _mNOutputState; + private object _mObjReadVar; public Motion() { InitializeComponent(); - _ACS = new Api(); //初始化 ACS运动控制类 + _acs = new Api(); //初始化 ACS运动控制类 // Register Event 注册时间 - _ACS.PHYSICALMOTIONEND += _ACS_PHYSICALMOTIONEND; - _ACS.PROGRAMEND += _ACS_PROGRAMEND; + _acs.PHYSICALMOTIONEND += ACS_PHYSICALMOTIONEND; + _acs.PROGRAMEND += ACS_PROGRAMEND; } + private void BtnSetZero_Click(object sender, EventArgs e) + { + // Change current poisition as you want + // SetFPosition(Axis number, new position) + _acs.SetFPosition((Axis)cboAxisNo.SelectedIndex, 0); + } + + #region Move to absolute position + + private void BtnPTP_Click(object sender, EventArgs e) + { + double lfTargetPos = 0.0f; + try + { + if (txtPTP_Pos.Text.Length > 0) + { + lfTargetPos = Convert.ToDouble(txtPTP_Pos.Text); + _acs.ToPoint( + 0, // '0' - Absolute position + (Axis)cboAxisNo.SelectedIndex, // Axis number + lfTargetPos // Target position + ); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); + Debug.WriteLine(ex.Message); + } + } + + #endregion + + #region On and Off General Output + + private void BtnSW_Click(object sender, EventArgs e) + { + int nBitNo = 0x01; + + try + { + Button btn = sender as Button; + if (btn == null) return; + + nBitNo = btn.TabIndex; + nBitNo = 0x01 << nBitNo; //左移几位 + + if ((_mNOutputState & nBitNo) != 0) + { + // Set only 1 bit + _acs.SetOutput( + 0, // Port number + btn.TabIndex, // Bit number + 0 // 0 = OFF, 1 = ON + ); + + // If your I/O device is EtherCAT type, you cannot use this function + // You can use WriteVariable function and Command function + // + // Ex) If EtherCAT mapped variable is 'EC_DOUT' + // Want to ON bit '3' + // _ACS.Command("EC_DOUT.3=1"); + } + else + { + _acs.SetOutput(0, btn.TabIndex, 1); + } + } + catch (Exception ex) + { + Debug.WriteLine("btnSW_Click() Error\n" + ex); + } + } + + #endregion + #region Initialize private void Form1_Load(object sender, EventArgs e) @@ -62,64 +133,65 @@ namespace HexcalMC btnOpen.Enabled = true; btnClose.Enabled = false; - m_lblLeftLimit = new Label[MAX_UI_LIMIT_CNT]; //左限位 - m_lblLeftLimit[0] = lblLL0; - m_lblLeftLimit[1] = lblLL1; - m_lblLeftLimit[2] = lblLL2; - m_lblLeftLimit[3] = lblLL3; - m_lblLeftLimit[4] = lblLL4; - m_lblLeftLimit[5] = lblLL5; - m_lblLeftLimit[6] = lblLL6; - m_lblLeftLimit[7] = lblLL7; + _mLblLeftLimit = new Label[MaxUiLimitCnt]; //左限位 + _mLblLeftLimit[0] = lblLL0; + _mLblLeftLimit[1] = lblLL1; + _mLblLeftLimit[2] = lblLL2; + _mLblLeftLimit[3] = lblLL3; + _mLblLeftLimit[4] = lblLL4; + _mLblLeftLimit[5] = lblLL5; + _mLblLeftLimit[6] = lblLL6; + _mLblLeftLimit[7] = lblLL7; - m_lblRightLimit = new Label[MAX_UI_LIMIT_CNT]; //有限位 - m_lblRightLimit[0] = lblRL0; - m_lblRightLimit[1] = lblRL1; - m_lblRightLimit[2] = lblRL2; - m_lblRightLimit[3] = lblRL3; - m_lblRightLimit[4] = lblRL4; - m_lblRightLimit[5] = lblRL5; - m_lblRightLimit[6] = lblRL6; - m_lblRightLimit[7] = lblRL7; + _mLblRightLimit = new Label[MaxUiLimitCnt]; //有限位 + _mLblRightLimit[0] = lblRL0; + _mLblRightLimit[1] = lblRL1; + _mLblRightLimit[2] = lblRL2; + _mLblRightLimit[3] = lblRL3; + _mLblRightLimit[4] = lblRL4; + _mLblRightLimit[5] = lblRL5; + _mLblRightLimit[6] = lblRL6; + _mLblRightLimit[7] = lblRL7; - m_lblInput = new Label[MAX_UI_IO_CNT]; - m_lblInput[0] = lblIN0; - m_lblInput[1] = lblIN1; - m_lblInput[2] = lblIN2; - m_lblInput[3] = lblIN3; - m_lblInput[4] = lblIN4; - m_lblInput[5] = lblIN5; - m_lblInput[6] = lblIN6; - m_lblInput[7] = lblIN7; + _mLblInput = new Label[MaxUiIoCnt]; + _mLblInput[0] = lblIN0; + _mLblInput[1] = lblIN1; + _mLblInput[2] = lblIN2; + _mLblInput[3] = lblIN3; + _mLblInput[4] = lblIN4; + _mLblInput[5] = lblIN5; + _mLblInput[6] = lblIN6; + _mLblInput[7] = lblIN7; - m_lblOutput = new Label[MAX_UI_IO_CNT]; - m_lblOutput[0] = lblOUT0; - m_lblOutput[1] = lblOUT1; - m_lblOutput[2] = lblOUT2; - m_lblOutput[3] = lblOUT3; - m_lblOutput[4] = lblOUT4; - m_lblOutput[5] = lblOUT5; - m_lblOutput[6] = lblOUT6; - m_lblOutput[7] = lblOUT7; + _mLblOutput = new Label[MaxUiIoCnt]; + _mLblOutput[0] = lblOUT0; + _mLblOutput[1] = lblOUT1; + _mLblOutput[2] = lblOUT2; + _mLblOutput[3] = lblOUT3; + _mLblOutput[4] = lblOUT4; + _mLblOutput[5] = lblOUT5; + _mLblOutput[6] = lblOUT6; + _mLblOutput[7] = lblOUT7; - m_btnOutput = new Button[MAX_UI_IO_CNT]; - m_btnOutput[0] = btnSW0; - m_btnOutput[1] = btnSW1; - m_btnOutput[2] = btnSW2; - m_btnOutput[3] = btnSW3; - m_btnOutput[4] = btnSW4; - m_btnOutput[5] = btnSW5; - m_btnOutput[6] = btnSW6; - m_btnOutput[7] = btnSW7; + _mBtnOutput = new Button[MaxUiIoCnt]; + _mBtnOutput[0] = btnSW0; + _mBtnOutput[1] = btnSW1; + _mBtnOutput[2] = btnSW2; + _mBtnOutput[3] = btnSW3; + _mBtnOutput[4] = btnSW4; + _mBtnOutput[5] = btnSW5; + _mBtnOutput[6] = btnSW6; + _mBtnOutput[7] = btnSW7; //m_nFault = new int[MAX_AXIS_COUNT]; //Array.Clear(m_nFault, 0, MAX_AXIS_COUNT); - m_nOutputState = 0; + _mNOutputState = 0; // Clear connection list from SPiiPlus UserMode-Driver (UMD) //TernminateUMD_Connection(); #region 副屏显示功能 + // Screen[] screens = Screen.AllScreens; // Screen secondaryScreen = screens.Length > 1 ? screens[1] : screens[0]; // 如果有多个屏幕,选择第二个屏幕作为副屏幕 // @@ -138,18 +210,16 @@ namespace HexcalMC // // 显示副屏窗体 // secondaryForm.Show(); - #endregion - } - private void rdoTCP_CheckedChanged(object sender, EventArgs e) + private void RdoTCP_CheckedChanged(object sender, EventArgs e) { txtIP.Enabled = true; txtPort.Enabled = true; } - private void rdoSimu_CheckedChanged(object sender, EventArgs e) + private void RdoSimu_CheckedChanged(object sender, EventArgs e) { txtIP.Enabled = false; txtPort.Enabled = false; @@ -159,7 +229,7 @@ namespace HexcalMC #region Communication - Open / Close - private void btnOpen_Click(object sender, EventArgs e) + private void BtnOpen_Click(object sender, EventArgs e) { string strTemp; int i; @@ -170,45 +240,45 @@ namespace HexcalMC if (rdoTCP.Checked) { // TCP/IP (Ethernet) - _ACS.OpenCommEthernetTCP( + _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(); + _acs.OpenCommSimulator(); } - m_bConnected = true; + _mBConnected = true; // Get Total number of axes // Using Transaction function : return string text from controller, we need to convert to integer value - strTemp = _ACS.Transaction("?SYSINFO(13)"); - m_nTotalAxis = Convert.ToInt32(strTemp.Trim()); + strTemp = _acs.Transaction("?SYSINFO(13)"); + _mNTotalAxis = Convert.ToInt32(strTemp.Trim()); // Using Sysinfo function //_ACS.GetSysInfo(_ACS.ACSC_SYS_NAXES_KEY, out lfTemp); // 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) - m_arrAxisList = new Axis[m_nTotalAxis + 1]; - for (i = 0; i < m_nTotalAxis; i++) + _mArrAxisList = new Axis[_mNTotalAxis + 1]; + for (i = 0; i < _mNTotalAxis; i++) { cboAxisNo.Items.Add(i.ToString()); - m_arrAxisList[i] = (Axis)i; + _mArrAxisList[i] = (Axis)i; } // Insert '-1' at the last - m_arrAxisList[m_nTotalAxis] = Axis.ACSC_NONE; + _mArrAxisList[_mNTotalAxis] = Axis.ACSC_NONE; cboAxisNo.SelectedIndex = 0; // Update current motion paramter to UI. UpdateProfile(); - strTemp = _ACS.Transaction("?SYSINFO(10)"); - m_nTotalBuffer = Convert.ToInt32(strTemp.Trim()); - for (i = 0; i < m_nTotalBuffer; i++) + strTemp = _acs.Transaction("?SYSINFO(10)"); + _mNTotalBuffer = Convert.ToInt32(strTemp.Trim()); + for (i = 0; i < _mNTotalBuffer; i++) { cboBufferNo.Items.Add(i.ToString()); } @@ -226,22 +296,21 @@ namespace HexcalMC catch (COMException comex) { MessageBox.Show("Connection fail", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - System.Diagnostics.Debug.WriteLine("Connection fail" + comex.Message); + Debug.WriteLine("Connection fail" + comex.Message); - m_bConnected = false; - return; + _mBConnected = false; } catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); - System.Diagnostics.Debug.WriteLine(ex.Message); + Debug.WriteLine(ex.Message); } } - private void btnClose_Click(object sender, EventArgs e) + private void BtnClose_Click(object sender, EventArgs e) { - if (m_bConnected) _ACS.CloseComm(); + if (_mBConnected) _acs.CloseComm(); tmrMonitor.Stop(); @@ -251,9 +320,9 @@ namespace HexcalMC /// - /// Terminate connections from SPiiPlus User Mode Driver - /// 终止来自 SPiiPlus 用户模式驱动程序的连接 - /// - Maximum connections up to 10 in UMD + /// Terminate connections from SPiiPlus User Mode Driver + /// 终止来自 SPiiPlus 用户模式驱动程序的连接 + /// - Maximum connections up to 10 in UMD /// private void TernminateUMD_Connection() { @@ -261,16 +330,16 @@ namespace HexcalMC { string terminateExceptionConnName = "ACS.Framework.exe"; - ACSC_CONNECTION_DESC[] connectionList = _ACS.GetConnectionsList(); + ACSC_CONNECTION_DESC[] connectionList = _acs.GetConnectionsList(); for (int index = 0; index < connectionList.Length; index++) { - if (terminateExceptionConnName.CompareTo((string)connectionList[index].Application) != 0) - _ACS.TerminateConnection(connectionList[index]); + if (terminateExceptionConnName.CompareTo(connectionList[index].Application) != 0) + _acs.TerminateConnection(connectionList[index]); } } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine(ex.ToString()); + Debug.WriteLine(ex.ToString()); } } @@ -279,33 +348,33 @@ namespace HexcalMC #region Update UI data from Controller /// - /// Update Motion Profile from Controller + /// Update Motion Profile from Controller /// private void UpdateProfile() { - if (m_bConnected) + if (_mBConnected) { - txtVel.Text = _ACS.GetVelocity((Axis)cboAxisNo.SelectedIndex).ToString(); - txtAcc.Text = _ACS.GetAcceleration((Axis)cboAxisNo.SelectedIndex).ToString(); - txtDec.Text = _ACS.GetDeceleration((Axis)cboAxisNo.SelectedIndex).ToString(); - txtKdec.Text = _ACS.GetKillDeceleration((Axis)cboAxisNo.SelectedIndex).ToString(); - txtJerk.Text = _ACS.GetJerk((Axis)cboAxisNo.SelectedIndex).ToString(); + txtVel.Text = _acs.GetVelocity((Axis)cboAxisNo.SelectedIndex).ToString(); + txtAcc.Text = _acs.GetAcceleration((Axis)cboAxisNo.SelectedIndex).ToString(); + txtDec.Text = _acs.GetDeceleration((Axis)cboAxisNo.SelectedIndex).ToString(); + txtKdec.Text = _acs.GetKillDeceleration((Axis)cboAxisNo.SelectedIndex).ToString(); + txtJerk.Text = _acs.GetJerk((Axis)cboAxisNo.SelectedIndex).ToString(); } } - private void cboAxisNo_SelectedIndexChanged(object sender, EventArgs e) + private void CboAxisNo_SelectedIndexChanged(object sender, EventArgs e) { UpdateProfile(); } - private void tmrMonitor_Tick(object sender, EventArgs e) + private void TmrMonitor_Tick(object sender, EventArgs e) { // Get selected axis number int iAxisNo = cboAxisNo.SelectedIndex; // Get selected buffer number int iBufferNo = cboBufferNo.SelectedIndex; - if (m_bConnected) + if (_mBConnected) { try { @@ -320,82 +389,82 @@ namespace HexcalMC // // Get Motor State // ACSPL+ Variable : MST (integer) - m_nMotorState = _ACS.GetMotorState((Axis)iAxisNo); + _mNMotorState = _acs.GetMotorState((Axis)iAxisNo); // Returned value is integer, you need to use bitmaks - if ((m_nMotorState & MotorStates.ACSC_MST_MOVE) != 0) lblMoving.Image = Properties.Resources.On; - else lblMoving.Image = Properties.Resources.Off; // 运动中 - if ((m_nMotorState & MotorStates.ACSC_MST_INPOS) != 0) lblInPos.Image = Properties.Resources.On; - else lblInPos.Image = Properties.Resources.Off; // 就位 - if ((m_nMotorState & MotorStates.ACSC_MST_ACC) != 0) lblAcc.Image = Properties.Resources.On; - else lblAcc.Image = Properties.Resources.Off; // 加速 - if ((m_nMotorState & MotorStates.ACSC_MST_ENABLE) != 0) lblEnable.Image = Properties.Resources.On; - else lblEnable.Image = Properties.Resources.Off; // 使能 + if ((_mNMotorState & MotorStates.ACSC_MST_MOVE) != 0) lblMoving.Image = Resources.On; + else lblMoving.Image = Resources.Off; // 运动中 + if ((_mNMotorState & MotorStates.ACSC_MST_INPOS) != 0) lblInPos.Image = Resources.On; + else lblInPos.Image = Resources.Off; // 就位 + if ((_mNMotorState & MotorStates.ACSC_MST_ACC) != 0) lblAcc.Image = Resources.On; + else lblAcc.Image = Resources.Off; // 加速 + if ((_mNMotorState & MotorStates.ACSC_MST_ENABLE) != 0) lblEnable.Image = Resources.On; + else lblEnable.Image = Resources.Off; // 使能 // Reference position // ACSPL+ Variable : RPOS (real) - m_lfRPos = _ACS.GetRPosition((Axis)iAxisNo); // 参考位置 + _mLfRPos = _acs.GetRPosition((Axis)iAxisNo); // 参考位置 // Feedback position (Encoder value) // ACSPL+ Variable : FPO (real) - m_lfFPos = _ACS.GetFPosition((Axis)iAxisNo); //反馈位置 + _mLfFPos = _acs.GetFPosition((Axis)iAxisNo); //反馈位置 // PE (Position Error) // There is no function in library. We need to use ReadVariable function - m_lfPE = (double)_ACS.ReadVariable("PE", ProgramBuffer.ACSC_NONE, iAxisNo, iAxisNo); //位置误差 + _mLfPe = (double)_acs.ReadVariable("PE", ProgramBuffer.ACSC_NONE, iAxisNo, iAxisNo); //位置误差 // Feedback Velocity - m_lfFVEL = (double)_ACS.ReadVariable("FVEL", ProgramBuffer.ACSC_NONE, iAxisNo, iAxisNo); //实际速度 + _mLfFvel = (double)_acs.ReadVariable("FVEL", ProgramBuffer.ACSC_NONE, iAxisNo, iAxisNo); //实际速度 - txtRPOS.Text = String.Format("{0:0.0000}", m_lfRPos); - txtFPOS.Text = String.Format("{0:0.0000}", m_lfFPos); - txtPE.Text = String.Format("{0:0.0000}", m_lfPE); - txtFVEL.Text = String.Format("{0:0.0000}", m_lfFVEL); + txtRPOS.Text = string.Format("{0:0.0000}", _mLfRPos); + txtFPOS.Text = string.Format("{0:0.0000}", _mLfFPos); + txtPE.Text = string.Format("{0:0.0000}", _mLfPe); + txtFVEL.Text = string.Format("{0:0.0000}", _mLfFvel); // Program State 运动状态 // State : Compiled, Running, Suspended, Autoroutine is running (ON syntax) // // ACSPL+ Variable : PST (integer) - m_nProgramState = _ACS.GetProgramState((ProgramBuffer)iBufferNo); - if ((m_nProgramState & ProgramStates.ACSC_PST_RUN) != 0) + _mNProgramState = _acs.GetProgramState((ProgramBuffer)iBufferNo); + if ((_mNProgramState & ProgramStates.ACSC_PST_RUN) != 0) { - lblPRG_Status_LED.Image = Properties.Resources.On; + lblPRG_Status_LED.Image = Resources.On; lblPRG_Status.Text = "Running"; } else { - lblPRG_Status_LED.Image = Properties.Resources.Off; + lblPRG_Status_LED.Image = Resources.Off; lblPRG_Status.Text = "Stop"; } // Read left/right hardware limits state // ACSPL+ Variable : FAULT (integer) - m_objReadVar = - _ACS.ReadVariableAsVector("FAULT", ProgramBuffer.ACSC_NONE, 0, m_nTotalAxis - 1, -1, -1); - if (m_objReadVar != null) + _mObjReadVar = + _acs.ReadVariableAsVector("FAULT", ProgramBuffer.ACSC_NONE, 0, _mNTotalAxis - 1); + if (_mObjReadVar != null) { - m_arrReadVector = m_objReadVar as Array; - if (m_arrReadVector != null) + _mArrReadVector = _mObjReadVar as Array; + if (_mArrReadVector != null) { - for (int i = 0; i < m_nTotalAxis; i++) + for (int i = 0; i < _mNTotalAxis; i++) { - UpdateLimitState(i, (int)m_arrReadVector.GetValue(i)); + UpdateLimitState(i, (int)_mArrReadVector.GetValue(i)); } } } // Read digital input/output (Port means all of bits) // If you want to read only 1 bit (not an integer), use "GetInput" function - m_nValues = _ACS.GetInputPort(0); // _ACS.ReadVariableAsVector("IN", -1, 0, 0, -1, -1); - UpdateIOState(m_nValues, true); + _mNValues = _acs.GetInputPort(0); // _ACS.ReadVariableAsVector("IN", -1, 0, 0, -1, -1); + UpdateIoState(_mNValues, true); - m_nOutputState = _ACS.GetOutputPort(0); // _ACS.ReadVariableAsVector("OUT", -1, 0, 0, -1, -1); - UpdateIOState(m_nOutputState, false); + _mNOutputState = _acs.GetOutputPort(0); // _ACS.ReadVariableAsVector("OUT", -1, 0, 0, -1, -1); + UpdateIoState(_mNOutputState, false); } catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); - System.Diagnostics.Debug.WriteLine(ex.Message); + Debug.WriteLine(ex.Message); } } } @@ -403,47 +472,47 @@ namespace HexcalMC // Update limit state private void UpdateLimitState(int axisNo, int fault) { - if (axisNo < MAX_UI_LIMIT_CNT) + if (axisNo < MaxUiLimitCnt) { if ((fault & (int)SafetyControlMasks.ACSC_SAFETY_LL) != 0) - m_lblLeftLimit[axisNo].Image = Properties.Resources.Error; - else m_lblLeftLimit[axisNo].Image = Properties.Resources.Off; + _mLblLeftLimit[axisNo].Image = Resources.Error; + else _mLblLeftLimit[axisNo].Image = Resources.Off; if ((fault & (int)SafetyControlMasks.ACSC_SAFETY_RL) != 0) - m_lblRightLimit[axisNo].Image = Properties.Resources.Error; - else m_lblRightLimit[axisNo].Image = Properties.Resources.Off; + _mLblRightLimit[axisNo].Image = Resources.Error; + else _mLblRightLimit[axisNo].Image = Resources.Off; } } // Update general I/O stae - private void UpdateIOState(int value, bool isInput) + private void UpdateIoState(int value, bool isInput) { int bitUpCnt = 0x01; - for (int i = 0; i < MAX_UI_IO_CNT; i++) + for (int i = 0; i < MaxUiIoCnt; i++) { if (isInput) { // Input state - if ((value & bitUpCnt) != 0) m_lblInput[i].Image = Properties.Resources.On; - else m_lblInput[i].Image = Properties.Resources.Off; + if ((value & bitUpCnt) != 0) _mLblInput[i].Image = Resources.On; + else _mLblInput[i].Image = Resources.Off; } else { // Output state if ((value & bitUpCnt) != 0) { - m_btnOutput[i].Text = "OFF"; - m_lblOutput[i].Image = Properties.Resources.On; + _mBtnOutput[i].Text = "OFF"; + _mLblOutput[i].Image = Resources.On; } else { - m_btnOutput[i].Text = "ON"; - m_lblOutput[i].Image = Properties.Resources.Off; + _mBtnOutput[i].Text = "ON"; + _mLblOutput[i].Image = Resources.Off; } } // 0x01 => 0x02 => 0x04 => 0x08 ... increase bit number - bitUpCnt = (0x01) << (i + 1); + bitUpCnt = 0x01 << (i + 1); } } @@ -451,10 +520,10 @@ namespace HexcalMC #region Motor Enable / Disable - private void btnEnable_Click(object sender, EventArgs e) + private void BtnEnable_Click(object sender, EventArgs e) { // Enable selected axis - _ACS.Enable((Axis)cboAxisNo.SelectedIndex); + _acs.Enable((Axis)cboAxisNo.SelectedIndex); // If you want to enable several axes, // @@ -464,57 +533,24 @@ namespace HexcalMC // _ACS.EnableM(AxisList); } - private void btnDisable_Click(object sender, EventArgs e) + private void BtnDisable_Click(object sender, EventArgs e) { // Disable selected axis - _ACS.Disable((Axis)cboAxisNo.SelectedIndex); + _acs.Disable((Axis)cboAxisNo.SelectedIndex); // Disable multi axes : DisableM(int[] axisList) } - private void btnDisableAll_Click(object sender, EventArgs e) + private void BtnDisableAll_Click(object sender, EventArgs e) { // Disable all of axes - _ACS.DisableAll(); - } - - #endregion - - private void btnSetZero_Click(object sender, EventArgs e) - { - // Change current poisition as you want - // SetFPosition(Axis number, new position) - _ACS.SetFPosition((Axis)cboAxisNo.SelectedIndex, 0); - } - - #region Move to absolute position - - private void btnPTP_Click(object sender, EventArgs e) - { - double lfTargetPos = 0.0f; - try - { - if (txtPTP_Pos.Text.Length > 0) - { - lfTargetPos = Convert.ToDouble(txtPTP_Pos.Text); - _ACS.ToPoint( - 0, // '0' - Absolute position - (Axis)cboAxisNo.SelectedIndex, // Axis number - lfTargetPos // Target position - ); - } - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); - System.Diagnostics.Debug.WriteLine(ex.Message); - } + _acs.DisableAll(); } #endregion #region Move to relative position (from current position) - private void btnPTP_R_Neg_Click(object sender, EventArgs e) + private void BtnPTP_R_Neg_Click(object sender, EventArgs e) { double lfTargetPos = 0.0f; try @@ -523,9 +559,9 @@ namespace HexcalMC { lfTargetPos = Convert.ToDouble(txtPTP_Pos.Text); if (lfTargetPos > 0) - lfTargetPos = lfTargetPos * (-1); // Target position (from current position, step move) + lfTargetPos = lfTargetPos * -1; // Target position (from current position, step move) - _ACS.ToPoint( + _acs.ToPoint( MotionFlags.ACSC_AMF_RELATIVE, // Flat (Axis)cboAxisNo.SelectedIndex, // Axis number lfTargetPos // Move distance @@ -535,11 +571,11 @@ namespace HexcalMC catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); - System.Diagnostics.Debug.WriteLine(ex.Message); + Debug.WriteLine(ex.Message); } } - private void btnPTP_R_Pos_Click(object sender, EventArgs e) + private void BtnPTP_R_Pos_Click(object sender, EventArgs e) { double lfTargetPos = 0.0f; try @@ -547,15 +583,15 @@ namespace HexcalMC if (txtPTP_Pos.Text.Length > 0) { lfTargetPos = Convert.ToDouble(txtPTP_Pos.Text); - if (lfTargetPos < 0) lfTargetPos = lfTargetPos * (-1); + if (lfTargetPos < 0) lfTargetPos = lfTargetPos * -1; - _ACS.ToPoint(MotionFlags.ACSC_AMF_RELATIVE, (Axis)cboAxisNo.SelectedIndex, lfTargetPos); + _acs.ToPoint(MotionFlags.ACSC_AMF_RELATIVE, (Axis)cboAxisNo.SelectedIndex, lfTargetPos); } } catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); - System.Diagnostics.Debug.WriteLine(ex.Message); + Debug.WriteLine(ex.Message); } } @@ -563,20 +599,20 @@ namespace HexcalMC #region Stop motion using deceleration (halt command) - private void btnHalt_Click(object sender, EventArgs e) + private void BtnHalt_Click(object sender, EventArgs e) { try { - _ACS.Halt((Axis)cboAxisNo.SelectedIndex); //使用 halt 命令减速 + _acs.Halt((Axis)cboAxisNo.SelectedIndex); //使用 halt 命令减速 } catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); - System.Diagnostics.Debug.WriteLine(ex.Message); + Debug.WriteLine(ex.Message); } } - private void btnHallAll_Click(object sender, EventArgs e) + private void BtnHallAll_Click(object sender, EventArgs e) { try { @@ -585,12 +621,12 @@ namespace HexcalMC // ex) You want to stop 0, 2, 5 axis // int[] m_arrAxisList = new int[] { 0, 2, 5, -1 }; // - if (m_arrAxisList != null) _ACS.HaltM(m_arrAxisList); + if (_mArrAxisList != null) _acs.HaltM(_mArrAxisList); } catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); - System.Diagnostics.Debug.WriteLine(ex.Message); + Debug.WriteLine(ex.Message); } } @@ -599,7 +635,7 @@ namespace HexcalMC #region JOG Command // Move negative direction - private void btnJogNeg_MouseDown(object sender, MouseEventArgs e) + private void BtnJogNeg_MouseDown(object sender, MouseEventArgs e) { double lfVelocity = 0.0f; @@ -608,9 +644,9 @@ namespace HexcalMC if (chkUseVel.Checked) { lfVelocity = Convert.ToDouble(txtJogVel.Text.Trim()); - if (lfVelocity > 0) lfVelocity = lfVelocity * (-1); // Negative direction : Using - (minus) velocity + if (lfVelocity > 0) lfVelocity = lfVelocity * -1; // Negative direction : Using - (minus) velocity - _ACS.Jog( + _acs.Jog( MotionFlags.ACSC_AMF_VELOCITY, // Velocity flag 速度标志 (Axis)cboAxisNo.SelectedIndex, // Axis number lfVelocity // Velocity @@ -618,18 +654,18 @@ namespace HexcalMC } else { - _ACS.Jog(0, (Axis)cboAxisNo.SelectedIndex, (double)GlobalDirection.ACSC_NEGATIVE_DIRECTION); + _acs.Jog(0, (Axis)cboAxisNo.SelectedIndex, (double)GlobalDirection.ACSC_NEGATIVE_DIRECTION); } } catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); - System.Diagnostics.Debug.WriteLine(ex.Message); + Debug.WriteLine(ex.Message); } } // 정방향 이동 동작 - private void btnJogPos_MouseDown(object sender, MouseEventArgs e) + private void BtnJogPos_MouseDown(object sender, MouseEventArgs e) { double lfVelocity = 0.0f; @@ -638,33 +674,33 @@ namespace HexcalMC if (chkUseVel.Checked) { lfVelocity = Convert.ToDouble(txtJogVel.Text.Trim()); - if (lfVelocity < 0) lfVelocity = lfVelocity * (-1); + if (lfVelocity < 0) lfVelocity = lfVelocity * -1; - _ACS.Jog(MotionFlags.ACSC_AMF_VELOCITY, (Axis)cboAxisNo.SelectedIndex, lfVelocity); + _acs.Jog(MotionFlags.ACSC_AMF_VELOCITY, (Axis)cboAxisNo.SelectedIndex, lfVelocity); } else { - _ACS.Jog(0, (Axis)cboAxisNo.SelectedIndex, (double)GlobalDirection.ACSC_POSITIVE_DIRECTION); + _acs.Jog(0, (Axis)cboAxisNo.SelectedIndex, (double)GlobalDirection.ACSC_POSITIVE_DIRECTION); } } catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); - System.Diagnostics.Debug.WriteLine(ex.Message); + Debug.WriteLine(ex.Message); } } // Stop JOG motion - private void btnJog_MouseUp(object sender, MouseEventArgs e) + private void BtnJog_MouseUp(object sender, MouseEventArgs e) { - _ACS.Halt((Axis)cboAxisNo.SelectedIndex); + _acs.Halt((Axis)cboAxisNo.SelectedIndex); } #endregion #region Run/Stop Buffer Program - private void btnRunBuffer_Click(object sender, EventArgs e) + private void BtnRunBuffer_Click(object sender, EventArgs e) { string temp; @@ -682,25 +718,25 @@ namespace HexcalMC } // Run buffer program from label position - _ACS.RunBuffer((ProgramBuffer)cboBufferNo.SelectedIndex, txtLabelName.Text.Trim()); + _acs.RunBuffer((ProgramBuffer)cboBufferNo.SelectedIndex, txtLabelName.Text.Trim()); } else { // Run buffer program from first line - _ACS.RunBuffer((ProgramBuffer)cboBufferNo.SelectedIndex, null); + _acs.RunBuffer((ProgramBuffer)cboBufferNo.SelectedIndex, null); } } catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); - System.Diagnostics.Debug.WriteLine(ex.Message); + Debug.WriteLine(ex.Message); } } - private void btnStopBuffer_Click(object sender, EventArgs e) + private void BtnStopBuffer_Click(object sender, EventArgs e) { // Stop program - _ACS.StopBuffer((ProgramBuffer)cboBufferNo.SelectedIndex); + _acs.StopBuffer((ProgramBuffer)cboBufferNo.SelectedIndex); } #endregion @@ -719,7 +755,7 @@ namespace HexcalMC if ((e.KeyChar >= 0x30 && e.KeyChar <= 0x39) || e.KeyChar == 0x2E || e.KeyChar == 0x08 || e.KeyChar == (char)Keys.Return || e.KeyChar == (char)Keys.Enter) { - if ((e.KeyChar == 0x2E) && (textBox.Text.Contains(Convert.ToString(0x2E)))) + if (e.KeyChar == 0x2E && textBox.Text.Contains(Convert.ToString(0x2E))) e.KeyChar = (char)0x00; if (e.KeyChar == (char)Keys.Return || e.KeyChar == (char)Keys.Enter) { @@ -732,19 +768,19 @@ namespace HexcalMC // Affect next motion : SetVelocity() case 0: - _ACS.SetVelocityImm((Axis)cboAxisNo.SelectedIndex, lfTemp); + _acs.SetVelocityImm((Axis)cboAxisNo.SelectedIndex, lfTemp); break; case 1: - _ACS.SetAccelerationImm((Axis)cboAxisNo.SelectedIndex, lfTemp); + _acs.SetAccelerationImm((Axis)cboAxisNo.SelectedIndex, lfTemp); break; case 2: - _ACS.SetDecelerationImm((Axis)cboAxisNo.SelectedIndex, lfTemp); + _acs.SetDecelerationImm((Axis)cboAxisNo.SelectedIndex, lfTemp); break; case 3: - _ACS.SetKillDecelerationImm((Axis)cboAxisNo.SelectedIndex, lfTemp); + _acs.SetKillDecelerationImm((Axis)cboAxisNo.SelectedIndex, lfTemp); break; case 4: - _ACS.SetJerkImm((Axis)cboAxisNo.SelectedIndex, lfTemp); + _acs.SetJerkImm((Axis)cboAxisNo.SelectedIndex, lfTemp); break; } @@ -756,7 +792,7 @@ namespace HexcalMC } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine("TextBoxes_KeyPress() Error\n" + ex.ToString()); + Debug.WriteLine("TextBoxes_KeyPress() Error\n" + ex); } } @@ -769,7 +805,7 @@ namespace HexcalMC } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine("TextBoxes_Enter() Error\n" + ex.ToString()); + Debug.WriteLine("TextBoxes_Enter() Error\n" + ex); } } @@ -786,19 +822,19 @@ namespace HexcalMC switch (textBox.TabIndex) { case 0: - _ACS.SetVelocityImm((Axis)cboAxisNo.SelectedIndex, lfTemp); + _acs.SetVelocityImm((Axis)cboAxisNo.SelectedIndex, lfTemp); break; case 1: - _ACS.SetAccelerationImm((Axis)cboAxisNo.SelectedIndex, lfTemp); + _acs.SetAccelerationImm((Axis)cboAxisNo.SelectedIndex, lfTemp); break; case 2: - _ACS.SetDecelerationImm((Axis)cboAxisNo.SelectedIndex, lfTemp); + _acs.SetDecelerationImm((Axis)cboAxisNo.SelectedIndex, lfTemp); break; case 3: - _ACS.SetKillDecelerationImm((Axis)cboAxisNo.SelectedIndex, lfTemp); + _acs.SetKillDecelerationImm((Axis)cboAxisNo.SelectedIndex, lfTemp); break; case 4: - _ACS.SetJerkImm((Axis)cboAxisNo.SelectedIndex, lfTemp); + _acs.SetJerkImm((Axis)cboAxisNo.SelectedIndex, lfTemp); break; } @@ -806,50 +842,7 @@ namespace HexcalMC } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine("TextBoxes_Leave() Error\n" + ex.ToString()); - } - } - - #endregion - - #region On and Off General Output - - private void btnSW_Click(object sender, EventArgs e) - { - int nBitNo = 0x01; - - try - { - Button btn = sender as Button; - if (btn == null) return; - - nBitNo = btn.TabIndex; - nBitNo = (0x01) << nBitNo; //左移几位 - - if ((m_nOutputState & nBitNo) != 0) - { - // Set only 1 bit - _ACS.SetOutput( - 0, // Port number - btn.TabIndex, // Bit number - 0 // 0 = OFF, 1 = ON - ); - - // If your I/O device is EtherCAT type, you cannot use this function - // You can use WriteVariable function and Command function - // - // Ex) If EtherCAT mapped variable is 'EC_DOUT' - // Want to ON bit '3' - // _ACS.Command("EC_DOUT.3=1"); - } - else - { - _ACS.SetOutput(0, btn.TabIndex, 1); - } - } - catch (Exception ex) - { - System.Diagnostics.Debug.WriteLine("btnSW_Click() Error\n" + ex.ToString()); + Debug.WriteLine("TextBoxes_Leave() Error\n" + ex); } } @@ -857,14 +850,14 @@ namespace HexcalMC #region Event - private void btnEventMotionEnd_Click(object sender, EventArgs e) + private void BtnEventMotionEnd_Click(object sender, EventArgs e) { //_ACS.PHYSICALMOTIONEND +=_ACS_PHYSICALMOTIONEND; - _ACS.EnableEvent(Interrupts.ACSC_INTR_PHYSICAL_MOTION_END); + _acs.EnableEvent(Interrupts.ACSC_INTR_PHYSICAL_MOTION_END); lstLog.Items.Add("PHYSICAL_MOTION_END event enabled"); } - void _ACS_PHYSICALMOTIONEND(AxisMasks axis) + private void ACS_PHYSICALMOTIONEND(AxisMasks axis) { int bit = 0x01; int axisNo = 0; @@ -882,21 +875,21 @@ namespace HexcalMC } // Add log to ListBox - this.Invoke((MethodInvoker)delegate + Invoke((MethodInvoker)delegate { - lstLog.Items.Add(String.Format(" - Axis {0}, Stoppped", axisNo)); + lstLog.Items.Add(string.Format(" - Axis {0}, Stoppped", axisNo)); lstLog.SelectedIndex = lstLog.Items.Count - 1; }); } - private void btnEventProgramEnd_Click(object sender, EventArgs e) + private void BtnEventProgramEnd_Click(object sender, EventArgs e) { //_ACS.PROGRAMEND += _ACS_PROGRAMEND; - _ACS.EnableEvent(Interrupts.ACSC_INTR_PROGRAM_END); + _acs.EnableEvent(Interrupts.ACSC_INTR_PROGRAM_END); lstLog.Items.Add("PROGRAM_END event enabled"); } - void _ACS_PROGRAMEND(BufferMasks buffer) + private void ACS_PROGRAMEND(BufferMasks buffer) { int bit = 0x01; int bufferNo = 0; @@ -914,9 +907,9 @@ namespace HexcalMC } // Add log to ListBox - this.Invoke((MethodInvoker)delegate + Invoke((MethodInvoker)delegate { - lstLog.Items.Add(String.Format(" - Buffer {0}, Stoppped", bufferNo)); + lstLog.Items.Add(string.Format(" - Buffer {0}, Stoppped", bufferNo)); lstLog.SelectedIndex = lstLog.Items.Count - 1; }); } @@ -925,25 +918,25 @@ namespace HexcalMC #region Communication Termial - Using Transaction function - private void txtCommand_KeyPress(object sender, KeyPressEventArgs e) + private void TxtCommand_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Enter) btnSend.PerformClick(); } - private void btnSend_Click(object sender, EventArgs e) + private void BtnSend_Click(object sender, EventArgs e) { string temp = string.Empty; - if (m_bConnected) + if (_mBConnected) { try { AppendTextToTextBox("> " + txtCommand.Text.Trim()); - temp = _ACS.Transaction(txtCommand.Text.Trim()); + temp = _acs.Transaction(txtCommand.Text.Trim()); } - catch (ACS.SPiiPlusNET.ACSException ex) + catch (ACSException ex) { - temp = String.Format("?{0}", ex.ErrorCode); + temp = string.Format("?{0}", ex.ErrorCode); } finally { diff --git a/HexcalMC/Program.cs b/HexcalMC/Program.cs index b76ae87..1c3b960 100644 --- a/HexcalMC/Program.cs +++ b/HexcalMC/Program.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Windows.Forms; @@ -28,14 +27,14 @@ using System.Windows.Forms; namespace HexcalMC { - static class Program + internal static class Program { [STAThread] - static void Main() + private static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainFrom()); } } -} +} \ No newline at end of file diff --git a/HexcalMC/packages.config b/HexcalMC/packages.config index ced538a..b1d9ff7 100644 --- a/HexcalMC/packages.config +++ b/HexcalMC/packages.config @@ -1,7 +1,7 @@  - - + +