fix: improve formatting and logging in ComPortController

This commit is contained in:
jkdevito
2025-10-27 16:46:09 -05:00
parent d01eb03890
commit 89e893b3b7

View File

@@ -9,6 +9,7 @@ using Crestron.SimplSharpPro;
using PepperDash.Core;
using Serilog.Events;
using PepperDash.Core.Logging;
using Crestron.SimplSharpPro.GeneralIO;
namespace PepperDash.Essentials.Core
@@ -72,7 +73,7 @@ namespace PepperDash.Essentials.Core
Debug.LogMessage(LogEventLevel.Information, this, "Configured com Port for this device does not exist.");
return;
}
if (Port.Parent is CrestronControlSystem)
if (Port.Parent is CrestronControlSystem || Port.Parent is CenIoCom102)
{
var result = Port.Register();
if (result != eDeviceRegistrationUnRegistrationResponse.Success)
@@ -82,19 +83,6 @@ namespace PepperDash.Essentials.Core
}
}
Port.PropertyChanged += (s, e) =>
{
this.LogInformation($"RegisterAndConfigureComPort: PropertyChanged Fired >> comPort-'{Port.ID}', Property Changed-'{e.Property}', Value Changed-'{e.Value}'");
this.LogInformation($"RegisterAndConfigureComPort: deviceName-'{Port.DeviceName}', parentDevice-'{Port.ParentDevice}', parent-`{Port.Parent}`, online-`{Port.IsOnline}`, preset-`{Port.Present}`, supportedBaudRates-'{Port.SupportedBaudRates}'");
};
Port.ExtendedInformationChanged += (s, e) =>
{
this.LogInformation($"RegisterAndConfigureComPort: ExtendedInformationChanged Fired >> comPort-'{Port.ID}', {e.Protocol} using {e.BaudRate},{e.Parity},{e.DataBits},{e.StopBits}, HW Handshake-'{e.HardwareHandshakeSetting}', SW Handshake-'{e.SoftwareHandshakeSetting}'");
};
this.LogInformation($"RegisterAndConfigureComPort: Configuring comPort-'{Port.ID}' using Spec {Spec.BaudRate},{Spec.DataBits},{Spec.Parity},{Spec.StopBits}, HW Handshake-'{Spec.HardwareHandShake}', SW Handshake-'{Spec.SoftwareHandshake}'");
var specResult = Port.SetComPortSpec(Spec);
if (specResult != 0)
{
@@ -102,7 +90,39 @@ namespace PepperDash.Essentials.Core
return;
}
this.LogInformation($"RegisterAndConfigureComPort: comPort-'{Port.ID}' configured successfully using {Port.BaudRate},{Port.DataBits},{Port.Parity},{Port.StopBits}, HW Handshake-'{Port.HwHandShake}', SW Handshake-'{Port.SwHandShake}'");
//this.LogInformation($"RegisterAndConfigureComPort: Port.Parent-'{Port.Parent}', Port.ParentDevice-'{Port.ParentDevice}'");
// if (Port.Parent is CenIoCom102)
// {
// this.LogInformation($"RegisterAndConfigureComPort: ");
// Port.Register();
// Port.PropertyChanged += (s, e) =>
// {
// this.LogInformation($"RegisterAndConfigureComPort: PropertyChanged Fired >> comPort-'{Port.ID}', Property Changed-'{e.Property}', Value Changed-'{e.Value}'");
// this.LogInformation($"RegisterAndConfigureComPort: deviceName-'{Port.DeviceName}', parentDevice-'{Port.ParentDevice}', parent-`{Port.Parent}`, online-`{Port.IsOnline}`, preset-`{Port.Present}`, supportedBaudRates-'{Port.SupportedBaudRates}'");
// };
// Port.ExtendedInformationChanged += (s, e) =>
// {
// this.LogInformation($@"RegisterAndConfigureComPort: ExtendedInformationChanged Fired >> comPort-'{Port.ID}', {e.Protocol} using `
// {e.BaudRate},
// {e.Parity},
// {e.DataBits},
// {e.StopBits},
// HW Handshake-'{e.HardwareHandshakeSetting}',
// SW Handshake-'{e.SoftwareHandshakeSetting}'");
// };
// this.LogInformation($@"RegisterAndConfigureComPort: Configuring comPort-'{Port.ID}' using Spec
// {Spec.BaudRate},
// {Spec.DataBits},
// {Spec.Parity},
// {Spec.StopBits},
// HW Handshake-'{Spec.HardwareHandShake}',
// SW Handshake-'{Spec.SoftwareHandshake}'");
// }
Port.SerialDataReceived += Port_SerialDataReceived;
}
@@ -139,7 +159,7 @@ namespace PepperDash.Essentials.Core
eventSubscribed = true;
}
if(!eventSubscribed) Debug.LogMessage(LogEventLevel.Warning, this, "Received data but no handler is registered");
if (!eventSubscribed) Debug.LogMessage(LogEventLevel.Warning, this, "Received data but no handler is registered");
}
/// <summary>