diff --git a/ApplicationView/ApplicationController.cs b/ApplicationView/ApplicationController.cs index 80d0e829e..98c3b55a4 100644 --- a/ApplicationView/ApplicationController.cs +++ b/ApplicationView/ApplicationController.cs @@ -179,7 +179,7 @@ namespace MatterHackers.MatterControl { UiThread.RunOnIdle(() => { - printer.Settings.printer.Connection.Connect(false); + printer.Settings.printer.Connection.Connect(); }, 2); } diff --git a/PartPreviewWindow/View3D/PrinterBar/PrinterConnectButton.cs b/PartPreviewWindow/View3D/PrinterBar/PrinterConnectButton.cs index 764f6e612..7ab342a02 100644 --- a/PartPreviewWindow/View3D/PrinterBar/PrinterConnectButton.cs +++ b/PartPreviewWindow/View3D/PrinterBar/PrinterConnectButton.cs @@ -32,6 +32,7 @@ using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; using MatterHackers.Localizations; using MatterHackers.MatterControl.PrinterCommunication; +using MatterHackers.MatterControl.PrinterControls.PrinterConnections; using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.SerialPortCommunication.FrostedSerial; @@ -49,6 +50,9 @@ namespace MatterHackers.MatterControl.ActionBar private EventHandler unregisterEvents; private PrinterConfig printer; + private bool listenForConnectFailed = false; + private long connectStartMs; + public PrinterConnectButton(PrinterConfig printer, ThemeConfig theme) { this.printer = printer; @@ -77,6 +81,7 @@ namespace MatterHackers.MatterControl.ActionBar cancelConnectButton.ToolTipText = "Stop trying to connect to the printer.".Localize(); cancelConnectButton.Click += (s, e) => UiThread.RunOnIdle(() => { + listenForConnectFailed = false; ApplicationController.Instance.ConditionalCancelPrint(); cancelConnectButton.Enabled = false; }); @@ -121,6 +126,21 @@ namespace MatterHackers.MatterControl.ActionBar printer.Connection.EnableChanged.RegisterEvent((s, e) => SetVisibleStates(), ref unregisterEvents); printer.Connection.CommunicationStateChanged.RegisterEvent((s, e) => SetVisibleStates(), ref unregisterEvents); + printer.Connection.ConnectionFailed.RegisterEvent((s, e) => + { +#if !__ANDROID__ + // TODO: Someday this functionality should be revised to an awaitable Connect() call in the Connect button that + // shows troubleshooting on failed attempts, rather than hooking the failed event and trying to determine if the + // Connect button started the task + if (listenForConnectFailed + && UiThread.CurrentTimerMs - connectStartMs < 25000) + { + // User initiated connect attempt failed, show port selection dialog + DialogWindow.Show(new SetupStepComPortOne(printer)); + } +#endif + listenForConnectFailed = false; + }, ref unregisterEvents); this.SetVisibleStates(); } @@ -135,6 +155,9 @@ namespace MatterHackers.MatterControl.ActionBar { if (printer.Settings.PrinterSelected) { + listenForConnectFailed = true; + connectStartMs = UiThread.CurrentTimerMs; + #if __ANDROID__ if (!printer.Settings.GetValue(SettingsKey.enable_network_printing) && !FrostedSerialPort.HasPermissionToDevice()) @@ -146,7 +169,7 @@ namespace MatterHackers.MatterControl.ActionBar #endif { printer.Connection.HaltConnectionThread(); - printer.Connection.Connect(true); + printer.Connection.Connect(); } } } @@ -191,6 +214,7 @@ namespace MatterHackers.MatterControl.ActionBar break; default: + listenForConnectFailed = false; SetChildVisible(disconnectButton, true); break; } diff --git a/PrinterCommunication/PrinterConnection.cs b/PrinterCommunication/PrinterConnection.cs index 605ad452d..29bc72e1f 100644 --- a/PrinterCommunication/PrinterConnection.cs +++ b/PrinterCommunication/PrinterConnection.cs @@ -42,7 +42,6 @@ using MatterControl.Printing; using MatterHackers.Agg; using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.PrinterCommunication.Io; -using MatterHackers.MatterControl.PrinterControls.PrinterConnections; using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.SerialPortCommunication; using MatterHackers.SerialPortCommunication.FrostedSerial; @@ -854,7 +853,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication } } - public void Connect(bool showHelpIfNoPort = false) + public void Connect() { // TODO: Consider adding any conditions that would results in a connection failure to this initial test // Start the process of requesting permission and exit if permission is not currently granted @@ -1044,14 +1043,6 @@ namespace MatterHackers.MatterControl.PrinterCommunication OnConnectionFailed( ConnectionFailure.PortUnavailable, $"{this.ComPort} is not available"); - -#if !__ANDROID__ - // Only pop up the com port helper if the USER actually CLICKED the connect button. - if (showHelpIfNoPort) - { - DialogWindow.Show(new SetupStepComPortOne(printer)); - } -#endif } } diff --git a/SetupWizard/AndroidConnectDevicePage.cs b/SetupWizard/AndroidConnectDevicePage.cs index 6040b47ee..24cd63fe9 100644 --- a/SetupWizard/AndroidConnectDevicePage.cs +++ b/SetupWizard/AndroidConnectDevicePage.cs @@ -142,7 +142,7 @@ namespace MatterHackers.MatterControl void ConnectButton_Click(object sender, EventArgs mouseEvent) { - ApplicationController.Instance.ActivePrinter.Connection.Connect(true); + ApplicationController.Instance.ActivePrinter.Connection.Connect(); } void NextButton_Click(object sender, EventArgs mouseEvent)