Skip to content

Commit cdb3b27

Browse files
authored
Add parameter to GetDeviceDetails (#155)
1 parent 8d13653 commit cdb3b27

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

nanoFirmwareFlasher.Library/NanoDeviceOperations.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public ObservableCollection<NanoDeviceBase> ListDevices()
4848
/// Gets device details of the requested .NET nanoFramework device.
4949
/// </summary>
5050
/// <param name="serialPort">Serial port name where the device is connected to.</param>
51-
/// <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>
51+
/// <param name="nanoDevice"><see cref="NanoDeviceBase"/> object for the requested device.</param>
52+
/// <returns>The <see cref="ExitCodes"/> with the operation result.</returns>
5253
/// <exception cref="CantConnectToNanoDeviceException">
5354
/// <para>
5455
/// Couldn't connect to specified nano device.
@@ -60,10 +61,9 @@ public ObservableCollection<NanoDeviceBase> ListDevices()
6061
/// Couldn't retrieve device details from the nano device.
6162
/// </para>
6263
/// </exception>
63-
public ExitCodes GetDeviceDetails(string serialPort)
64+
public ExitCodes GetDeviceDetails(string serialPort,
65+
ref NanoDeviceBase nanoDevice)
6466
{
65-
NanoDeviceBase nanoDevice = null;
66-
6767
if (ReadDetailsFromDevice(serialPort, ref nanoDevice))
6868
{
6969
// check that we are in CLR
@@ -115,6 +115,11 @@ public ExitCodes GetDeviceDetails(string serialPort)
115115
throw new CantConnectToNanoDeviceException("Couldn't connect to specified nano device.");
116116
}
117117

118+
if (nanoDevice is null)
119+
{
120+
throw new ArgumentNullException(nameof(nanoDevice));
121+
}
122+
118123
return ExitCodes.E2000;
119124
}
120125

@@ -527,8 +532,14 @@ public void Dispose()
527532
GC.SuppressFinalize(this);
528533
}
529534

530-
private bool ReadDetailsFromDevice(string serialPort, ref NanoDeviceBase nanoDevice)
535+
private bool ReadDetailsFromDevice(string serialPort,
536+
ref NanoDeviceBase nanoDevice)
531537
{
538+
if (serialPort is null)
539+
{
540+
throw new ArgumentNullException(nameof(serialPort));
541+
}
542+
532543
while (!_serialDebuggerPort.IsDevicesEnumerationComplete)
533544
{
534545
Thread.Sleep(100);

nanoFirmwareFlasher.Tool/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,10 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
356356
{
357357
try
358358
{
359-
_exitCode = _nanoDeviceOperations.GetDeviceDetails(o.SerialPort);
359+
NanoDeviceBase nanoDevice = null;
360+
_exitCode = _nanoDeviceOperations.GetDeviceDetails(
361+
o.SerialPort,
362+
ref nanoDevice);
360363

361364
// done here
362365
return;

0 commit comments

Comments
 (0)