fix: deactivate ComPortController on program stopping event

This commit is contained in:
copilot-swe-agent[bot] 2026-06-09 17:06:54 +00:00 committed by GitHub
parent 148dead020
commit a2388acf64
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -50,6 +50,7 @@ namespace PepperDash.Essentials.Core
ComPort.ComPortSpec spec, EssentialsControlPropertiesConfig config) : base(key) ComPort.ComPortSpec spec, EssentialsControlPropertiesConfig config) : base(key)
{ {
StreamDebugging = new CommunicationStreamDebugging(key); StreamDebugging = new CommunicationStreamDebugging(key);
CrestronEnvironment.ProgramStatusEventHandler += CrestronEnvironment_ProgramStatusEventHandler;
Spec = spec; Spec = spec;
@ -70,6 +71,8 @@ namespace PepperDash.Essentials.Core
public ComPortController(string key, ComPort port, ComPort.ComPortSpec spec) public ComPortController(string key, ComPort port, ComPort.ComPortSpec spec)
: base(key) : base(key)
{ {
CrestronEnvironment.ProgramStatusEventHandler += CrestronEnvironment_ProgramStatusEventHandler;
if (port == null) 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");
@ -142,6 +145,12 @@ namespace PepperDash.Essentials.Core
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");
} }
void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType programEventType)
{
if (programEventType == eProgramStatusEventType.Stopping)
Deactivate();
}
/// <summary> /// <summary>
/// Deactivate method /// Deactivate method
/// </summary> /// </summary>