Skip to content

Commit

Permalink
Revert SerialConnection.ListenerProc to v2.0.56 version (pre-debuggin…
Browse files Browse the repository at this point in the history
…g changes)
  • Loading branch information
adrianstevens committed Nov 28, 2024
1 parent b2efcde commit 084e388
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Source/v2/Meadow.Cli/Meadow.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Authors>Wilderness Labs, Inc</Authors>
<Company>Wilderness Labs, Inc</Company>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>2.0.61.0</PackageVersion>
<PackageVersion>2.0.62.0</PackageVersion>
<Platforms>AnyCPU</Platforms>
<PackageProjectUrl>http://developer.wildernesslabs.co/Meadow/Meadow.CLI/</PackageProjectUrl>
<RepositoryUrl>https://github.com/WildernessLabs/Meadow.CLI</RepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ namespace Meadow.CLI;

public static class Constants
{
public const string CLI_VERSION = "2.0.61.0";
public const string CLI_VERSION = "2.0.62.0";
}
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 @@ -153,7 +153,7 @@
},
"Firmware Write version": {
"commandName": "Project",
"commandLineArgs": "firmware write -v 1.9.1.8"
"commandLineArgs": "firmware write -v 2.0.0.2"
},
"Firmware Write runtime": {
"commandName": "Project",
Expand Down
68 changes: 26 additions & 42 deletions Source/v2/Meadow.HCom/Connections/SerialConnection.ListenerProc.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Meadow.Hcom
namespace Meadow.Hcom
{
public partial class SerialConnection
{
Expand All @@ -8,7 +8,7 @@ public partial class SerialConnection

public override async Task WaitForMeadowAttach(CancellationToken? cancellationToken)
{
var timeout = 50;
var timeout = 500;

while (timeout-- > 0)
{
Expand All @@ -26,7 +26,7 @@ public override async Task WaitForMeadowAttach(CancellationToken? cancellationTo
return;
}

await Task.Delay(100);
await Task.Delay(20);

if (!_port.IsOpen)
{
Expand All @@ -52,34 +52,6 @@ private async Task ListenerProc()
var delimiter = new byte[] { 0x00 };
var receivedLength = 0;

async Task ReOpen() // local function
{
Debug.WriteLine($"Device reset detected");

var timeout = 20;
try { _port.Close(); } catch { } // Swallow any exceptions on close - there is nothing we can do about it

while (!_port.IsOpen)
{
await Task.Delay(500);

if (timeout-- < 0)
{
return;
}

try
{
Open();
Debug.WriteLine($"Port re-opened");
}
catch
{
Debug.WriteLine($"Failed to re-open port");
}
}
}

while (!_isDisposed)
{
if (_port.IsOpen)
Expand All @@ -92,20 +64,32 @@ async Task ReOpen() // local function
try
{
receivedLength = _port.Read(readBuffer, 0, readBuffer.Length);
if (receivedLength == 0)
{
Debug.WriteLine($"Received 0 bytes");
throw new OperationCanceledException();
}
}
catch (OperationCanceledException)
{
await ReOpen();
goto read;
}
catch (InvalidOperationException)
{
await ReOpen();
Debug.WriteLine($"Device reset detected");

var timeout = 20;

while (!_port.IsOpen)
{
await Task.Delay(500);

if (timeout-- < 0)
{
return;
}

try
{
Open();
Debug.WriteLine($"Port re-opened");
}
catch
{
Debug.WriteLine($"Failed to re-open port");
}
}
goto read;
}

Expand Down

0 comments on commit 084e388

Please sign in to comment.