public void OpenComPort() { ComPort.PortName = Convert.ToString(Properties.Settings.Default.savedComPort); ComPort.BaudRate = Convert.ToInt32(Properties.Settings.Default.savedBaudRate.ToString()); ComPort.DataBits = Convert.ToInt16(Properties.Settings.Default.savedDataBits.ToString()); ComPort.StopBits = (StopBits)Enum.Parse(typeof(StopBits), Properties.Settings.Default.savedStopBits); ComPort.Handshake = (Handshake)Enum.Parse(typeof(Handshake), Properties.Settings.Default.savedHandshake); ComPort.Parity = (Parity)Enum.Parse(typeof(Parity), Properties.Settings.Default.savedParity); ComPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(port_DataReceived_1); try { ComPort.Open(); instrumentStateOn = true; } catch { frontSwitchOn = false; instrumentStateOn = false; MessageBox.Show("K2700 instumend is not on connected to " + ComPort.PortName); InstrumentSwitchedOffEventArgs args = new InstrumentSwitchedOffEventArgs(frontSwitchOn); InstrumentSwitchedOff(this, args); } if (instrumentStateOn == true) { Reset(); ComPort.Write("DISP:ENAB OFF\r\n"); } }
private void k2700FrontswitchOff(object sender, InstrumentSwitchedOffEventArgs e) { K2700frontSwitchOn = e.FrontSwitchOn; TestAbortedEventArgs args = new TestAbortedEventArgs(true); TestAborted(this, args); }
private void port_DataReceived_1(object sender, SerialDataReceivedEventArgs e) { while (!InputData.Contains("\r")) { InputData = InputData + ComPort.ReadExisting(); } if (InputData.Equals("1\r")) { frontSwitchOn = false; MessageBox.Show("K2700 Instrument Front switch is in OFF state!"); InstrumentSwitchedOffEventArgs args = new InstrumentSwitchedOffEventArgs(frontSwitchOn); InstrumentSwitchedOff(this, args); } else if (InputData.Equals("0\r")) { frontSwitchOn = true; } else if (InputData != String.Empty) { measuredCurrent = InputData; } InputData = String.Empty; }