From c9cbe4ecc7729de08aac5754ff25e4e2b29d4a9a Mon Sep 17 00:00:00 2001 From: Edward Wright Date: Tue, 4 Jun 2019 21:52:17 -0400 Subject: [PATCH] fixed missing object reference exception in ExitProgram() --- SimplySerial/SimplySerial.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/SimplySerial/SimplySerial.cs b/SimplySerial/SimplySerial.cs index 0b79f03..e5f8536 100644 --- a/SimplySerial/SimplySerial.cs +++ b/SimplySerial/SimplySerial.cs @@ -240,11 +240,6 @@ namespace SimplySerial // get a list of all available com ports string[] availablePorts = SerialPort.GetPortNames(); - foreach (string potentialPort in availablePorts) - { - Console.WriteLine("PORT: {0}", potentialPort); - } - // if no port was specified, default to the first/only available com port, exit with error if no ports are available if (port == String.Empty) { @@ -305,7 +300,7 @@ namespace SimplySerial static void ExitProgram(string message="", int exitCode=0, bool silent=false) { // the serial port should be closed before exiting - if (serialPort.IsOpen) + if (serialPort != null && serialPort.IsOpen) serialPort.Close(); if (!silent) @@ -339,7 +334,7 @@ namespace SimplySerial // '?' or 'h' trigger the 'help' text output and supersede all other command-line arguments // 'q' enables the 'quiet' option, which needs to be enabled before something that would normally generate console output // 'n' enables the 'nowait' option, which needs to be enabled before anything that would trigger an artificial delay - foreach (char c in "?hqn") + foreach (char c in "?hlqn") { if (x[0] == c) return (-1);