From d01eb0389039f5cbbddab2b7617094c654af6b39 Mon Sep 17 00:00:00 2001 From: jkdevito Date: Mon, 27 Oct 2025 14:06:20 -0500 Subject: [PATCH 1/8] feat: enhance ComPortController with detailed logging on configuration changes --- .../Comm and IR/ComPortController.cs | 49 +++++++++++++------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs b/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs index cc57fa19..15050ebf 100644 --- a/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs +++ b/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs @@ -8,6 +8,7 @@ using Crestron.SimplSharpPro; using PepperDash.Core; using Serilog.Events; +using PepperDash.Core.Logging; namespace PepperDash.Essentials.Core @@ -71,23 +72,39 @@ namespace PepperDash.Essentials.Core Debug.LogMessage(LogEventLevel.Information, this, "Configured com Port for this device does not exist."); return; } - if (Port.Parent is CrestronControlSystem) - { - var result = Port.Register(); - if (result != eDeviceRegistrationUnRegistrationResponse.Success) - { - Debug.LogMessage(LogEventLevel.Information, this, "ERROR: Cannot register Com port: {0}", result); - return; // false - } - } + if (Port.Parent is CrestronControlSystem) + { + var result = Port.Register(); + if (result != eDeviceRegistrationUnRegistrationResponse.Success) + { + Debug.LogMessage(LogEventLevel.Information, this, "ERROR: Cannot register Com port: {0}", result); + return; // false + } + } - var specResult = Port.SetComPortSpec(Spec); - if (specResult != 0) - { - Debug.LogMessage(LogEventLevel.Information, this, "WARNING: Cannot set comspec"); - return; - } - Port.SerialDataReceived += Port_SerialDataReceived; + 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) + { + Debug.LogMessage(LogEventLevel.Information, this, "WARNING: Cannot set comspec"); + 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}'"); + + Port.SerialDataReceived += Port_SerialDataReceived; } ~ComPortController() From 89e893b3b7ea6a02446f57c911ee06f9f31dadc7 Mon Sep 17 00:00:00 2001 From: jkdevito Date: Mon, 27 Oct 2025 16:46:09 -0500 Subject: [PATCH 2/8] fix: improve formatting and logging in ComPortController --- .../Comm and IR/ComPortController.cs | 230 ++++++++++-------- 1 file changed, 125 insertions(+), 105 deletions(-) diff --git a/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs b/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs index 15050ebf..746fd317 100644 --- a/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs +++ b/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs @@ -9,52 +9,53 @@ using Crestron.SimplSharpPro; using PepperDash.Core; using Serilog.Events; using PepperDash.Core.Logging; +using Crestron.SimplSharpPro.GeneralIO; namespace PepperDash.Essentials.Core { - /// - /// Represents a ComPortController - /// + /// + /// Represents a ComPortController + /// public class ComPortController : Device, IBasicCommunicationWithStreamDebugging { - /// - /// Gets or sets the StreamDebugging - /// - public CommunicationStreamDebugging StreamDebugging { get; private set; } + /// + /// Gets or sets the StreamDebugging + /// + public CommunicationStreamDebugging StreamDebugging { get; private set; } public event EventHandler BytesReceived; public event EventHandler TextReceived; - /// - /// Gets or sets the IsConnected - /// + /// + /// Gets or sets the IsConnected + /// public bool IsConnected { get { return true; } } ComPort Port; ComPort.ComPortSpec Spec; - public ComPortController(string key, Func postActivationFunc, - ComPort.ComPortSpec spec, EssentialsControlPropertiesConfig config) : base(key) - { - StreamDebugging = new CommunicationStreamDebugging(key); + public ComPortController(string key, Func postActivationFunc, + ComPort.ComPortSpec spec, EssentialsControlPropertiesConfig config) : base(key) + { + StreamDebugging = new CommunicationStreamDebugging(key); - Spec = spec; + Spec = spec; - AddPostActivationAction(() => - { - Port = postActivationFunc(config); + AddPostActivationAction(() => + { + Port = postActivationFunc(config); - RegisterAndConfigureComPort(); - }); - } + RegisterAndConfigureComPort(); + }); + } public ComPortController(string key, ComPort port, ComPort.ComPortSpec spec) : base(key) { if (port == null) { - Debug.LogMessage(LogEventLevel.Information, this, "ERROR: Invalid com port, continuing but comms will not function"); + Debug.LogMessage(LogEventLevel.Information, this, "ERROR: Invalid com port, continuing but comms will not function"); return; } @@ -65,14 +66,14 @@ namespace PepperDash.Essentials.Core RegisterAndConfigureComPort(); } - private void RegisterAndConfigureComPort() - { - if (Port == null) - { - Debug.LogMessage(LogEventLevel.Information, this, "Configured com Port for this device does not exist."); - return; - } - if (Port.Parent is CrestronControlSystem) + private void RegisterAndConfigureComPort() + { + if (Port == null) + { + Debug.LogMessage(LogEventLevel.Information, this, "Configured com Port for this device does not exist."); + return; + } + 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,50 +90,82 @@ 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; - } + } - ~ComPortController() + ~ComPortController() { Port.SerialDataReceived -= Port_SerialDataReceived; } void Port_SerialDataReceived(ComPort ReceivingComPort, ComPortSerialDataEventArgs args) { - OnDataReceived(args.SerialData); + OnDataReceived(args.SerialData); } - void OnDataReceived(string s) - { + void OnDataReceived(string s) + { var eventSubscribed = false; - var bytesHandler = BytesReceived; - if (bytesHandler != null) - { - var bytes = Encoding.GetEncoding(28591).GetBytes(s); + var bytesHandler = BytesReceived; + if (bytesHandler != null) + { + var bytes = Encoding.GetEncoding(28591).GetBytes(s); if (StreamDebugging.RxStreamDebuggingIsEnabled) Debug.LogMessage(LogEventLevel.Information, this, "Received: '{0}'", ComTextHelper.GetEscapedText(bytes)); - bytesHandler(this, new GenericCommMethodReceiveBytesArgs(bytes)); + bytesHandler(this, new GenericCommMethodReceiveBytesArgs(bytes)); eventSubscribed = true; - } - var textHandler = TextReceived; - if (textHandler != null) - { + } + var textHandler = TextReceived; + if (textHandler != null) + { if (StreamDebugging.RxStreamDebuggingIsEnabled) Debug.LogMessage(LogEventLevel.Information, this, "Received: '{0}'", s); - textHandler(this, new GenericCommMethodReceiveTextArgs(s)); + textHandler(this, new GenericCommMethodReceiveTextArgs(s)); 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"); + } - /// - /// Deactivate method - /// - /// + /// + /// Deactivate method + /// + /// public override bool Deactivate() { return Port.UnRegister() == eDeviceRegistrationUnRegistrationResponse.Success; @@ -153,70 +173,70 @@ namespace PepperDash.Essentials.Core #region IBasicCommunication Members - /// - /// SendText method - /// + /// + /// SendText method + /// public void SendText(string text) { if (Port == null) return; - if (StreamDebugging.TxStreamDebuggingIsEnabled) - Debug.LogMessage(LogEventLevel.Information, this, "Sending {0} characters of text: '{1}'", text.Length, text); - Port.Send(text); + if (StreamDebugging.TxStreamDebuggingIsEnabled) + Debug.LogMessage(LogEventLevel.Information, this, "Sending {0} characters of text: '{1}'", text.Length, text); + Port.Send(text); } - /// - /// SendBytes method - /// + /// + /// SendBytes method + /// public void SendBytes(byte[] bytes) { if (Port == null) return; var text = Encoding.GetEncoding(28591).GetString(bytes, 0, bytes.Length); - if (StreamDebugging.TxStreamDebuggingIsEnabled) - Debug.LogMessage(LogEventLevel.Information, this, "Sending {0} bytes: '{1}'", bytes.Length, ComTextHelper.GetEscapedText(bytes)); + if (StreamDebugging.TxStreamDebuggingIsEnabled) + Debug.LogMessage(LogEventLevel.Information, this, "Sending {0} bytes: '{1}'", bytes.Length, ComTextHelper.GetEscapedText(bytes)); Port.Send(text); } - /// - /// Connect method - /// + /// + /// Connect method + /// public void Connect() - { + { } - /// - /// Disconnect method - /// + /// + /// Disconnect method + /// public void Disconnect() { } #endregion - /// - /// - /// - /// - /// - /// SimulateReceive method - /// - public void SimulateReceive(string s) - { - // split out hex chars and build string - var split = Regex.Split(s, @"(\\[Xx][0-9a-fA-F][0-9a-fA-F])"); - StringBuilder b = new StringBuilder(); - foreach (var t in split) - { - if (t.StartsWith(@"\") && t.Length == 4) - b.Append((char)(Convert.ToByte(t.Substring(2, 2), 16))); - else - b.Append(t); - } + /// + /// + /// + /// + /// + /// SimulateReceive method + /// + public void SimulateReceive(string s) + { + // split out hex chars and build string + var split = Regex.Split(s, @"(\\[Xx][0-9a-fA-F][0-9a-fA-F])"); + StringBuilder b = new StringBuilder(); + foreach (var t in split) + { + if (t.StartsWith(@"\") && t.Length == 4) + b.Append((char)(Convert.ToByte(t.Substring(2, 2), 16))); + else + b.Append(t); + } - OnDataReceived(b.ToString()); - } + OnDataReceived(b.ToString()); + } } } \ No newline at end of file From 151a90c9beeaa18bf10e1939b6123cd30e2c209c Mon Sep 17 00:00:00 2001 From: jkdevito Date: Mon, 27 Oct 2025 17:13:43 -0500 Subject: [PATCH 3/8] refactor: streamline ComPort registration and configuration logic with enhanced logging --- .../Comm and IR/ComPortController.cs | 80 +++++++++---------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs b/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs index 746fd317..fcd1bdde 100644 --- a/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs +++ b/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs @@ -73,56 +73,56 @@ namespace PepperDash.Essentials.Core Debug.LogMessage(LogEventLevel.Information, this, "Configured com Port for this device does not exist."); return; } - if (Port.Parent is CrestronControlSystem || Port.Parent is CenIoCom102) + // TODO [ ] - Verify nothing blows up without the `if` check + //if (Port.Parent is CrestronControlSystem || Port.Parent is CenIoCom102) + //{ + var result = Port.Register(); + if (result != eDeviceRegistrationUnRegistrationResponse.Success) { - var result = Port.Register(); - if (result != eDeviceRegistrationUnRegistrationResponse.Success) - { - Debug.LogMessage(LogEventLevel.Information, this, "ERROR: Cannot register Com port: {0}", result); - return; // false - } + Debug.LogMessage(LogEventLevel.Information, this, "ERROR: Cannot register Com port: {0}", result); + return; // false } + //} var specResult = Port.SetComPortSpec(Spec); if (specResult != 0) { - Debug.LogMessage(LogEventLevel.Information, this, "WARNING: Cannot set comspec"); + this.LogInformation("WARNING: Cannot set comspec"); return; } - - //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}'"); + this.LogDebug($"ComPort comspec successfully set (specResult == {specResult})"); - // } + // TODO [ ] - Remove debug logging once verified working + if (Port.Parent is CenIoCom102) + { + Port.PropertyChanged += (s, e) => + { + this.LogInformation($@"RegisterAndConfigureComPort: PropertyChanged Fired >> + comPort-'{Port.ID}', + Property Changed-'{e.Property}', + Value Changed-'{e.Value}', + deviceName-'{Port.DeviceName}', + parentDevice-'{Port.ParentDevice}', + parent-`{Port.Parent}`, + online-`{Port.IsOnline}`, + present-`{Port.Present}`, + supportedBaudRates-'{Port.SupportedBaudRates}'"); + }; + Port.ExtendedInformationChanged += (s, e) => + { + + this.LogInformation($@"RegisterAndConfigureComPort: ExtendedInformationChanged Fired >> + comPort-'{Port.ID}', + {e.Protocol}, + {e.BaudRate}, + {e.Parity}, + {e.DataBits}, + {e.StopBits}, + HW Handshake-'{e.HardwareHandshakeSetting}', + SW Handshake-'{e.SoftwareHandshakeSetting}'"); + }; + } Port.SerialDataReceived += Port_SerialDataReceived; } From 32a332a6e20f4c0968ca7d8965aa1564eb4e9c65 Mon Sep 17 00:00:00 2001 From: jkdevito Date: Mon, 27 Oct 2025 17:32:40 -0500 Subject: [PATCH 4/8] refactor: update TODO comment for Port registration verification --- src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs b/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs index fcd1bdde..c2d71945 100644 --- a/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs +++ b/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs @@ -73,7 +73,7 @@ namespace PepperDash.Essentials.Core Debug.LogMessage(LogEventLevel.Information, this, "Configured com Port for this device does not exist."); return; } - // TODO [ ] - Verify nothing blows up without the `if` check + // TODO [ ] - Verify nothing blows up without the `if` check || if there is a property identifying the parent/device is either registerable or notRegisterable //if (Port.Parent is CrestronControlSystem || Port.Parent is CenIoCom102) //{ var result = Port.Register(); From 3ce282e2dba03a9554fac487647d72e45f38c699 Mon Sep 17 00:00:00 2001 From: jkdevito Date: Mon, 27 Oct 2025 17:33:06 -0500 Subject: [PATCH 5/8] refactor: comment out debug logging for ComPort registration --- .../Comm and IR/ComPortController.cs | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs b/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs index c2d71945..ca9b51fe 100644 --- a/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs +++ b/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs @@ -94,35 +94,35 @@ namespace PepperDash.Essentials.Core // TODO [ ] - Remove debug logging once verified working - if (Port.Parent is CenIoCom102) - { - Port.PropertyChanged += (s, e) => - { - this.LogInformation($@"RegisterAndConfigureComPort: PropertyChanged Fired >> - comPort-'{Port.ID}', - Property Changed-'{e.Property}', - Value Changed-'{e.Value}', - deviceName-'{Port.DeviceName}', - parentDevice-'{Port.ParentDevice}', - parent-`{Port.Parent}`, - online-`{Port.IsOnline}`, - present-`{Port.Present}`, - supportedBaudRates-'{Port.SupportedBaudRates}'"); - }; - Port.ExtendedInformationChanged += (s, e) => - { + // if (Port.Parent is CenIoCom102) + // { + // Port.PropertyChanged += (s, e) => + // { + // this.LogInformation($@"RegisterAndConfigureComPort: PropertyChanged Fired >> + // comPort-'{Port.ID}', + // Property Changed-'{e.Property}', + // Value Changed-'{e.Value}', + // deviceName-'{Port.DeviceName}', + // parentDevice-'{Port.ParentDevice}', + // parent-`{Port.Parent}`, + // online-`{Port.IsOnline}`, + // present-`{Port.Present}`, + // supportedBaudRates-'{Port.SupportedBaudRates}'"); + // }; + // Port.ExtendedInformationChanged += (s, e) => + // { - this.LogInformation($@"RegisterAndConfigureComPort: ExtendedInformationChanged Fired >> - comPort-'{Port.ID}', - {e.Protocol}, - {e.BaudRate}, - {e.Parity}, - {e.DataBits}, - {e.StopBits}, - HW Handshake-'{e.HardwareHandshakeSetting}', - SW Handshake-'{e.SoftwareHandshakeSetting}'"); - }; - } + // this.LogInformation($@"RegisterAndConfigureComPort: ExtendedInformationChanged Fired >> + // comPort-'{Port.ID}', + // {e.Protocol}, + // {e.BaudRate}, + // {e.Parity}, + // {e.DataBits}, + // {e.StopBits}, + // HW Handshake-'{e.HardwareHandshakeSetting}', + // SW Handshake-'{e.SoftwareHandshakeSetting}'"); + // }; + // } Port.SerialDataReceived += Port_SerialDataReceived; } From c4d064965f8b03e5f90d29765da570012be2b509 Mon Sep 17 00:00:00 2001 From: jkdevito Date: Tue, 28 Oct 2025 08:40:29 -0500 Subject: [PATCH 6/8] refactor: enhance ComPortController with additional event documentation and logging improvements --- .../Comm and IR/ComPortController.cs | 47 ++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs b/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs index ca9b51fe..0c4bc198 100644 --- a/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs +++ b/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs @@ -24,7 +24,14 @@ namespace PepperDash.Essentials.Core /// public CommunicationStreamDebugging StreamDebugging { get; private set; } + /// + /// Event fired when bytes are received + /// public event EventHandler BytesReceived; + + /// + /// Event fired when text is received + /// public event EventHandler TextReceived; /// @@ -35,6 +42,13 @@ namespace PepperDash.Essentials.Core ComPort Port; ComPort.ComPortSpec Spec; + /// + /// Constructor + /// + /// + /// + /// + /// public ComPortController(string key, Func postActivationFunc, ComPort.ComPortSpec spec, EssentialsControlPropertiesConfig config) : base(key) { @@ -50,6 +64,12 @@ namespace PepperDash.Essentials.Core }); } + /// + /// Constructor + /// + /// Device key + /// COM port instance + /// COM port specification public ComPortController(string key, ComPort port, ComPort.ComPortSpec spec) : base(key) { @@ -73,24 +93,26 @@ namespace PepperDash.Essentials.Core Debug.LogMessage(LogEventLevel.Information, this, "Configured com Port for this device does not exist."); return; } - // TODO [ ] - Verify nothing blows up without the `if` check || if there is a property identifying the parent/device is either registerable or notRegisterable + // TODO [ ] - Remove commented out code once verified working //if (Port.Parent is CrestronControlSystem || Port.Parent is CenIoCom102) - //{ - var result = Port.Register(); - if (result != eDeviceRegistrationUnRegistrationResponse.Success) + if (Port.Parent is GenericBase genericDevice && genericDevice.Registerable) { - Debug.LogMessage(LogEventLevel.Information, this, "ERROR: Cannot register Com port: {0}", result); - return; // false + this.LogInformation($"INFO: Attempting to register {Port.Parent.GetType().Name}-comport-{Port.ID} using GenericBase"); + var result = genericDevice.Register(); + if (result != eDeviceRegistrationUnRegistrationResponse.Success) + { + this.LogError($"ERROR: Cannot register comport: {result}"); + return; // false + } } - //} - + var specResult = Port.SetComPortSpec(Spec); if (specResult != 0) { - this.LogInformation("WARNING: Cannot set comspec"); + this.LogError("ERROR: Cannot set comspec"); return; } - this.LogDebug($"ComPort comspec successfully set (specResult == {specResult})"); + this.LogInformation($"INFO: Comspec successfully set (result == {specResult})"); // TODO [ ] - Remove debug logging once verified working @@ -111,7 +133,7 @@ namespace PepperDash.Essentials.Core // }; // Port.ExtendedInformationChanged += (s, e) => // { - + // this.LogInformation($@"RegisterAndConfigureComPort: ExtendedInformationChanged Fired >> // comPort-'{Port.ID}', // {e.Protocol}, @@ -127,6 +149,9 @@ namespace PepperDash.Essentials.Core Port.SerialDataReceived += Port_SerialDataReceived; } + /// + /// Destructor + /// ~ComPortController() { Port.SerialDataReceived -= Port_SerialDataReceived; From 92c9db8237be1729255c5a020d76e22231ac50dc Mon Sep 17 00:00:00 2001 From: jkdevito Date: Tue, 28 Oct 2025 09:04:15 -0500 Subject: [PATCH 7/8] refactor: improve logging messages in ComPort registration and configuration --- .../Comm and IR/ComPortController.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs b/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs index 0c4bc198..ee65c208 100644 --- a/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs +++ b/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs @@ -97,11 +97,11 @@ namespace PepperDash.Essentials.Core //if (Port.Parent is CrestronControlSystem || Port.Parent is CenIoCom102) if (Port.Parent is GenericBase genericDevice && genericDevice.Registerable) { - this.LogInformation($"INFO: Attempting to register {Port.Parent.GetType().Name}-comport-{Port.ID} using GenericBase"); + //this.LogInformation($"INFO: Attempting to register {Key} using {Port.Parent.GetType().Name}-comport-{Port.ID}"); var result = genericDevice.Register(); if (result != eDeviceRegistrationUnRegistrationResponse.Success) { - this.LogError($"ERROR: Cannot register comport: {result}"); + this.LogError($"ERROR: Cannot register {Key} using {Port.Parent.GetType().Name}-comport-{Port.ID} (result == {result})"); return; // false } } @@ -109,10 +109,10 @@ namespace PepperDash.Essentials.Core var specResult = Port.SetComPortSpec(Spec); if (specResult != 0) { - this.LogError("ERROR: Cannot set comspec"); + this.LogError($"ERROR: Cannot set comspec for {Key} using {Port.Parent.GetType().Name}-comport-{Port.ID} (result == {specResult})"); return; } - this.LogInformation($"INFO: Comspec successfully set (result == {specResult})"); + //this.LogInformation($"INFO: Successfully set comspec for {Key} using {Port.Parent.GetType().Name}-comport-{Port.ID} (result == {specResult})"); // TODO [ ] - Remove debug logging once verified working From ba576180a7f6ddd73f3b642a4372fa35af650fd4 Mon Sep 17 00:00:00 2001 From: jkdevito Date: Tue, 28 Oct 2025 09:05:56 -0500 Subject: [PATCH 8/8] refactor: remove unused using directives in ComPortController --- .../Comm and IR/ComPortController.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs b/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs index ee65c208..ba599ead 100644 --- a/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs +++ b/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs @@ -1,15 +1,10 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Text; using System.Text.RegularExpressions; -using Crestron.SimplSharp; using Crestron.SimplSharpPro; - using PepperDash.Core; -using Serilog.Events; using PepperDash.Core.Logging; -using Crestron.SimplSharpPro.GeneralIO; +using Serilog.Events; namespace PepperDash.Essentials.Core