/// <summary> /// Create a serial port monitor for the supplied port name, in response /// to an event generated by the main window. /// </summary> /// <param name='portname'> /// Name of the serial port to open. /// </param> private void show_monitor(string portname) { // ignore monitor activation requests while uploading if (upload_in_progress) { return; } // set/switch port assignment set_port(portname); // create the monitor if it's not already open if (mon == null) { // create a new monitor mon = new Mon(port); //mon.QuitEvent += end_monitor; ?? mon.DeleteEvent += end_monitor; mon.LogEvent += log; // and connect it to the port mon.connect(port); } else { // bring the window to the front mon.Present(); } }
private void set_port(string portname) { if (upload_in_progress) { throw new Exception("attempt to change port while upload in progress"); } // If the port name hasn't changed, keep the existing port if ((port != null) && (portname.Equals(port.PortName))) { return; } // dispose of the old port if (mon != null) { mon.disconnect(); } if ((port != null) && port.IsOpen) { port.Close(); } port = null; try { // create a new one port = new SerialPort(portname, 115200, Parity.None, 8, StopBits.One); log("opening " + port.PortName + "\n", 1); port.Open(); log("opened " + port.PortName + "\n", 1); // remember that we successfully opened this port config_section.lastPort = port.PortName; } catch { log("FAIL: cannot open " + port.PortName + "\n"); port = null; } // if we have a port and a monitor, connect it to the new port if ((port != null) && (mon != null)) { mon.connect(port); } }
/// <summary> /// Create a serial port monitor for the supplied port name, in response /// to an event generated by the main window. /// </summary> /// <param name='portname'> /// Name of the serial port to open. /// </param> private void show_monitor (string portname) { // ignore monitor activation requests while uploading if (upload_in_progress) return; // set/switch port assignment set_port (portname); // create the monitor if it's not already open if (mon == null) { // create a new monitor mon = new Mon (port); //mon.QuitEvent += end_monitor; ?? mon.DeleteEvent += end_monitor; mon.LogEvent += log; // and connect it to the port mon.connect (port); } else { // bring the window to the front mon.Present (); } }