diff options
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/Connection')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs | 136 | ||||
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/IMachineProvider.cs | 15 |
2 files changed, 13 insertions, 138 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 b2c752ca8..a16e2f649 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs @@ -21,7 +21,6 @@ using Tango.Integration; using Tango.Transport; using System.Threading; using Tango.Core.ExtensionMethods; -using System.IO.Ports; namespace Tango.PPC.Common.Connection { @@ -36,26 +35,6 @@ namespace Tango.PPC.Common.Connection private Thread _connection_thread; private ObservablesContext _context; - /// <summary> - /// Occurs when the machine has connected. - /// </summary> - public event EventHandler MachineConnected; - - /// <summary> - /// Occurs when the machine has disconnected. - /// </summary> - public event EventHandler MachineDisconnected; - - private bool _isConnected; - /// <summary> - /// Gets a value indicating whether the machine is currently connected. - /// </summary> - public bool IsConnected - { - get { return _isConnected; } - private set { _isConnected = value; RaisePropertyChangedAuto(); } - } - private Machine _machine; /// <summary> /// Gets the database machine entity associated with the current machine. @@ -95,24 +74,18 @@ namespace Tango.PPC.Common.Connection /// </summary> public DefaultMachineProvider() { - var settings = SettingsManager.Default.GetOrCreate<PPCSettings>(); - MachineOperator = new MachineOperator(); - MachineOperator.StatusChanged += MachineOperator_StatusChanged; MachineOperator.EnableEventsNotification = true; MachineOperator.EnableJobResume = true; MachineOperator.UseKeepAlive = true; MachineOperator.EnableMachineStatusUpdates = true; - MachineOperator.EnableDiagnostics = true; - MachineOperator.EnablePowerUpSequence = true; - MachineOperator.EnableEmbeddedDebugging = settings.EnableEmbeddedDebugLogs; - MachineOperator.EnableAutomaticThreadLoading = settings.EnableAutomaticThreadLoading; - MachineOperator.JobRunsLogger.JobSource = BL.Enumerations.JobSource.Local; - + MachineOperator.EnableDiagnostics = false; + MachineOperator.EnableEmbeddedDebugging = false; MachineOperator.FirmwareUpgradeMode = Integration.Upgrade.FirmwareUpgradeModes.DFU | Integration.Upgrade.FirmwareUpgradeModes.TFP_PACKAGE; + var settings = SettingsManager.Default.GetOrCreate<PPCSettings>(); + MachineOperator.JobUploadStrategy = settings.JobUploadStrategy; - MachineOperator.JobUnitsMethod = settings.JobUnitsMethod; MachineOperator.GradientGenerationConfiguration.IsEnabled = settings.EnableGradientGeneration; MachineOperator.GradientGenerationConfiguration.ResolutionCM = settings.GradientGenerationResolution; @@ -123,28 +96,8 @@ namespace Tango.PPC.Common.Connection MachineOperator.EnableJobLiquidQuantityValidation = settings.EnableJobLiquidQuantityValidation; } - private void MachineOperator_StatusChanged(object sender, MachineStatuses status) - { - if (status != MachineStatuses.Disconnected) - { - if (!IsConnected) - { - OnMachineConnected(); - } - } - else - { - if (IsConnected) - { - OnMachineDisconnected(); - } - } - } - private async void ConnectionThreadMethod() { - bool fileLoggingDisabled = false; - while (true) { if (MachineOperator.State != TransportComponentState.Connected) @@ -153,10 +106,7 @@ namespace Tango.PPC.Common.Connection { Thread.Sleep(2000); - if (!fileLoggingDisabled) - { - LogManager.Log("Starting machine connection procedure...", LogCategory.Info); - } + LogManager.Log("Starting machine connection procedure...", LogCategory.Debug); var settings = SettingsManager.Default.GetOrCreate<PPCSettings>(); @@ -166,28 +116,22 @@ namespace Tango.PPC.Common.Connection { TimeSpan timeout = TimeSpan.FromSeconds(SettingsManager.Default.GetOrCreate<PPCSettings>().MachineScanningTimeoutSeconds); - LogManager.Log("Scanning for machine on available serial ports...", LogCategory.Info); + LogManager.Log("Scanning for machine on available serial ports...", LogCategory.Debug); 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.Info); + LogManager.Log("Machine discovered on port: " + response.Adapter.Address, LogCategory.Debug); LogManager.Log("Device Information:", LogCategory.Debug); - LogManager.Log(response.Response.DeviceInformation.ToJsonString(), LogCategory.Info); + LogManager.Log(response.Response.DeviceInformation.ToJsonString(), LogCategory.Debug); - LogManager.Log("Disconnecting machine operator...", LogCategory.Info); + LogManager.Log("Disconnecting machine operator...", LogCategory.Debug); await MachineOperator.Disconnect(); MachineOperator.Adapter = response.Adapter; MachineOperator.JobHandlingMode = JobHandlerModes.SettingUp; - LogManager.Log("Connecting machine operator...", LogCategory.Info); + LogManager.Log("Connecting machine operator...", LogCategory.Debug); try { await MachineOperator.Connect(); - - if (MachineOperator.DeviceInformation != null) - { - settings.FirmwareVersion = MachineOperator.DeviceInformation.Version; - settings.Save(); - } } catch (Exception) { @@ -202,17 +146,7 @@ namespace Tango.PPC.Common.Connection } else { - //Perform a pre-test to not overload the log file when machine is off for a long time. - using (SerialPort preCheckSerialPort = new SerialPort(settings.EmbeddedComPort)) - { - preCheckSerialPort.BaudRate = UsbSerialBaudRates.BR_115200.ToInt32(); - preCheckSerialPort.Open(); - preCheckSerialPort.Close(); - fileLoggingDisabled = false; - Thread.Sleep(500); //Wait a little while to not scare the other side?.. - } - - LogManager.Log($"Connecting to machine on {settings.EmbeddedComPort}...", LogCategory.Info); + LogManager.Log($"Connecting to machine on {settings.EmbeddedComPort}...", LogCategory.Debug); UsbTransportAdapter adapter = new UsbTransportAdapter(settings.EmbeddedComPort, UsbSerialBaudRates.BR_115200); MachineOperator.Adapter = adapter; @@ -220,12 +154,6 @@ namespace Tango.PPC.Common.Connection try { await MachineOperator.Connect(); - - if (MachineOperator.DeviceInformation != null) - { - settings.FirmwareVersion = MachineOperator.DeviceInformation.Version; - settings.Save(); - } } catch (Exception) { @@ -256,24 +184,13 @@ namespace Tango.PPC.Common.Connection LogManager.Log("Connecting machine operator..."); await MachineOperator.Connect(); - if (MachineOperator.DeviceInformation != null) - { - settings.FirmwareVersion = MachineOperator.DeviceInformation.Version; - settings.Save(); - } - await Task.Delay(1000); await MachineOperator.UploadHardwareConfiguration(Machine.Configuration.HardwareVersion, Machine.Configuration); } } catch (Exception ex) { - if (!fileLoggingDisabled || LogManager.Categories.Contains(LogCategory.Debug)) - { - LogManager.Log(ex, "Error while trying to scan and connect to the machine."); - LogManager.Log("Application logging of further connection attempts is now disabled and will resume when connection is successful."); - fileLoggingDisabled = true; - } + LogManager.Log(ex, LogCategory.Debug, "Error while trying to scan and connect to the machine."); } } @@ -300,15 +217,6 @@ namespace Tango.PPC.Common.Connection if (Machine != null) { LogManager.Log("First machine entry found. Machine serial number is: " + Machine.SerialNumber + "."); - - if (Machine.IsDemo) - { - LogManager.Log("Machine is in demo mode. Changing firmware upgrade mode to TFP package only."); - MachineOperator.FirmwareUpgradeMode = Integration.Upgrade.FirmwareUpgradeModes.TFP_PACKAGE; - } - - MachineOperator.JobRunsLogger.SetDefaultMachine(Machine); - ConnectToMachine(); } else @@ -339,7 +247,7 @@ namespace Tango.PPC.Common.Connection public async Task SaveMachine() { await _context.SaveChangesAsync(); - Machine = await new MachineBuilder(_context).SetFirst().BuildAsync(); + Machine = await new MachineBuilder(_context).SetFirst().WithSettings().BuildAsync(); TangoMessenger.Default.Send(new MachineSettingsSavedMessage() { Machine = Machine }); } @@ -396,23 +304,5 @@ namespace Tango.PPC.Common.Connection return machineOperator; } - - /// <summary> - /// Called when the machine has connected. - /// </summary> - protected virtual void OnMachineConnected() - { - IsConnected = true; - MachineConnected?.Invoke(this, new EventArgs()); - } - - /// <summary> - /// Called when the machine has disconnected. - /// </summary> - protected virtual void OnMachineDisconnected() - { - IsConnected = false; - MachineDisconnected?.Invoke(this, new EventArgs()); - } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/IMachineProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/IMachineProvider.cs index 774fa7c9e..10180b9cc 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/IMachineProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/IMachineProvider.cs @@ -16,21 +16,6 @@ namespace Tango.PPC.Common.Connection public interface IMachineProvider { /// <summary> - /// Occurs when the machine has connected. - /// </summary> - event EventHandler MachineConnected; - - /// <summary> - /// Occurs when the machine has disconnected. - /// </summary> - event EventHandler MachineDisconnected; - - /// <summary> - /// Gets a value indicating whether the machine is currently connected. - /// </summary> - bool IsConnected { get; } - - /// <summary> /// Gets the database machine entity associated with the current machine. /// </summary> Machine Machine { get; } |
