Skip to content

Commit

Permalink
Add parameter to GetDeviceDetails (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes authored Aug 22, 2022
1 parent 8d13653 commit cdb3b27
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
21 changes: 16 additions & 5 deletions nanoFirmwareFlasher.Library/NanoDeviceOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public ObservableCollection<NanoDeviceBase> ListDevices()
/// Gets device details of the requested .NET nanoFramework device.
/// </summary>
/// <param name="serialPort">Serial port name where the device is connected to.</param>
/// <returns>The <see cref="NanoDeviceBase"/> object for the requested device. <see langword="null"/> if there is no .NET nanoFramework device in the specified <paramref name="serialPort"/>.</returns>
/// <param name="nanoDevice"><see cref="NanoDeviceBase"/> object for the requested device.</param>
/// <returns>The <see cref="ExitCodes"/> with the operation result.</returns>
/// <exception cref="CantConnectToNanoDeviceException">
/// <para>
/// Couldn't connect to specified nano device.
Expand All @@ -60,10 +61,9 @@ public ObservableCollection<NanoDeviceBase> ListDevices()
/// Couldn't retrieve device details from the nano device.
/// </para>
/// </exception>
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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion nanoFirmwareFlasher.Tool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cdb3b27

Please sign in to comment.