Skip to content

Commit 1304b50

Browse files
authored
Improve output on failure to open COM port (#102)
1 parent 55a655d commit 1304b50

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

nanoFirmwareFlasher/EspTool.cs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,32 @@ internal EspTool(
103103
{
104104
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
105105
{
106-
// open/close the port to see if it is available
107-
using (var test = new SerialPort(serialPort, baudRate))
108-
{
106+
// open/close the COM port to check if it is available
107+
var test = new SerialPort(serialPort, baudRate);
109108

110-
try
111-
{
112-
test.Open();
113-
test.Close();
114-
}
115-
catch
109+
try
110+
{
111+
test.Open();
112+
test.Close();
113+
}
114+
catch(Exception ex)
115+
{
116+
if (Verbosity >= VerbosityLevel.Detailed)
116117
{
117-
// presume any exception here is caused by the serial not existing or not possible to open
118-
throw new EspToolExecutionException();
118+
Console.ForegroundColor = ConsoleColor.DarkRed;
119+
120+
Console.WriteLine("");
121+
Console.WriteLine("******************* EXCEPTION *****************");
122+
Console.WriteLine($"Exception occurred while trying to open <{serialPort}>:");
123+
Console.WriteLine($"{ex.Message}");
124+
Console.WriteLine("***********************************************");
125+
Console.WriteLine("");
126+
127+
Console.ForegroundColor = ConsoleColor.White;
119128
}
129+
130+
// presume any exception here is caused by the serial not existing or not possible to open
131+
throw new EspToolExecutionException();
120132
}
121133
}
122134
else

0 commit comments

Comments
 (0)