Skip to content

Commit

Permalink
fix WaitForAttach when we have ever been attached (i.e. DFU -> boot)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctacke committed Sep 28, 2023
1 parent cf59b9a commit 1d10487
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Source/v2/Meadow.Cli/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
},
"Firmware Write all": {
"commandName": "Project",
"commandLineArgs": "firmware write runtime esp"
"commandLineArgs": "firmware write"
},
"Firmware Write version": {
"commandName": "Project",
Expand Down
25 changes: 23 additions & 2 deletions Source/v2/Meadow.Hcom/Connections/SerialConnection.ListenerProc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,30 @@ public override async Task WaitForMeadowAttach(CancellationToken? cancellationTo
if (cancellationToken?.IsCancellationRequested ?? false) throw new TaskCanceledException();
if (timeout <= 0) throw new TimeoutException();

if (State == ConnectionState.MeadowAttached) return;
if (State == ConnectionState.MeadowAttached)
{
if (Device == null)
{
// no device set - this happens when we are waiting for attach from DFU mode
await Attach(cancellationToken, 5);
}

return;
}

await Task.Delay(500);

if (!_port.IsOpen)
{
try
{
Open();
}
catch (Exception ex)
{
Debug.WriteLine($"Unable to open port: {ex.Message}");
}
}
}

throw new TimeoutException();
Expand Down Expand Up @@ -64,7 +85,7 @@ private async Task ListenerProc()

try
{
_port.Open();
Open();
Debug.WriteLine($"Port re-opened");
}
catch
Expand Down

0 comments on commit 1d10487

Please sign in to comment.