Ambient clean-up.

This commit is contained in:
Milan Hanajik
2021-04-02 15:12:22 +02:00
parent 4e9d1c8281
commit 51aa0f4e43
6 changed files with 80 additions and 124 deletions
+31 -48
View File
@@ -21,7 +21,7 @@ namespace TBF.Rig.Ambient.Comet
public class Ambient : ComponentBase, IDevice, IOperation, GenericDevices.IAmbient, IDrawingItCmpntWithMeasuredVal
{
private static readonly ILog log = LogManager.GetLogger(typeof(Ambient));
public override string ToString() { return string.Format("Ambient({0})", Cfg.ToString(-1)); }
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
///
/// Configuration and wrappers
@@ -51,7 +51,8 @@ namespace TBF.Rig.Ambient.Comet
public double MeasuredVal { get { return temperature; } }
public string AltString
{
get {
get
{
return string.Format(ambientCfg.Format, Units.ConvertTo(TempUnit, temperature),
Units.ConvertTo(PressureUnit, pressure),
Units.ConvertTo(HumiUnit, humidity));
@@ -62,62 +63,48 @@ namespace TBF.Rig.Ambient.Comet
/// Private fields
SerialPort serialPort;
/// <summary>The state of the measurement</summary>
MsrmntState msrmntState;
int msrmntTimeStamp;
/// Measured values when MsrmntState == MsrmntState.Valid
double temperature; /// [°C]
double pressure; /// [bar]
double humidity; /// [R%]
/// <summary>Time stamp of the measurement</summary>
int msrmntTimeStamp;
public Ambient()
{
}
public Ambient() { }
/// <summary>
/// Ambient temperature / humidity / pressure meter 'Greco' connected via serial interface (RS232)
/// </summary>
public Ambient(AmbientCfg cfg, IList<Generic.IComponent> components)
: this(cfg)
{
}
public Ambient(Generic.IComponentCfg cfg)
public Ambient(Generic.IComponentCfg cfg)
: base(cfg)
{
ambientCfg = cfg as AmbientCfg;
temperature = DefaultTemperature;
pressure = DefaultPressure;
humidity = DefaultHumidity;
log.Warn(this.ToString());
}
public void Initialize()
{
if (ambientCfg.DebugLevel == DebugMode.Simulate)
{
msrmntTimeStamp = StateMachine.Time;
msrmntState = MsrmntState.Valid;
return;
}
string comPortName = "COM" + ambientCfg.ComPortNr.ToString();
serialPort = new SerialPort(comPortName, ambientCfg.BaudRate, ambientCfg.Parity, ambientCfg.DataBits, ambientCfg.StopBits);
serialPort.Handshake = ambientCfg.Handshake;
serialPort.Open();
if (ambientCfg.SetDtrToOne)
{
serialPort.DtrEnable = true;
}
temperature = DefaultTemperature;
pressure = DefaultPressure;
humidity = DefaultHumidity;
msrmntTimeStamp = 0;
msrmntState = MsrmntState.Busy;
log.FatalFormat("Successfully initialized device {0}", ToString());
if (ambientCfg.DebugLevel == DebugMode.Normal)
{
string comPortName = "COM" + ambientCfg.ComPortNr.ToString();
serialPort = new SerialPort(comPortName, ambientCfg.BaudRate, ambientCfg.Parity, ambientCfg.DataBits, ambientCfg.StopBits);
serialPort.Handshake = ambientCfg.Handshake;
serialPort.Open();
if (ambientCfg.SetDtrToOne) serialPort.DtrEnable = true;
log.FatalFormat("{0} - Device successfully initialized", Name);
}
else
{
serialPort = null;
log.FatalFormat("{0} - Device simulated", Name);
}
}
/// <summary>Run this device</summary>
@@ -150,7 +137,6 @@ namespace TBF.Rig.Ambient.Comet
pressure = value / 10000.0;
msrmntTimeStamp = StateMachine.Time;
msrmntState = MsrmntState.Valid;
UpdateProcessData(temperature, pressure, humidity);
@@ -221,15 +207,12 @@ namespace TBF.Rig.Ambient.Comet
/// <summary>Stop this device</summary>
public void StopDevice()
{
if ((ambientCfg.DebugLevel == DebugMode.Normal) && (serialPort != null))
{
serialPort.Close();
serialPort = null;
}
if (serialPort != null && serialPort.IsOpen) serialPort.Close();
}
public void StopDevice2() { }
void UpdateProcessData(double temperature, double pressure, double humidity)
{
TBF.Rig.Sequences.ProcessData.AmbTemp.Val = temperature;
@@ -256,9 +239,9 @@ namespace TBF.Rig.Ambient.Comet
/// <summary>Start this operation</summary>
public void Start()
{
if (tempBox != null) tempBox.Val = temperature;
if (tempBox != null) tempBox.Val = temperature;
if (pressureBox != null) pressureBox.Val = pressure;
if (humiBox != null) humiBox.Val = humidity;
if (humiBox != null) humiBox.Val = humidity;
}
/// <summary>Run this operation</summary>
@@ -267,9 +250,9 @@ namespace TBF.Rig.Ambient.Comet
/// </returns>
public Event Run()
{
if (tempBox != null) tempBox.Val = temperature;
if (tempBox != null) tempBox.Val = temperature;
if (pressureBox != null) pressureBox.Val = pressure;
if (humiBox != null) humiBox.Val = humidity;
if (humiBox != null) humiBox.Val = humidity;
return Event.AmbientDone;
}
+1 -1
View File
@@ -15,7 +15,7 @@ namespace TBF.Rig.Ambient.Comet
public IComponent DummyComponent() { return new Ambient(); }
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new Ambient(cfg); }
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new Ambient(cfg); }
public IComponentCfg DefaultConfig() { return new AmbientCfg("Ambient", this); }
+27 -38
View File
@@ -22,7 +22,7 @@ namespace TBF.Rig.Ambient.Greco
public class Ambient : ComponentBase, IDevice, IOperation, GenericDevices.IAmbient, IDrawingItCmpntWithMeasuredVal
{
private static readonly ILog log = LogManager.GetLogger(typeof(Ambient));
public override string ToString() { return string.Format("Ambient({0})", Cfg.ToString(-1)); }
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
private readonly AmbientCfg ambientCfg;
///
@@ -49,7 +49,8 @@ namespace TBF.Rig.Ambient.Greco
public double MeasuredVal { get { return temperature; } }
public string AltString
{
get {
get
{
return string.Format(ambientCfg.Format, Units.ConvertTo(TempUnit, temperature),
Units.ConvertTo(PressureUnit, pressure),
Units.ConvertTo(HumiUnit, humidity));
@@ -60,9 +61,6 @@ namespace TBF.Rig.Ambient.Greco
SerialPort serialPort;
StringBuilder measurementBuilder;
/// <summary>The state of the measurement</summary>
MsrmntState msrmntState;
///
/// Measured values when MsrmntState == MsrmntState.Valid
///
@@ -73,48 +71,41 @@ namespace TBF.Rig.Ambient.Greco
/// <summary>Measurement time stamp when MsrmntState == MsrmntState.Valid</summary>
int msrmntTimeStamp;
public Ambient()
{
}
public Ambient() { }
/// <summary>
/// Ambient temperature / humidity / pressure meter 'Greco' connected via serial interface (RS232)
/// Connection settings: 19200 Bd 8-bits No-parity 1-stop-bit Flow control: none or hardware.
/// </summary>
public Ambient(AmbientCfg cfg, IList<Generic.IComponent> components)
: this(cfg)
{
}
public Ambient(Generic.IComponentCfg cfg)
public Ambient(Generic.IComponentCfg cfg)
: base(cfg)
{
ambientCfg = cfg as AmbientCfg;
temperature = DefaultTemperature;
pressure = DefaultPressure;
humidity = DefaultHumidity;
log.Warn(this.ToString());
}
public void Initialize()
{
if (ambientCfg.DebugLevel == DebugMode.Simulate)
{
msrmntTimeStamp = StateMachine.Time;
msrmntState = MsrmntState.Valid;
return;
}
temperature = DefaultTemperature;
pressure = DefaultPressure;
humidity = DefaultHumidity;
msrmntTimeStamp = 0;
string comPortName = "COM" + ambientCfg.ComPortNr.ToString();
serialPort = new SerialPort(comPortName, ambientCfg.BaudRate, ambientCfg.Parity, ambientCfg.DataBits, ambientCfg.StopBits);
serialPort.Handshake = ambientCfg.Handshake;
serialPort.Open();
measurementBuilder = new StringBuilder(40);
msrmntState = MsrmntState.Busy;
log.FatalFormat("Successfully initialized device {0}", ToString());
if (ambientCfg.DebugLevel == DebugMode.Normal)
{
string comPortName = "COM" + ambientCfg.ComPortNr.ToString();
serialPort = new SerialPort(comPortName, ambientCfg.BaudRate, ambientCfg.Parity, ambientCfg.DataBits, ambientCfg.StopBits);
serialPort.Handshake = ambientCfg.Handshake;
serialPort.Open();
measurementBuilder = new StringBuilder(40);
log.FatalFormat("{0} - Device successfully initialized", Name);
}
else
{
serialPort = null;
log.FatalFormat("{0} - Device simulated", Name);
}
}
/// <summary>Run this device</summary>
@@ -170,7 +161,6 @@ namespace TBF.Rig.Ambient.Greco
UpdateProcessData(temperature, pressure, humidity);
msrmntTimeStamp = StateMachine.Time;
msrmntState = MsrmntState.Valid;
log.InfoFormat("Ambient: temperature = {0:F1} C, humidity = {1:F1} %, pressure = {2:F0} mbar", temperature, humidity, 1000 * pressure);
}
else
@@ -193,18 +183,17 @@ namespace TBF.Rig.Ambient.Greco
}
/// <summary>Run this device</summary>
public void RunDeviceAfter()
{
}
public void RunDeviceAfter() { }
/// <summary>Stop this device</summary>
public void StopDevice()
{
if (serialPort != null) serialPort.Close();
if (serialPort != null && serialPort.IsOpen) serialPort.Close();
}
public void StopDevice2() { }
void UpdateProcessData(double temperature, double pressure, double humidity)
{
TBF.Rig.Sequences.ProcessData.AmbTemp.Val = temperature;
+1 -1
View File
@@ -15,7 +15,7 @@ namespace TBF.Rig.Ambient.Greco
public IComponent DummyComponent() { return new Ambient(); }
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new Ambient(cfg); }
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new Ambient(cfg); }
public IComponentCfg DefaultConfig() { return new AmbientCfg("Ambient", this); }