Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert SerialConnection.ListenerProc to v2.0.56 version (pre-debuggin… #605

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading