aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-30 15:23:44 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-30 15:23:44 +0300
commit66dc46ad7547c9d51fef406186a705dce0ccd7a3 (patch)
tree26ed43db9de56df372f8678facb71595fbb70004 /Software/Visual_Studio/PPC/Tango.PPC.Common/Connection
parent049d3b2fd82020539a4967fff1288704ca915fd8 (diff)
downloadTango-66dc46ad7547c9d51fef406186a705dce0ccd7a3.tar.gz
Tango-66dc46ad7547c9d51fef406186a705dce0ccd7a3.zip
Improved connection attempts file logging optimization by pre-testing using a simple open/close serial port. Logs can still be viewed using "Debug" on tech module.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/Connection')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs42
1 files changed, 19 insertions, 23 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 794e37694..244d26f28 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs
@@ -21,6 +21,7 @@ using Tango.Integration;
using Tango.Transport;
using System.Threading;
using Tango.Core.ExtensionMethods;
+using System.IO.Ports;
namespace Tango.PPC.Common.Connection
{
@@ -34,7 +35,6 @@ namespace Tango.PPC.Common.Connection
private bool _isInitialized;
private Thread _connection_thread;
private ObservablesContext _context;
- private bool disableConnectionFileLogging;
/// <summary>
/// Occurs when the machine has connected.
@@ -143,23 +143,21 @@ namespace Tango.PPC.Common.Connection
private async void ConnectionThreadMethod()
{
+ bool fileLoggingDisabled = false;
+
while (true)
{
if (MachineOperator.State != TransportComponentState.Connected)
{
- var fileLogger = LogManager.RegisteredLoggers.FirstOrDefault(x => x.GetType() == typeof(FileLogger));
-
try
{
Thread.Sleep(2000);
- if (fileLogger != null && disableConnectionFileLogging)
+ if (!fileLoggingDisabled)
{
- fileLogger.Enabled = false;
+ LogManager.Log("Starting machine connection procedure...", LogCategory.Info);
}
- LogManager.Log("Starting machine connection procedure...", LogCategory.Info);
-
var settings = SettingsManager.Default.GetOrCreate<PPCSettings>();
if (!Machine.IsDemo)
@@ -190,8 +188,6 @@ namespace Tango.PPC.Common.Connection
settings.FirmwareVersion = MachineOperator.DeviceInformation.Version;
settings.Save();
}
-
- disableConnectionFileLogging = false;
}
catch (Exception)
{
@@ -206,6 +202,16 @@ 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);
UsbTransportAdapter adapter = new UsbTransportAdapter(settings.EmbeddedComPort, UsbSerialBaudRates.BR_115200);
@@ -220,8 +226,6 @@ namespace Tango.PPC.Common.Connection
settings.FirmwareVersion = MachineOperator.DeviceInformation.Version;
settings.Save();
}
-
- disableConnectionFileLogging = false;
}
catch (Exception)
{
@@ -252,8 +256,6 @@ namespace Tango.PPC.Common.Connection
LogManager.Log("Connecting machine operator...");
await MachineOperator.Connect();
- disableConnectionFileLogging = false;
-
if (MachineOperator.DeviceInformation != null)
{
settings.FirmwareVersion = MachineOperator.DeviceInformation.Version;
@@ -266,17 +268,11 @@ namespace Tango.PPC.Common.Connection
}
catch (Exception ex)
{
- 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)
+ if (!fileLoggingDisabled || LogManager.Categories.Contains(LogCategory.Debug))
{
- fileLogger.Enabled = true;
+ 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;
}
}
}