private void btnCheckIP_Click(object sender, EventArgs e) { if (!txtIPAddress.Text.IsMatch(IPRegex)) { MessageBox.Show(Resources.NotCorrectIP); txtIPAddress.SetSelect(); return; } foreach (var item in cboLAN.Items) { if (((string)item).Contains(txtIPAddress.Text)) { MessageBox.Show(Resources.LANContainIP); txtIPAddress.SetSelect(); return; } } if (!PortUltility.OpenIPAddress(txtIPAddress.Text, out string fullAddress)) { MessageBox.Show(Resources.NotDetectIP); txtIPAddress.SetSelect(); return; } cboLAN.Items.Add(fullAddress); cboLAN.Text = cboLAN.Items[cboLAN.Items.Count - 1].ToString(); MessageBox.Show(Resources.DetectOK); }
private void scanBtn_Click(object sender, EventArgs e) { string title = Text; t = Task.Factory.StartNew(() => { try { //InvokeToForm(() => { btnRefresh.Enabled = false; btnOpen.Enabled = false; Text = title + Resources.LoadingRS232; }); List <string> devices = new List <string>(); string[] content1 = PortUltility.FindAddresses(PortType.RS232); string[] content2 = PortUltility.FindRS232Type(content1); List <string> list1 = new List <string>(); List <string> list2 = new List <string>(); for (int i = 0; i < content2.Length; i++) { if (content2[i].Contains("LPT")) { continue; } list1.Add(content1[i]); list2.Add(content2[i]); } content1 = list1.ToArray(); //ASRL1::INSR... content2 = list2.ToArray(); //COM1... devices = list1; // InvokeToForm(() => devicesCB.ShowAndDisplay(content1, content2)); // InvokeToForm(() => { Text = title + Resources.LoadingUSB; }); content1 = PortUltility.FindAddresses(PortType.USB); devices.AddRange(content1); // InvokeToForm(() => cboUSB.ShowAndDisplay(content1)); // InvokeToForm(() => { Text = title + Resources.LoadingGPIB; }); content1 = PortUltility.FindAddresses(PortType.GPIB); devices.AddRange(content1); // InvokeToForm(() => cboGPIB.ShowAndDisplay(content1)); // InvokeToForm(() => { Text = title + Resources.LoadingLAN; }); content1 = PortUltility.FindAddresses(PortType.LAN); devices.AddRange(content1); string[] list = devices.ToArray(); InvokeToForm(() => devicesCB.ShowAndDisplay(list)); // InvokeToForm(() => { btnRefresh.Enabled = true; btnOpen.Enabled = true; Text = title; }); } catch (Exception ex) { MessageBox.Show("exception:" + ex.ToString()); } }).ContinueWith(x => { if (x.IsFaulted) { MessageBox.Show("Scan not completed! Error!!!"); // CancelDisplayForm = true; // InvokeToForm(() => { tableLayoutPanel.Enabled = false; this.Text = Resources.RuntimeError; }); } }); }
private void btnRefresh_Click(object sender, EventArgs e) { string title = Text; t = Task.Factory.StartNew(() => { InvokeToForm(() => { btnRefresh.Enabled = false; btnOpen.Enabled = false; Text = title + Resources.LoadingRS232; }); string[] content1 = PortUltility.FindAddresses(PortType.RS232); string[] content2 = PortUltility.FindRS232Type(content1); List <string> list1 = new List <string>(); List <string> list2 = new List <string>(); for (int i = 0; i < content2.Length; i++) { if (content2[i].Contains("LPT")) { continue; } list1.Add(content1[i]); list2.Add(content2[i]); } content1 = list1.ToArray(); content2 = list2.ToArray(); InvokeToForm(() => cboRS232.ShowAndDisplay(content1, content2)); InvokeToForm(() => { Text = title + Resources.LoadingUSB; }); content1 = PortUltility.FindAddresses(PortType.USB); InvokeToForm(() => cboUSB.ShowAndDisplay(content1)); InvokeToForm(() => { Text = title + Resources.LoadingGPIB; }); content1 = PortUltility.FindAddresses(PortType.GPIB); InvokeToForm(() => cboGPIB.ShowAndDisplay(content1)); InvokeToForm(() => { Text = title + Resources.LoadingLAN; }); content1 = PortUltility.FindAddresses(PortType.LAN); InvokeToForm(() => cboLAN.ShowAndDisplay(content1)); InvokeToForm(() => { btnRefresh.Enabled = true; btnOpen.Enabled = true; Text = title; }); }).ContinueWith(x => { if (x.IsFaulted) { CancelDisplayForm = true; InvokeToForm(() => { tableLayoutPanel.Enabled = false; this.Text = Resources.RuntimeError; }); } }); }