From 89bd9883918cd753a6ad471aef59f5aceeb654db Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 26 Jan 2022 09:34:44 -0700 Subject: [PATCH 1/4] fix (Core): Add better log messages and null checks Checking if a device exists in the Device Manager and if it implements `IRelayPorts` are now 2 separate steps instead of one. There is now a null check in the PostActivation method to allow for logging an error if getting the relay device fails. --- .../Crestron IO/Relay/GenericRelayDevice.cs | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Relay/GenericRelayDevice.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Relay/GenericRelayDevice.cs index 445ac338..5a49a443 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Relay/GenericRelayDevice.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Relay/GenericRelayDevice.cs @@ -44,6 +44,12 @@ namespace PepperDash.Essentials.Core.CrestronIO { RelayOutput = postActivationFunc(config); + if (RelayOutput == null) + { + Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Unable to get parent relay device for device key {0} and port {1}", config.PortDeviceKey, config.PortNumber); + return; + } + RelayOutput.Register(); RelayOutput.StateChange += RelayOutput_StateChange; @@ -61,30 +67,32 @@ namespace PepperDash.Essentials.Core.CrestronIO { if (!Global.ControlSystem.SupportsRelay) { - Debug.Console(0, "GetRelayDevice: Processor does not support relays"); + Debug.Console(0, "Processor does not support relays"); return null; } relayDevice = Global.ControlSystem; + + return relayDevice.RelayPorts[dc.PortNumber]; } - else + + var essentialsDevice = DeviceManager.GetDeviceForKey(dc.PortDeviceKey); + if (essentialsDevice == null) { - var relayDev = DeviceManager.GetDeviceForKey(dc.PortDeviceKey) as IRelayPorts; - if (relayDev == null) - { - Debug.Console(0, "GetRelayDevice: Device {0} is not a valid device", dc.PortDeviceKey); - return null; - } - relayDevice = relayDev; + Debug.Console(0, "Device {0} was not found in Device Manager. Check configuration or for errors with device.", dc.PortDeviceKey); + return null; } + + relayDevice = essentialsDevice as IRelayPorts; + if (relayDevice == null) { - Debug.Console(0, "GetRelayDevice: Device '0' is not a valid IRelayPorts Device", dc.PortDeviceKey); + Debug.Console(0, "Device {0} is not a valid relay parent. Please check configuration.", dc.PortDeviceKey); return null; } if (dc.PortNumber > relayDevice.NumberOfRelayPorts) { - Debug.Console(0, "GetRelayDevice: Device {0} does not contain a port {1}", dc.PortDeviceKey, dc.PortNumber); + Debug.Console(0, "Device {0} does not contain a port {1}", dc.PortDeviceKey, dc.PortNumber); } return relayDevice.RelayPorts[dc.PortNumber]; From 4eace11943a60b526b64044e33489ea9fd207d4b Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 26 Jan 2022 09:35:09 -0700 Subject: [PATCH 2/4] refactor(Core): Removed old commented out code --- .../Crestron IO/Relay/GenericRelayDevice.cs | 52 ------------------- 1 file changed, 52 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Relay/GenericRelayDevice.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Relay/GenericRelayDevice.cs index 5a49a443..effe2a93 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Relay/GenericRelayDevice.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Relay/GenericRelayDevice.cs @@ -208,58 +208,6 @@ namespace PepperDash.Essentials.Core.CrestronIO var portDevice = new GenericRelayDevice(dc.Key, dc.Name, GetRelay, props); return portDevice; - - - /* - if (props.PortDeviceKey == "processor") - portDevice = Global.ControlSystem as IRelayPorts; - else - portDevice = DeviceManager.GetDeviceForKey(props.PortDeviceKey) as IRelayPorts; - - if (portDevice == null) - Debug.Console(0, "Unable to add relay device with key '{0}'. Port Device does not support relays", key); - else - { - var cs = (portDevice as CrestronControlSystem); - - if (cs != null) - { - // The relay is on a control system processor - if (!cs.SupportsRelay || props.PortNumber > cs.NumberOfRelayPorts) - { - Debug.Console(0, "Port Device: {0} does not support relays or does not have enough relays"); - return null; - } - } - else - { - // The relay is on another device type - - if (props.PortNumber > portDevice.NumberOfRelayPorts) - { - Debug.Console(0, "Port Device: {0} does not have enough relays"); - return null; - } - } - - Relay relay = portDevice.RelayPorts[props.PortNumber]; - - if (!relay.Registered) - { - if (relay.Register() == eDeviceRegistrationUnRegistrationResponse.Success) - return new GenericRelayDevice(key, relay); - else - Debug.Console(0, "Attempt to register relay {0} on device with key '{1}' failed.", props.PortNumber, props.PortDeviceKey); - } - else - { - return new GenericRelayDevice(key, relay); - } - - // Future: Check if portDevice is 3-series card or other non control system that supports versiports - } - */ - } } From 8393ae3dedf13c95d5f9e3994e7a1189e276fe77 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 26 Jan 2022 09:39:57 -0700 Subject: [PATCH 3/4] fix(Core): Add return if port number is greater than supported ports on the device --- .../Crestron IO/Relay/GenericRelayDevice.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Relay/GenericRelayDevice.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Relay/GenericRelayDevice.cs index effe2a93..69c588ae 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Relay/GenericRelayDevice.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Relay/GenericRelayDevice.cs @@ -90,12 +90,13 @@ namespace PepperDash.Essentials.Core.CrestronIO return null; } - if (dc.PortNumber > relayDevice.NumberOfRelayPorts) + if (dc.PortNumber <= relayDevice.NumberOfRelayPorts) { - Debug.Console(0, "Device {0} does not contain a port {1}", dc.PortDeviceKey, dc.PortNumber); + return relayDevice.RelayPorts[dc.PortNumber]; } - - return relayDevice.RelayPorts[dc.PortNumber]; + + Debug.Console(0, "Device {0} does not contain a port {1}", dc.PortDeviceKey, dc.PortNumber); + return null; } #endregion From 05aece772fae128256f3609297512279ab40329f Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 26 Jan 2022 10:51:03 -0700 Subject: [PATCH 4/4] fix(DM): Add `IRelayPorts` implementation the `DmRmc4kzScalerCController` class now implements `IRelayPorts` and delegates implementation to the Crestron `DmRm4kzScalerC` class. #891 --- .../Receivers/DmRmc4kZScalerCController.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Receivers/DmRmc4kZScalerCController.cs b/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Receivers/DmRmc4kZScalerCController.cs index 21663e78..73dd59b9 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Receivers/DmRmc4kZScalerCController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Receivers/DmRmc4kZScalerCController.cs @@ -14,7 +14,7 @@ namespace PepperDash.Essentials.DM { [Description("Wrapper Class for DM-RMC-4K-Z-SCALER-C")] public class DmRmc4kZScalerCController : DmRmcControllerBase, IRmcRoutingWithFeedback, - IIROutputPorts, IComPorts, ICec + IIROutputPorts, IComPorts, ICec, IRelayPorts { private readonly DmRmc4kzScalerC _rmc; @@ -168,5 +168,18 @@ namespace PepperDash.Essentials.DM } #endregion + #region Implementation of IRelayPorts + + public CrestronCollection RelayPorts + { + get { return _rmc.RelayPorts; } + } + + public int NumberOfRelayPorts + { + get { return _rmc.NumberOfRelayPorts; } + } + + #endregion } } \ No newline at end of file