aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection
diff options
context:
space:
mode:
authorAvi Levkovich <avi@twine-s.com>2020-08-31 12:03:11 +0300
committerAvi Levkovich <avi@twine-s.com>2020-08-31 12:03:11 +0300
commit5c19a9bef046ff080a9a7008bd4f39e2a13e4ccb (patch)
tree500e4b50dd615b86cad12c7b11439ba007b20668 /Software/Visual_Studio/PPC/Tango.PPC.Common/Connection
parent29b08a41f29655561ab83d8b454ea5fb6227ad7a (diff)
parent751ec679b65431ab3ce13f1c5c58cb0891b2fdbe (diff)
downloadTango-5c19a9bef046ff080a9a7008bd4f39e2a13e4ccb.tar.gz
Tango-5c19a9bef046ff080a9a7008bd4f39e2a13e4ccb.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
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;
}
}
}