public void closeInstr() { if (_instr_isOpened) { _instrument.Close(); } }
private void RefreshInstruments(Interface_3497xx instr, Button open, ComboBox cb) { if (_instr_isOpened) { instr.Close(); open.Text = "Open"; } cb.Items.Clear(); List <string> devices = _instrument.ScanDevices(); foreach (string item in devices) { cb.Items.Add(item); Console.WriteLine("device:" + item); } // cb.Items.AddRange(SerialPort.GetPortNames()); if (cb.Items.Count != 0) { cb.SelectedIndex = 0; } }
private void ManualOpenInstrument(ref string addr, ref Interface_3497xx instr, ref Button open, ref Button scan, ref ComboBox cb) { if (open.Text.Equals("Open")) { if (cb.SelectedItem == null) { return; } Console.WriteLine("instru.baud:" + instrBaudRate.ToString()); string addrSelected = cb.SelectedItem.ToString(); bool error_flag = false; try { //sp.RtsEnable = true; //sp.DtrEnable = true; if (instr.Open(addrSelected, 2000, instrBaudRate)) { open.Text = "Close"; scan.Enabled = false; cb.Enabled = false; _instr_isOpened = true; } else { _instr_isOpened = false; MessageBox.Show("Open fail,please check setting!"); } } catch (Exception ex) { MessageBox.Show("Error:" + ex.ToString()); error_flag = true; _instr_isOpened = false; } if (!error_flag) { //MessageBox.Show("Open device successful!"); //string SERIAL_key = string.Format("SERIAL{0}", _id); addr = addrSelected; } } else { try { instr.Close(); } catch (Exception ex) { MessageBox.Show("Error:" + ex.ToString()); } finally { open.Text = "Open"; scan.Enabled = true; cb.Enabled = true; } } }