//private static System.Text.RegularExpressions.Regex ComRX = new System.Text.RegularExpressions.Regex(@"(?'wholecom'(?:^|[ (])COM(?'comno'\d+)(?:[) ]|$))", System.Text.RegularExpressions.RegexOptions.Compiled); //private System.Collections.Generic.SortedDictionary<int, string> GetPortDictionary() //{ // System.Collections.Generic.SortedDictionary<int, string> rv = new System.Collections.Generic.SortedDictionary<int, string>(); // // try //add using managment object // { // using (System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(@"\\.\root\cimv2", "SELECT * FROM Win32_PnPEntity")) // { // System.Management.ManagementObjectCollection moc = searcher.Get(); // foreach (System.Management.ManagementObject mo in moc) // { // string caption = (string)mo["Caption"]; // if (caption != null && ComRX.IsMatch(caption)) // { // System.Text.RegularExpressions.Match m = ComRX.Match(caption); // if (m != null && m.Groups["comno"] != null) // { // int no = int.Parse(m.Groups["comno"].Value); // string wholecom = m.Groups["wholecom"].Value; // if (!rv.ContainsKey(no)) // rv.Add(int.Parse(m.Groups["comno"].Value), caption.Replace(wholecom, "").Trim()); // } // } // } // // } // } // catch { } // // try //add using SerialPort.GetPortNames // { // foreach (string dirty in System.IO.Ports.SerialPort.GetPortNames()) // { // string comno = dirty; // if (!char.IsDigit(comno[comno.Length - 1])) // comno = comno.Substring(0, comno.Length - 1); // // string caption = comno; // if (caption != null && ComRX.IsMatch(caption)) // { // System.Text.RegularExpressions.Match m = ComRX.Match(caption); // if (m != null && m.Groups["comno"] != null) // { // int no = int.Parse(m.Groups["comno"].Value); // if (!rv.ContainsKey(no)) // rv.Add(int.Parse(m.Groups["comno"].Value), "Generic COM Port"); // } // } // } // } // catch { } // // return rv; //} void BtnConnectDisconnectClick(object sender, EventArgs e) { if (Core.MachineStatus == GrblCore.MacStatus.Disconnected) { Core.OpenCom(); } else if (!(Core.InProgram && System.Windows.Forms.MessageBox.Show(Strings.DisconnectAnyway, "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != System.Windows.Forms.DialogResult.Yes)) { Core.CloseCom(true); } TimerUpdate(); }
private void MnConnect_Click(object sender, EventArgs e) { Core.OpenCom(); }