diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-03-28 10:02:12 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-03-28 10:02:12 +0300 |
| commit | 3d6a882cf14f36297d8b379e0fdf65376064edf7 (patch) | |
| tree | 91728997624076d0eb0d6b38df011851e559a838 /Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs | |
| parent | 888d3037722f80b00c12e140ba101f58661ec4b6 (diff) | |
| download | Tango-3d6a882cf14f36297d8b379e0fdf65376064edf7.tar.gz Tango-3d6a882cf14f36297d8b379e0fdf65376064edf7.zip | |
Many changes and improvements.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs index acdf20fa8..1c0c52196 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs @@ -34,6 +34,7 @@ namespace Tango.PPC.Common.Connection private bool _isInitialized; private Thread _connection_thread; private ObservablesContext _context; + private bool disableConnectionFileLogging; private Machine _machine; /// <summary> @@ -106,11 +107,18 @@ namespace Tango.PPC.Common.Connection { if (MachineOperator.State != TransportComponentState.Connected) { + var fileLogger = LogManager.RegisteredLoggers.FirstOrDefault(x => x.GetType() == typeof(FileLogger)); + try { Thread.Sleep(2000); - LogManager.Log("Starting machine connection procedure...", LogCategory.Debug); + if (fileLogger != null && disableConnectionFileLogging) + { + fileLogger.Enabled = false; + } + + LogManager.Log("Starting machine connection procedure...", LogCategory.Info); var settings = SettingsManager.Default.GetOrCreate<PPCSettings>(); @@ -120,19 +128,19 @@ namespace Tango.PPC.Common.Connection { TimeSpan timeout = TimeSpan.FromSeconds(SettingsManager.Default.GetOrCreate<PPCSettings>().MachineScanningTimeoutSeconds); - LogManager.Log("Scanning for machine on available serial ports...", LogCategory.Debug); + LogManager.Log("Scanning for machine on available serial ports...", LogCategory.Info); Transport.Discovery.UsbCommunicationScanner<ConnectRequest, ConnectResponse> scanner = new Transport.Discovery.UsbCommunicationScanner<ConnectRequest, ConnectResponse>(UsbSerialBaudRates.BR_115200); var response = await scanner.Scan(new ConnectRequest() { Password = "1234" }, settings.EmbeddedDeviceHint, timeout); - LogManager.Log("Machine discovered on port: " + response.Adapter.Address, LogCategory.Debug); + LogManager.Log("Machine discovered on port: " + response.Adapter.Address, LogCategory.Info); LogManager.Log("Device Information:", LogCategory.Debug); - LogManager.Log(response.Response.DeviceInformation.ToJsonString(), LogCategory.Debug); + LogManager.Log(response.Response.DeviceInformation.ToJsonString(), LogCategory.Info); - LogManager.Log("Disconnecting machine operator...", LogCategory.Debug); + LogManager.Log("Disconnecting machine operator...", LogCategory.Info); await MachineOperator.Disconnect(); MachineOperator.Adapter = response.Adapter; MachineOperator.JobHandlingMode = JobHandlerModes.SettingUp; - LogManager.Log("Connecting machine operator...", LogCategory.Debug); + LogManager.Log("Connecting machine operator...", LogCategory.Info); try { await MachineOperator.Connect(); @@ -142,6 +150,8 @@ namespace Tango.PPC.Common.Connection settings.FirmwareVersion = MachineOperator.DeviceInformation.Version; settings.Save(); } + + disableConnectionFileLogging = false; } catch (Exception) { @@ -156,7 +166,7 @@ namespace Tango.PPC.Common.Connection } else { - LogManager.Log($"Connecting to machine on {settings.EmbeddedComPort}...", LogCategory.Debug); + LogManager.Log($"Connecting to machine on {settings.EmbeddedComPort}...", LogCategory.Info); UsbTransportAdapter adapter = new UsbTransportAdapter(settings.EmbeddedComPort, UsbSerialBaudRates.BR_115200); MachineOperator.Adapter = adapter; @@ -170,6 +180,8 @@ namespace Tango.PPC.Common.Connection settings.FirmwareVersion = MachineOperator.DeviceInformation.Version; settings.Save(); } + + disableConnectionFileLogging = false; } catch (Exception) { @@ -200,6 +212,8 @@ namespace Tango.PPC.Common.Connection LogManager.Log("Connecting machine operator..."); await MachineOperator.Connect(); + disableConnectionFileLogging = false; + if (MachineOperator.DeviceInformation != null) { settings.FirmwareVersion = MachineOperator.DeviceInformation.Version; @@ -212,7 +226,18 @@ namespace Tango.PPC.Common.Connection } catch (Exception ex) { - LogManager.Log(ex, LogCategory.Debug, "Error while trying to scan and connect to the machine."); + LogManager.Log(ex, "Error while trying to scan and connect to the machine."); + LogManager.Log("File logging of further connection attempts is now disabled and will resume when connection is successful."); + disableConnectionFileLogging = true; + } + finally + { + await Task.Delay(100); + + if (fileLogger != null) + { + fileLogger.Enabled = true; + } } } |
