Merge pull request #1354 from PepperDash/comport-controller-updates

fix: improve logging for COM port registration and configuration
This commit is contained in:
Andrew Welker
2025-11-04 10:55:44 -05:00
committed by GitHub

View File

@@ -1,7 +1,9 @@
using System; using System;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro; using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.GeneralIO;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Core.Logging; using PepperDash.Core.Logging;
using Serilog.Events; using Serilog.Events;
@@ -85,36 +87,32 @@ namespace PepperDash.Essentials.Core
{ {
if (Port == null) if (Port == null)
{ {
Debug.LogMessage(LogEventLevel.Information, this, "Configured com Port for this device does not exist."); this.LogInformation($"Configured {Port.Parent.GetType().Name}-comport-{Port.ID} for {Key} does not exist.");
return; return;
} }
// TODO [ ] - Remove commented out code once verified working
//if (Port.Parent is CrestronControlSystem || Port.Parent is CenIoCom102) var result = Port.Register();
if (Port.Parent is GenericBase genericDevice && genericDevice.Registerable) if (result != eDeviceRegistrationUnRegistrationResponse.Success)
{ {
//this.LogInformation($"INFO: Attempting to register {Key} using {Port.Parent.GetType().Name}-comport-{Port.ID}"); this.LogError($"Cannot register {Key} using {Port.Parent.GetType().Name}-comport-{Port.ID} (result == {result})");
var result = genericDevice.Register(); return;
if (result != eDeviceRegistrationUnRegistrationResponse.Success)
{
this.LogError($"ERROR: Cannot register {Key} using {Port.Parent.GetType().Name}-comport-{Port.ID} (result == {result})");
return; // false
}
} }
this.LogInformation($"Successfully registered {Key} using {Port.Parent.GetType().Name}-comport-{Port.ID} (result == {result})");
var specResult = Port.SetComPortSpec(Spec); var specResult = Port.SetComPortSpec(Spec);
if (specResult != 0) if (specResult != 0)
{ {
this.LogError($"ERROR: Cannot set comspec for {Key} using {Port.Parent.GetType().Name}-comport-{Port.ID} (result == {specResult})"); this.LogError($"Cannot set comspec for {Key} using {Port.Parent.GetType().Name}-comport-{Port.ID} (result == {specResult})");
return; return;
} }
//this.LogInformation($"INFO: Successfully set comspec for {Key} using {Port.Parent.GetType().Name}-comport-{Port.ID} (result == {specResult})"); this.LogInformation($"Successfully set comspec for {Key} using {Port.Parent.GetType().Name}-comport-{Port.ID} (result == {specResult})");
// TODO [ ] - Remove debug logging once verified working // TODO [ ] - Remove debug logging once verified working
// if (Port.Parent is CenIoCom102) // if (Port.Parent is CenIoCom102)
// { // {
// Port.PropertyChanged += (s, e) => // Port.PropertyChanged += (s, e) =>
// { // {
// this.LogInformation($@"RegisterAndConfigureComPort: PropertyChanged Fired >> // this.LogInformation($@"RegisterAndConfigureComPort: PropertyChanged Fired >>
// comPort-'{Port.ID}', // comPort-'{Port.ID}',
// Property Changed-'{e.Property}', // Property Changed-'{e.Property}',