Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
alexischr committed Dec 12, 2024
1 parent 881d02d commit bf4f256
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions Source/v2/Meadow.HCom/Connections/SerialConnection.ListenerProc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ async Task ReOpen() // local function

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

if (timeout-- < 0)
{
return;
Expand All @@ -77,6 +75,7 @@ async Task ReOpen() // local function
{
Debug.WriteLine($"Failed to re-open port");
}
await Task.Delay(100);
}
}

Expand All @@ -92,16 +91,6 @@ 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)
{
Expand Down Expand Up @@ -351,7 +340,9 @@ async Task ReOpen() // local function
catch (OperationCanceledException)
{
// this happens on disconnect - could be cable pulled, could be device reset
Debug.WriteLine($"Operation Cancelled");
Debug.WriteLine($"Operation Cancelled. Port open: {_port.IsOpen}");
if (!_port.IsOpen) { await ReOpen();
}
}
catch (Exception ex)
{
Expand Down

0 comments on commit bf4f256

Please sign in to comment.