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
+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;