mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-04-13 20:47:04 +00:00
adds new ctor to add post activation action
for ComPortController
This commit is contained in:
parent
5608721e3d
commit
282ea62f83
1 changed files with 26 additions and 8 deletions
|
|
@ -21,6 +21,19 @@ namespace PepperDash.Essentials.Core
|
||||||
ComPort Port;
|
ComPort Port;
|
||||||
ComPort.ComPortSpec Spec;
|
ComPort.ComPortSpec Spec;
|
||||||
|
|
||||||
|
public ComPortController(string key, Func<EssentialsControlPropertiesConfig, ComPort> postActivationFunc,
|
||||||
|
ComPort.ComPortSpec spec, EssentialsControlPropertiesConfig config) : base(key)
|
||||||
|
{
|
||||||
|
Spec = spec;
|
||||||
|
|
||||||
|
AddPostActivationAction(() =>
|
||||||
|
{
|
||||||
|
Port = postActivationFunc(config);
|
||||||
|
|
||||||
|
ConfigureComPort();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public ComPortController(string key, ComPort port, ComPort.ComPortSpec spec)
|
public ComPortController(string key, ComPort port, ComPort.ComPortSpec spec)
|
||||||
: base(key)
|
: base(key)
|
||||||
{
|
{
|
||||||
|
|
@ -45,13 +58,18 @@ namespace PepperDash.Essentials.Core
|
||||||
return; // false
|
return; // false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ConfigureComPort();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConfigureComPort()
|
||||||
|
{
|
||||||
var specResult = Port.SetComPortSpec(Spec);
|
var specResult = Port.SetComPortSpec(Spec);
|
||||||
if (specResult != 0)
|
if (specResult != 0)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, "WARNING: Cannot set comspec");
|
Debug.Console(0, this, "WARNING: Cannot set comspec");
|
||||||
return; // false
|
return;
|
||||||
}
|
}
|
||||||
Port.SerialDataReceived += new ComPortDataReceivedEvent(Port_SerialDataReceived);
|
Port.SerialDataReceived += Port_SerialDataReceived;
|
||||||
}
|
}
|
||||||
|
|
||||||
~ComPortController()
|
~ComPortController()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue