Ambient clean-up.
This commit is contained in:
@@ -19,7 +19,7 @@ namespace TBF.Rig.Modbus.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
|
||||
@@ -50,18 +50,15 @@ namespace TBF.Rig.Modbus.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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
readonly GenericDevices.IModbus modbus;
|
||||
|
||||
/// <summary>The state of the measurement</summary>
|
||||
MsrmntState msrmntState;
|
||||
readonly Common.Modbus modbus;
|
||||
|
||||
///
|
||||
/// Measured values when MsrmntState == MsrmntState.Valid
|
||||
@@ -87,41 +84,25 @@ namespace TBF.Rig.Modbus.Ambient.Comet
|
||||
{
|
||||
ambientCfg = cfg as AmbientCfg;
|
||||
|
||||
modbus = (GenericDevices.IModbus)TbfComponents.FindComponent(cfg.ParentName, components);
|
||||
modbus = TbfComponents.FindComponent(cfg.ParentName, components) as Common.Modbus;
|
||||
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
msrmntState = MsrmntState.Busy;
|
||||
temperature = DefaultTemperature;
|
||||
pressure = DefaultPressure;
|
||||
humidity = DefaultHumidity;
|
||||
msrmntTimeStamp = 0;
|
||||
ticketNumber = modbus.RegisterForPolling();
|
||||
|
||||
log.FatalFormat("Successfully initialized device {0}", ToString());
|
||||
log.FatalFormat("{0} - Device successfully initialized", Name);
|
||||
}
|
||||
|
||||
/// <summary>Run this device</summary>
|
||||
public void RunDeviceBefore()
|
||||
{
|
||||
if (ambientCfg.DebugLevel == DebugMode.Simulate ||
|
||||
ambientCfg.DebugLevel == DebugMode.FailureDuringOperation)
|
||||
{
|
||||
msrmntTimeStamp = StateMachine.Time;
|
||||
return;
|
||||
}
|
||||
|
||||
if (modbus.ReceivedTelegrams[ambientCfg.ModbusAddress].Count > 0)
|
||||
{
|
||||
byte[] telegram = modbus.ReceivedTelegrams[ambientCfg.ModbusAddress].Dequeue();
|
||||
@@ -138,7 +119,6 @@ namespace TBF.Rig.Modbus.Ambient.Comet
|
||||
pressure = value / 10000.0;
|
||||
|
||||
msrmntTimeStamp = StateMachine.Time;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
|
||||
UpdateProcessData(temperature, pressure, humidity);
|
||||
|
||||
@@ -149,9 +129,7 @@ namespace TBF.Rig.Modbus.Ambient.Comet
|
||||
|
||||
public void RunDeviceAfter()
|
||||
{
|
||||
if (ambientCfg.DebugLevel != Config.Entities.DebugMode.Simulate &&
|
||||
ambientCfg.DebugLevel != Config.Entities.DebugMode.FailureDuringOperation &&
|
||||
modbus.IsMyTurn(ticketNumber))
|
||||
if (modbus.IsMyTurn(ticketNumber))
|
||||
{
|
||||
/// Read four registers: 0x31, 0x32, 0x33, 0x34
|
||||
UInt16 regAddr = 0x0030; /// register addr. = 0x31 (Modbus!)
|
||||
|
||||
Reference in New Issue
Block a user