Skip to content

Commit 3d50f5f

Browse files
committed
fix: improve logging for COM port registration and configuration
1 parent 11d62ae commit 3d50f5f

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
22
using System.Text;
33
using System.Text.RegularExpressions;
4+
using Crestron.SimplSharp;
45
using Crestron.SimplSharpPro;
6+
using Crestron.SimplSharpPro.GeneralIO;
57
using PepperDash.Core;
68
using PepperDash.Core.Logging;
79
using Serilog.Events;
@@ -85,36 +87,32 @@ private void RegisterAndConfigureComPort()
8587
{
8688
if (Port == null)
8789
{
88-
Debug.LogMessage(LogEventLevel.Information, this, "Configured com Port for this device does not exist.");
90+
this.LogInformation($"Configured {Port.Parent.GetType().Name}-comport-{Port.ID} for {Key} does not exist.");
8991
return;
9092
}
91-
// TODO [ ] - Remove commented out code once verified working
92-
//if (Port.Parent is CrestronControlSystem || Port.Parent is CenIoCom102)
93-
if (Port.Parent is GenericBase genericDevice && genericDevice.Registerable)
93+
94+
var result = Port.Register();
95+
if (result != eDeviceRegistrationUnRegistrationResponse.Success)
9496
{
95-
//this.LogInformation($"INFO: Attempting to register {Key} using {Port.Parent.GetType().Name}-comport-{Port.ID}");
96-
var result = genericDevice.Register();
97-
if (result != eDeviceRegistrationUnRegistrationResponse.Success)
98-
{
99-
this.LogError($"ERROR: Cannot register {Key} using {Port.Parent.GetType().Name}-comport-{Port.ID} (result == {result})");
100-
return; // false
101-
}
97+
this.LogError($"Cannot register {Key} using {Port.Parent.GetType().Name}-comport-{Port.ID} (result == {result})");
98+
return;
10299
}
100+
this.LogInformation($"Successfully registered {Key} using {Port.Parent.GetType().Name}-comport-{Port.ID} (result == {result})");
103101

104102
var specResult = Port.SetComPortSpec(Spec);
105103
if (specResult != 0)
106104
{
107-
this.LogError($"ERROR: Cannot set comspec for {Key} using {Port.Parent.GetType().Name}-comport-{Port.ID} (result == {specResult})");
105+
this.LogError($"Cannot set comspec for {Key} using {Port.Parent.GetType().Name}-comport-{Port.ID} (result == {specResult})");
108106
return;
109107
}
110-
//this.LogInformation($"INFO: Successfully set comspec for {Key} using {Port.Parent.GetType().Name}-comport-{Port.ID} (result == {specResult})");
108+
this.LogInformation($"Successfully set comspec for {Key} using {Port.Parent.GetType().Name}-comport-{Port.ID} (result == {specResult})");
111109

112110

113111
// TODO [ ] - Remove debug logging once verified working
114112
// if (Port.Parent is CenIoCom102)
115-
// {
113+
// {
116114
// Port.PropertyChanged += (s, e) =>
117-
// {
115+
// {
118116
// this.LogInformation($@"RegisterAndConfigureComPort: PropertyChanged Fired >>
119117
// comPort-'{Port.ID}',
120118
// Property Changed-'{e.Property}',

0 commit comments

Comments
 (0)