From cdb3b27f8768445345291427673a6399eca35763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Tue, 23 Aug 2022 00:11:07 +0100 Subject: [PATCH] Add parameter to GetDeviceDetails (#155) --- .../NanoDeviceOperations.cs | 21 ++++++++++++++----- nanoFirmwareFlasher.Tool/Program.cs | 5 ++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/nanoFirmwareFlasher.Library/NanoDeviceOperations.cs b/nanoFirmwareFlasher.Library/NanoDeviceOperations.cs index d27cc11e..fa06dd37 100644 --- a/nanoFirmwareFlasher.Library/NanoDeviceOperations.cs +++ b/nanoFirmwareFlasher.Library/NanoDeviceOperations.cs @@ -48,7 +48,8 @@ public ObservableCollection ListDevices() /// Gets device details of the requested .NET nanoFramework device. /// /// Serial port name where the device is connected to. - /// The object for the requested device. if there is no .NET nanoFramework device in the specified . + /// object for the requested device. + /// The with the operation result. /// /// /// Couldn't connect to specified nano device. @@ -60,10 +61,9 @@ public ObservableCollection ListDevices() /// Couldn't retrieve device details from the nano device. /// /// - public ExitCodes GetDeviceDetails(string serialPort) + public ExitCodes GetDeviceDetails(string serialPort, + ref NanoDeviceBase nanoDevice) { - NanoDeviceBase nanoDevice = null; - if (ReadDetailsFromDevice(serialPort, ref nanoDevice)) { // check that we are in CLR @@ -115,6 +115,11 @@ public ExitCodes GetDeviceDetails(string serialPort) throw new CantConnectToNanoDeviceException("Couldn't connect to specified nano device."); } + if (nanoDevice is null) + { + throw new ArgumentNullException(nameof(nanoDevice)); + } + return ExitCodes.E2000; } @@ -527,8 +532,14 @@ public void Dispose() GC.SuppressFinalize(this); } - private bool ReadDetailsFromDevice(string serialPort, ref NanoDeviceBase nanoDevice) + private bool ReadDetailsFromDevice(string serialPort, + ref NanoDeviceBase nanoDevice) { + if (serialPort is null) + { + throw new ArgumentNullException(nameof(serialPort)); + } + while (!_serialDebuggerPort.IsDevicesEnumerationComplete) { Thread.Sleep(100); diff --git a/nanoFirmwareFlasher.Tool/Program.cs b/nanoFirmwareFlasher.Tool/Program.cs index 5734fdbf..c3a46f3b 100644 --- a/nanoFirmwareFlasher.Tool/Program.cs +++ b/nanoFirmwareFlasher.Tool/Program.cs @@ -356,7 +356,10 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o) { try { - _exitCode = _nanoDeviceOperations.GetDeviceDetails(o.SerialPort); + NanoDeviceBase nanoDevice = null; + _exitCode = _nanoDeviceOperations.GetDeviceDetails( + o.SerialPort, + ref nanoDevice); // done here return;