Ambient cleanup, ver. 2.18.1120

This commit is contained in:
Milan Hanajik
2019-01-23 08:26:53 +01:00
parent c6e1d672e5
commit 9bed5e6682
2 changed files with 89 additions and 101 deletions
+21 -33
View File
@@ -27,16 +27,13 @@ namespace TBF.BenchControl.Ambient.Comet
/// <summary>The state of the measurement</summary>
MsrmntState msrmntState;
int msrmntTimeStamp;
///
/// Measured values when MsrmntState == MsrmntState.Valid
///
float temperature; /// [°C]
float pressure; /// [bar]
float humidity; /// [R%]
/// <summary>Measurement time stamp when MsrmntState == MsrmntState.Valid</summary>
int msrmntTimeStamp;
public Ambient()
{
@@ -64,6 +61,7 @@ namespace TBF.BenchControl.Ambient.Comet
temperature = 20.0f;
humidity = 40.0f;
pressure = 1.0f;
msrmntTimeStamp = StateMachine.Time;
msrmntState = MsrmntState.Valid;
return;
@@ -73,6 +71,8 @@ namespace TBF.BenchControl.Ambient.Comet
serialPort = new SerialPort(comPortName, ambientCfg.BaudRate, ambientCfg.Parity, ambientCfg.DataBits, ambientCfg.StopBits);
serialPort.Handshake = ambientCfg.Handshake;
serialPort.Open();
msrmntTimeStamp = 0;
msrmntState = MsrmntState.Busy;
log.FatalFormat("Successfully initialized device {0}", ToString());
@@ -81,19 +81,11 @@ namespace TBF.BenchControl.Ambient.Comet
/// <summary>Run this device</summary>
public void RunDeviceBefore()
{
if (ambientCfg.DebugLevel == DebugMode.Simulate ||
ambientCfg.DebugLevel == DebugMode.FailureDuringOperation)
if ((ambientCfg.DebugLevel == DebugMode.Normal) && (serialPort != null))
{
msrmntTimeStamp = StateMachine.Time;
return;
}
if (serialPort == null)
{
log.ErrorFormat("{0} - RunDeviceBefore() - serial port closed", Name);
return;
}
///
/// Read response
///
try
{
int receivedBytes = serialPort.BytesToRead;
@@ -124,35 +116,29 @@ namespace TBF.BenchControl.Ambient.Comet
catch (Exception e)
{
DebugLevel = DebugMode.FailureDuringOperation;
//serialPort.Close(); /// ?
serialPort = null;
log.FatalFormat("Ambient: Serail port read failure : {0}", e.Message);
log.FatalFormat("Ambient: Serial port read failure : {0}", e.Message);
if (e.InnerException != null)
{
log.FatalFormat("InnerMessage : {0}", e.InnerException.Message);
}
}
}
}
/// <summary>Run this device</summary>
public void RunDeviceAfter()
{
if (ambientCfg.DebugLevel == DebugMode.Simulate ||
ambientCfg.DebugLevel == DebugMode.FailureDuringOperation)
if ((ambientCfg.DebugLevel == DebugMode.Normal) && (serialPort != null))
{
return;
}
if (serialPort == null)
{
log.ErrorFormat("{0} - RunDeviceAfter() - serial port closed", Name);
return;
}
try
{
/// Each 10 seconds
if ((StateMachine.Time % 10) == 0)
{
///
/// Send request once per 10 seconds
///
try
{
/// Read four registers: 0x31, 0x32, 0x33, 0x34
UInt16 regAddr = 0x0030; /// register addr. = 0x31 (Modbus!)
@@ -171,10 +157,10 @@ namespace TBF.BenchControl.Ambient.Comet
log.Debug(Telegram.LogTelegram("Sending ", msg));
serialPort.Write(msg, 0, msg.Length);
}
}
catch (Exception e)
{
DebugLevel = DebugMode.FailureDuringOperation;
//serialPort.Close(); /// ?
serialPort = null;
log.FatalFormat("Ambient: Serail port read failure : {0}", e.Message);
@@ -184,11 +170,13 @@ namespace TBF.BenchControl.Ambient.Comet
}
}
}
}
}
/// <summary>Stop this device</summary>
public void StopDevice()
{
if (serialPort != null)
if ((ambientCfg.DebugLevel == DebugMode.Normal) && (serialPort != null))
{
serialPort.Close();
serialPort = null;
+2 -2
View File
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number
// Revision
//
[assembly: AssemblyVersion("2.18.1119.0")]
[assembly: AssemblyFileVersion("2.18.1119.0")]
[assembly: AssemblyVersion("2.18.1120.0")]
[assembly: AssemblyFileVersion("2.18.1120.0")]