From ca0ad09b6181c750fcd2e85e5ae5ac620c59f65c Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Fri, 29 Sep 2023 12:35:32 -0500 Subject: [PATCH] added serial connection manager retry (cherry picked from commit 9370420e863730c1bacde89731895b535e314103) --- .../v2/Meadow.Cli/MeadowConnectionManager.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Source/v2/Meadow.Cli/MeadowConnectionManager.cs b/Source/v2/Meadow.Cli/MeadowConnectionManager.cs index 361c4b09..c294b721 100644 --- a/Source/v2/Meadow.Cli/MeadowConnectionManager.cs +++ b/Source/v2/Meadow.Cli/MeadowConnectionManager.cs @@ -54,7 +54,23 @@ public MeadowConnectionManager(ISettingsManager settingsManager) } else { - _currentConnection = new SerialConnection(route); + var retryCount = 0; + + get_serial_connection: + try + { + _currentConnection = new SerialConnection(route); + } + catch + { + retryCount++; + if (retryCount > 10) + { + throw new Exception($"Cannot find port {route}"); + } + Thread.Sleep(500); + goto get_serial_connection; + } } return _currentConnection;