Skip to content

Commit a3c63e3

Browse files
authored
Add proper handling of COM port open failure (#33)
1 parent b64356e commit a3c63e3

File tree

6 files changed

+35
-9
lines changed

6 files changed

+35
-9
lines changed

source/nanoFirmwareFlasher.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ VisualStudioVersion = 16.0.29806.167
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nanoFirmwareFlasher", "nanoFirmwareFlasher\nanoFirmwareFlasher.csproj", "{762BA2A1-B3E9-4E26-9491-AE11D1F1C1EA}"
77
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9FD8C426-A16A-49DB-952D-747C3AD96C42}"
9+
ProjectSection(SolutionItems) = preProject
10+
NuGet.Config = NuGet.Config
11+
version.json = version.json
12+
EndProjectSection
13+
EndProject
814
Global
915
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1016
Debug|x64 = Debug|x64

source/nanoFirmwareFlasher/EspTool.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ internal EspTool(
163163
test.Open();
164164
test.Close();
165165
}
166-
catch(IOException)
166+
catch
167167
{
168-
// presume any IOException here is caused by the serial not existing or not possible to open
169-
return;
168+
// presume any exception here is caused by the serial not existing or not possible to open
169+
throw new EspToolExecutionException();
170170
}
171171
}
172172

source/nanoFirmwareFlasher/Exceptions/EspToolExecutionException.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ internal class EspToolExecutionException : Exception
1919
/// </summary>
2020
public string ExecutionError;
2121

22+
public EspToolExecutionException() : base()
23+
{
24+
25+
}
26+
2227
public EspToolExecutionException(string message) : base(message)
2328
{
2429
ExecutionError = message;

source/nanoFirmwareFlasher/ExitCodes.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public enum ExitCodes : int
7777
[Display(Name = "Failed to read from ESP32 flash.")]
7878
E4004 = 4004,
7979

80+
/// <summary>
81+
/// Can't open COM port.
82+
/// </summary>
83+
[Display(Name = "Failed to open specified COM port.")]
84+
E4005 = 4005,
8085

8186
////////////////////
8287
// ST Link Errors //

source/nanoFirmwareFlasher/Program.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,22 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
220220
_exitCode = ExitCodes.E6001;
221221
return;
222222
}
223+
224+
EspTool espTool;
223225

224-
var espTool = new EspTool(
225-
o.SerialPort,
226-
o.BaudRate,
227-
o.Esp32FlashMode,
228-
o.Esp32FlashFrequency);
226+
try
227+
{
228+
espTool = new EspTool(
229+
o.SerialPort,
230+
o.BaudRate,
231+
o.Esp32FlashMode,
232+
o.Esp32FlashFrequency);
233+
}
234+
catch(Exception)
235+
{
236+
_exitCode = ExitCodes.E4005;
237+
return;
238+
}
229239

230240
EspTool.DeviceInfo esp32Device;
231241

source/version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
3-
"version": "1.12.0-preview.{height}",
3+
"version": "1.12.1-preview.{height}",
44
"assemblyVersion": {
55
"precision": "revision"
66
},

0 commit comments

Comments
 (0)