From bf4f2569e9c2c9be328f1217c417c6469250ff8b Mon Sep 17 00:00:00 2001 From: Alexis Christoforides Date: Wed, 11 Dec 2024 21:12:25 -0800 Subject: [PATCH] WIP --- .../SerialConnection.ListenerProc.cs | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/Source/v2/Meadow.HCom/Connections/SerialConnection.ListenerProc.cs b/Source/v2/Meadow.HCom/Connections/SerialConnection.ListenerProc.cs index 0f438efe..56f53d62 100644 --- a/Source/v2/Meadow.HCom/Connections/SerialConnection.ListenerProc.cs +++ b/Source/v2/Meadow.HCom/Connections/SerialConnection.ListenerProc.cs @@ -61,8 +61,6 @@ async Task ReOpen() // local function while (!_port.IsOpen) { - await Task.Delay(500); - if (timeout-- < 0) { return; @@ -77,6 +75,7 @@ async Task ReOpen() // local function { Debug.WriteLine($"Failed to re-open port"); } + await Task.Delay(100); } } @@ -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) { @@ -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) {