Skip to content

Commit a33aeec

Browse files
authored
Improve output details for JLink devices (#203)
***NO_CI***
1 parent 87a4afc commit a33aeec

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

nanoFirmwareFlasher.Library/JLinkDevice.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Collections.Generic;
88
using System.IO;
99
using System.Linq;
10+
using System.Text;
1011
using System.Text.RegularExpressions;
1112

1213
namespace nanoFramework.Tools.FirmwareFlasher
@@ -89,20 +90,24 @@ public JLinkDevice(string probeId = null)
8990
}
9091

9192
// parse the output to fill in the details
92-
var match = Regex.Match(cliOutput, @"(Device "")(?<deviceid>\w*)("" selected\.)|(Firmware: )(?<firmware>.*)", RegexOptions.Multiline);
93+
var match = Regex.Match(cliOutput, "(Firmware: )(?<firmware>.*)$", RegexOptions.Multiline);
9394
if (match.Success)
9495
{
95-
// grab details
96-
DeviceId = match.Groups["deviceid"].ToString().Trim();
97-
98-
if (match.Groups["firmware"] != null)
96+
if (match.Groups["firmware"].Captures.Count > 0)
9997
{
10098
Firmare = match.Groups["firmware"].ToString().Trim();
10199
}
102100
}
103101

102+
match = Regex.Match(cliOutput, @"(Device "")(?<deviceid>.*)("" selected.)", RegexOptions.Multiline);
103+
if (match.Success)
104+
{
105+
// grab details
106+
DeviceId = match.Groups["deviceid"].ToString().Trim();
107+
}
108+
104109
match = Regex.Match(cliOutput, @"(Hardware version: )(?<hardware>.*)", RegexOptions.Multiline);
105-
if (match.Success && match.Groups["hardware"] != null)
110+
if (match.Success && match.Groups["hardware"].Captures.Count > 0)
106111
{
107112
Hardware = match.Groups["hardware"].ToString().Trim();
108113
}
@@ -175,5 +180,18 @@ public ExitCodes FlashHexFiles(IList<string> files)
175180
files,
176181
ProbeId);
177182
}
183+
184+
/// <inheritdoc/>
185+
public override string ToString()
186+
{
187+
StringBuilder deviceInfo = new();
188+
189+
deviceInfo.AppendLine($"JLink firmware: {Firmare}");
190+
deviceInfo.AppendLine($"JLink hardware: {Hardware}");
191+
deviceInfo.AppendLine($"CPU: {DeviceCPU}");
192+
deviceInfo.AppendLine($"Device ID: {DeviceId}");
193+
194+
return deviceInfo.ToString();
195+
}
178196
}
179197
}

0 commit comments

Comments
 (0)