diff --git a/Source/v2/Meadow.Cli/Commands/Current/BaseDeviceCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/BaseDeviceCommand.cs index 944136dc..30ea8fda 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/BaseDeviceCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/BaseDeviceCommand.cs @@ -14,10 +14,8 @@ public BaseDeviceCommand(MeadowConnectionManager connectionManager, ILoggerFacto ConnectionManager = connectionManager; } - public override async ValueTask ExecuteAsync(IConsole console) + protected async Task RefreshConnection() { - SetConsole(console); - CurrentConnection = ConnectionManager.GetCurrentConnection(); if (CurrentConnection != null) @@ -61,4 +59,11 @@ public override async ValueTask ExecuteAsync(IConsole console) Logger?.LogError("Current Connnection Unavailable"); } } + + public override async ValueTask ExecuteAsync(IConsole console) + { + SetConsole(console); + + await RefreshConnection(); + } } \ No newline at end of file diff --git a/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs index 2389a0e3..563680a4 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs @@ -2,7 +2,6 @@ using CliFx.Infrastructure; using Meadow.Cli; using Meadow.CLI.Core.Internals.Dfu; -using Meadow.Hcom; using Meadow.LibUsb; using Meadow.Software; using Microsoft.Extensions.Logging; @@ -84,7 +83,7 @@ public override async ValueTask ExecuteAsync(IConsole console) } catch (Exception ex) { - Logger.LogError(ex.Message); + Logger?.LogError(ex.Message); return; } @@ -99,13 +98,13 @@ public override async ValueTask ExecuteAsync(IConsole console) } catch (Exception ex) { - Logger.LogError($"Exception type: {ex.GetType().Name}"); + Logger?.LogError($"Exception type: {ex.GetType().Name}"); // TODO: scope this to the right exception type for Win 10 access violation thing // TODO: catch the Win10 DFU error here and change the global provider configuration to "classic" Settings.SaveSetting(SettingsManager.PublicSettings.LibUsb, "classic"); - Logger.LogWarning("This machine requires an older version of libusb. Not to worry, I'll make the change for you, but you will have to re-run this 'firmware write' command."); + Logger?.LogWarning("This machine requires an older version of libusb. Not to worry, I'll make the change for you, but you will have to re-run this 'firmware write' command."); return; } @@ -125,9 +124,13 @@ public override async ValueTask ExecuteAsync(IConsole console) newPort = ports.Except(initialPorts).FirstOrDefault(); } + Logger?.LogInformation($"Meadow found at {newPort}"); + // configure the route to that port for the user Settings.SaveSetting(SettingsManager.PublicSettings.Route, newPort); + await RefreshConnection(); + if (CurrentConnection == null) { Logger?.LogError($"No connection path is defined");