diff --git a/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs index 7a7ffb30..28a52c21 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs @@ -248,10 +248,7 @@ protected override async ValueTask ExecuteCommand() private async Task WriteRuntime(IMeadowConnection? connection, DeviceInfo? deviceInfo, string runtimePath, string destinationFilename) { - if (connection == null) - { - connection = await GetConnectionAndDisableRuntime(); - } + connection ??= await GetConnectionAndDisableRuntime(); Logger?.LogInformation($"{Environment.NewLine}Writing Runtime ..."); @@ -280,6 +277,8 @@ protected override async ValueTask ExecuteCommand() throw CommandException.MeadowDeviceNotFound; } + connection = await GetCurrentConnection(true); + Logger?.LogInformation($"Meadow found at {newPort}"); // configure the route to that port for the user @@ -318,10 +317,7 @@ private async Task WriteEspFiles(IMeadowConnection? connection, DeviceInfo? devi }; } - if (deviceInfo == null) - { - deviceInfo = await connection.GetDeviceInfo(CancellationToken); - } + deviceInfo ??= await connection.GetDeviceInfo(CancellationToken); if (UseDfu || RequiresDfuForEspUpdates(deviceInfo)) {