Skip to content

Commit bcfcc4a

Browse files
authored
Improve list devices (#216)
***NO_CI***
1 parent fd62d99 commit bcfcc4a

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,14 @@ To get the details of a nano device connected to a serial port.
343343
nanoff --nanodevice --devicedetails --serialport COM9
344344
```
345345

346+
### List connected nano devices
347+
348+
To get a list of connected nano devices. If more details are required pass verbose option above normal.
349+
350+
```console
351+
nanoff --listdevices | -v d
352+
```
353+
346354
## Common options
347355

348356
### Pre-check if target fits connected device

nanoFirmwareFlasher.Library/NanoDeviceOperations.cs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,56 @@ public NanoDeviceOperations()
3535
/// <summary>
3636
/// List connected .NET nanoFramework devices.
3737
/// </summary>
38+
/// <param name="getDeviceDetails">Set to <see langword="true"/> to get details from devices.</param>
3839
/// <returns>An observable collection of <see cref="NanoDeviceBase"/>. devices</returns>
39-
public ObservableCollection<NanoDeviceBase> ListDevices()
40+
public ObservableCollection<NanoDeviceBase> ListDevices(bool getDeviceDetails)
4041
{
42+
// start device watchers
43+
_serialDebuggerPort.StartDeviceWatchers();
44+
4145
while (!_serialDebuggerPort.IsDevicesEnumerationComplete)
4246
{
4347
Thread.Sleep(100);
4448
}
4549

50+
if (getDeviceDetails)
51+
{
52+
// get device details
53+
foreach (var device in _serialDebuggerPort.NanoFrameworkDevices)
54+
{
55+
_ = device.DebugEngine.Connect(
56+
false,
57+
true);
58+
59+
// check that we are in CLR
60+
if (device.DebugEngine.IsConnectedTonanoCLR)
61+
{
62+
try
63+
{
64+
// get device info
65+
_ = device.GetDeviceInfo(true);
66+
}
67+
catch
68+
{
69+
// no need to report this, just move on
70+
}
71+
}
72+
else
73+
{
74+
// we are in booter, can only get TargetInfo
75+
try
76+
{
77+
// get device info
78+
_ = device.DebugEngine?.TargetInfo;
79+
}
80+
catch
81+
{
82+
// no need to report this, just move on
83+
}
84+
}
85+
}
86+
}
87+
4688
return _serialDebuggerPort.NanoFrameworkDevices;
4789
}
4890

nanoFirmwareFlasher.Tool/Program.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
313313

314314
try
315315
{
316-
var connectedDevices = _nanoDeviceOperations.ListDevices();
316+
var connectedDevices = _nanoDeviceOperations.ListDevices(_verbosityLevel > VerbosityLevel.Normal);
317317

318318
if (connectedDevices.Count() == 0)
319319
{
@@ -327,6 +327,38 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
327327
foreach (var nanoDevice in connectedDevices)
328328
{
329329
Console.WriteLine($"{nanoDevice.Description}");
330+
331+
if (_verbosityLevel >= VerbosityLevel.Normal)
332+
{
333+
// check that we are in CLR
334+
if (nanoDevice.DebugEngine.IsConnectedTonanoCLR)
335+
{
336+
// we have to have a valid device info
337+
if (nanoDevice.DeviceInfo.Valid)
338+
{
339+
Console.WriteLine($" Target: {nanoDevice.DeviceInfo.TargetName?.ToString()}");
340+
Console.WriteLine($" Platform: {nanoDevice.DeviceInfo.Platform?.ToString()}");
341+
Console.WriteLine($" Date: {nanoDevice.DebugEngine.Capabilities.SoftwareVersion.BuildDate ?? "unknown"}");
342+
Console.WriteLine($" Type: {nanoDevice.DebugEngine.Capabilities.SolutionReleaseInfo.VendorInfo ?? "unknown"}");
343+
Console.WriteLine($" CLR Version: {nanoDevice.DeviceInfo.SolutionBuildVersion}");
344+
}
345+
}
346+
else
347+
{
348+
// we are in booter, can only get TargetInfo
349+
// we have to have a valid device info
350+
if (nanoDevice.DebugEngine.TargetInfo != null)
351+
{
352+
Console.WriteLine($" Target: {nanoDevice.DebugEngine.TargetInfo.TargetName}");
353+
Console.WriteLine($" Platform: {nanoDevice.DebugEngine.TargetInfo.PlatformName}");
354+
Console.WriteLine($" Type: {nanoDevice.DebugEngine.TargetInfo.PlatformInfo}");
355+
Console.WriteLine($" CLR Version: {nanoDevice.DebugEngine.TargetInfo.CLRVersion}");
356+
Console.WriteLine($" Booter Version: {nanoDevice.DebugEngine.TargetInfo.CLRVersion}");
357+
}
358+
}
359+
360+
Console.WriteLine("");
361+
}
330362
}
331363

332364
Console.WriteLine("------------------------------------------");

0 commit comments

Comments
 (0)