Initialization of 30 components changed, done in Initialize( ).
This commit is contained in:
+101
-114
@@ -48,9 +48,7 @@ namespace TBF.Rig.Hart.Common
|
||||
Queue<byte[]> telegramsToSend;
|
||||
|
||||
|
||||
public Hart()
|
||||
{
|
||||
}
|
||||
public Hart() { }
|
||||
|
||||
/// <summary>
|
||||
/// HART modem connected via serial interface (RS232).
|
||||
@@ -59,166 +57,155 @@ namespace TBF.Rig.Hart.Common
|
||||
public Hart(Generic.IComponentCfg cfg)
|
||||
: base(cfg)
|
||||
{
|
||||
receivedTelegrams = new Queue<byte[]>[16]; /// Max. 16 slaves with adresses 0..15
|
||||
for (int i = 0; i < receivedTelegrams.Length; i++)
|
||||
{
|
||||
receivedTelegrams[i] = new Queue<byte[]>();
|
||||
}
|
||||
telegramsToSend = new Queue<byte[]>();
|
||||
|
||||
serialPort = null;
|
||||
hartCfg = cfg as HartCfg;
|
||||
hartCfg = cfg as HartCfg;
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
~Hart()
|
||||
public override void Initialize()
|
||||
{
|
||||
}
|
||||
telegramsToSend = new Queue<byte[]>();
|
||||
|
||||
receivedTelegrams = new Queue<byte[]>[16]; /// Max. 16 slaves with adresses 0..15
|
||||
for (int i = 0; i < receivedTelegrams.Length; i++)
|
||||
{
|
||||
receivedTelegrams[i] = new Queue<byte[]>();
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
if (hartCfg.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
serialPort = null;
|
||||
log.FatalFormat("{0} - Device simulated", Name);
|
||||
return;
|
||||
}
|
||||
|
||||
string comPortName = "COM" + hartCfg.ComPortNr.ToString();
|
||||
serialPort = new SerialPort(comPortName, hartCfg.BaudRate, hartCfg.Parity, hartCfg.DataBits, hartCfg.StopBits);
|
||||
serialPort.Handshake = hartCfg.Handshake;
|
||||
serialPort.Open();
|
||||
|
||||
log.FatalFormat("{0} - Device successfully initialized", Name);
|
||||
if (hartCfg.DebugLevel == DebugMode.Normal)
|
||||
{
|
||||
string comPortName = "COM" + hartCfg.ComPortNr.ToString();
|
||||
serialPort = new SerialPort(comPortName, hartCfg.BaudRate, hartCfg.Parity, hartCfg.DataBits, hartCfg.StopBits);
|
||||
serialPort.Handshake = hartCfg.Handshake;
|
||||
serialPort.Open();
|
||||
log.FatalFormat("{0} - Device successfully initialized", Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
serialPort = null;
|
||||
log.FatalFormat("{0} - Device simulated", Name);
|
||||
}
|
||||
}
|
||||
|
||||
public void RunDeviceBefore()
|
||||
{
|
||||
if (serialPort != null)
|
||||
{
|
||||
ParseReceivedData();
|
||||
}
|
||||
ParseReceivedData();
|
||||
}
|
||||
|
||||
public void RunDeviceAfter()
|
||||
{
|
||||
if ((serialPort != null) && (telegramsToSend.Count > 0) && (DateTime.Now - lastSerialPortWrite) > new TimeSpan(0, 0, 0, 0, 500))
|
||||
if (telegramsToSend.Count > 0 && DateTime.Now - lastSerialPortWrite > new TimeSpan(0, 0, 0, 0, 500))
|
||||
{
|
||||
SendMessageNow(telegramsToSend.Dequeue());
|
||||
WriteMessageToSerialPort(telegramsToSend.Dequeue());
|
||||
}
|
||||
}
|
||||
|
||||
public void StopDevice()
|
||||
{
|
||||
if (serialPort != null)
|
||||
{
|
||||
serialPort.Close();
|
||||
serialPort = null;
|
||||
}
|
||||
if (serialPort != null && serialPort.IsOpen) serialPort.Close();
|
||||
}
|
||||
|
||||
public void StopDevice2() { }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Send an arbitrary modbus message.
|
||||
/// When the message length is N, however only bytes 1..N-2 have to be set.
|
||||
/// The last two message bytes (CRC) may be uninitialized or zero.
|
||||
/// They are calculated inside this function as required by Modbus specification.
|
||||
/// </summary>
|
||||
/// <param name="message">Message incl. a reserved checksum byte, checksum does not have to be set</param>
|
||||
public void SendMessage(int preambLen, byte[] message)
|
||||
{
|
||||
Telegram.UpdateTelegramChecksum(message);
|
||||
byte[] preambAndMessage = new byte[message.Length + preambLen];
|
||||
|
||||
public void SendMessageNow(byte[] message)
|
||||
{
|
||||
serialPort.Write(message, 0, message.Length);
|
||||
lastSerialPortWrite = DateTime.Now;
|
||||
|
||||
string s = Telegram.LogTelegram(string.Format("{0} - Sending message ", Name), message);
|
||||
Debug.WriteLine(s);
|
||||
log.Debug(s);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send an arbitrary modbus message.
|
||||
/// When the message length is N, however only bytes 1..N-2 have to be set.
|
||||
/// The last two message bytes (CRC) may be uninitialized or zero.
|
||||
/// They are calculated inside this function as required by Modbus specification.
|
||||
/// </summary>
|
||||
/// <param name="message">Message incl. a reserved checksum byte, checksum does not have to be set</param>
|
||||
public void SendMessage(int preambLen, byte[] message)
|
||||
{
|
||||
if (serialPort == null) return;
|
||||
|
||||
Telegram.UpdateTelegramChecksum(message);
|
||||
byte[] preambAndMessage = new byte[message.Length + preambLen];
|
||||
|
||||
for (int i = 0; i < preambLen; i++) preambAndMessage[i] = (byte)0xFF;
|
||||
for (int i = preambLen; i < preambLen + message.Length; i++) preambAndMessage[i] = message[i - preambLen];
|
||||
for (int i = 0; i < preambLen; i++) preambAndMessage[i] = (byte)0xFF;
|
||||
for (int i = preambLen; i < preambLen + message.Length; i++) preambAndMessage[i] = message[i - preambLen];
|
||||
|
||||
if ((DateTime.Now - lastSerialPortWrite) > new TimeSpan(0, 0, 0, 0, 500))
|
||||
{
|
||||
/// More then 100 ms since last 'send' --> do not enqueue the message
|
||||
SendMessageNow(preambAndMessage);
|
||||
WriteMessageToSerialPort(preambAndMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
telegramsToSend.Enqueue(preambAndMessage);
|
||||
|
||||
string s = Telegram.LogTelegram(string.Format("{0} - Enqueueing message ", Name), message);
|
||||
Debug.WriteLine(s);
|
||||
log.Debug(s);
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteMessageToSerialPort(byte[] message)
|
||||
{
|
||||
if (serialPort != null && serialPort.IsOpen)
|
||||
{
|
||||
serialPort.Write(message, 0, message.Length);
|
||||
}
|
||||
lastSerialPortWrite = DateTime.Now;
|
||||
string s = Telegram.LogTelegram(string.Format("{0} - Sending message ", Name), message);
|
||||
Debug.WriteLine(s);
|
||||
log.Debug(s);
|
||||
}
|
||||
|
||||
void ParseReceivedData()
|
||||
{
|
||||
int nrBytes = serialPort.BytesToRead;
|
||||
if (nrBytes > 0)
|
||||
{
|
||||
/// Read available data
|
||||
byte[] buf = new byte[nrBytes];
|
||||
serialPort.Read(buf, 0, nrBytes);
|
||||
if (serialPort != null && serialPort.IsOpen)
|
||||
{
|
||||
int nrBytes = serialPort.BytesToRead;
|
||||
if (nrBytes > 0)
|
||||
{
|
||||
/// Read available data
|
||||
byte[] buf = new byte[nrBytes];
|
||||
serialPort.Read(buf, 0, nrBytes);
|
||||
|
||||
/// Determine count of leading FF-s
|
||||
int preambLen = 0;
|
||||
for (int i = 0; i < nrBytes; i++)
|
||||
{
|
||||
if (buf[i] != (byte)0xFF) break;
|
||||
preambLen++;
|
||||
}
|
||||
/// Determine count of leading FF-s
|
||||
int preambLen = 0;
|
||||
for (int i = 0; i < nrBytes; i++)
|
||||
{
|
||||
if (buf[i] != (byte)0xFF) break;
|
||||
preambLen++;
|
||||
}
|
||||
|
||||
int telegramLen = nrBytes - preambLen;
|
||||
int telegramLen = nrBytes - preambLen;
|
||||
|
||||
/// Check a telegram length, a checksum, a start byte (S -> M) and a master address (primary)
|
||||
if (preambLen < 3 ||
|
||||
telegramLen < 4 ||
|
||||
!Telegram.VerifyTelegramChecksum(preambLen, buf) ||
|
||||
((buf[preambLen] != (byte)Mark.ShortFrameSlave2Master) && (buf[preambLen] != (byte)Mark.LongFrameSlave2Master)) ||
|
||||
((buf[preambLen + 1] & 0x80) != (byte)Master.Primary))
|
||||
{
|
||||
string s = Telegram.LogTelegram(string.Format("{0} - Invalid data received ", Name), buf);
|
||||
Debug.WriteLine(s);
|
||||
log.Debug(s);
|
||||
return;
|
||||
}
|
||||
/// Check a telegram length, a checksum, a start byte (S -> M) and a master address (primary)
|
||||
if (preambLen < 3 ||
|
||||
telegramLen < 4 ||
|
||||
!Telegram.VerifyTelegramChecksum(preambLen, buf) ||
|
||||
((buf[preambLen] != (byte)Mark.ShortFrameSlave2Master) && (buf[preambLen] != (byte)Mark.LongFrameSlave2Master)) ||
|
||||
((buf[preambLen + 1] & 0x80) != (byte)Master.Primary))
|
||||
{
|
||||
string s = Telegram.LogTelegram(string.Format("{0} - Invalid data received ", Name), buf);
|
||||
Debug.WriteLine(s);
|
||||
log.Debug(s);
|
||||
return;
|
||||
}
|
||||
|
||||
/// Strip the preamble
|
||||
byte[] data = new byte[telegramLen];
|
||||
for (int i = preambLen; i < nrBytes; i++) data[i - preambLen] = buf[i];
|
||||
/// Strip the preamble
|
||||
byte[] data = new byte[telegramLen];
|
||||
for (int i = preambLen; i < nrBytes; i++) data[i - preambLen] = buf[i];
|
||||
|
||||
bool isShortFrame = (data[0] == 0x06);
|
||||
bool isShortFrame = (data[0] == 0x06);
|
||||
|
||||
if (isShortFrame)
|
||||
{
|
||||
int address = data[1] & 0x0F;
|
||||
receivedTelegrams[address].Enqueue(data);
|
||||
if (isShortFrame)
|
||||
{
|
||||
int address = data[1] & 0x0F;
|
||||
receivedTelegrams[address].Enqueue(data);
|
||||
|
||||
string s = string.Format("{0} - {1} address={2} preambLen={3} count={4}", Name, Telegram.LogTelegram("Valid telegram received: ", data), address, preambLen, receivedTelegrams[address].Count);
|
||||
Debug.WriteLine(s);
|
||||
log.Debug(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
/// TODO
|
||||
string s = Telegram.LogTelegram(string.Format("{0} - Telegram with long address received ", Name), buf);
|
||||
Debug.WriteLine(s);
|
||||
log.Debug(s);
|
||||
}
|
||||
}
|
||||
string s = string.Format("{0} - {1} address={2} preambLen={3} count={4}", Name, Telegram.LogTelegram("Valid telegram received: ", data), address, preambLen, receivedTelegrams[address].Count);
|
||||
Debug.WriteLine(s);
|
||||
log.Debug(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
/// TODO
|
||||
string s = Telegram.LogTelegram(string.Format("{0} - Telegram with long address received ", Name), buf);
|
||||
Debug.WriteLine(s);
|
||||
log.Debug(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,9 +50,7 @@ namespace TBF.Rig.Hart.Nivotrack
|
||||
CurrentOp currentOp;
|
||||
|
||||
|
||||
public Nivotrack()
|
||||
{
|
||||
}
|
||||
public Nivotrack() { }
|
||||
|
||||
/// <summary>
|
||||
/// Ambient temperature / humidity / pressure meter 'Greco' connected via serial interface (RS232)
|
||||
@@ -66,12 +64,17 @@ namespace TBF.Rig.Hart.Nivotrack
|
||||
hart = (IHart)TbfComponents.FindComponent(cfg.ParentName, components);
|
||||
if (hart == null) throw new Exception("Cannot find " + Name + " parent");
|
||||
|
||||
levelReadings = new double[StableReadingsCount];
|
||||
sortedLevelReadings = new double[StableReadingsCount];
|
||||
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
levelReadings = new double[StableReadingsCount];
|
||||
sortedLevelReadings = new double[StableReadingsCount];
|
||||
rawLevel_mm = 0;
|
||||
isRawLevelValid = false;
|
||||
}
|
||||
|
||||
///
|
||||
/// Calendar support
|
||||
///
|
||||
@@ -106,14 +109,6 @@ namespace TBF.Rig.Hart.Nivotrack
|
||||
return calendarEvents;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
if (nivotrackCfg.DebugLevel == DebugMode.Simulate) return;
|
||||
|
||||
rawLevel_mm = 0;
|
||||
isRawLevelValid = false;
|
||||
}
|
||||
|
||||
|
||||
void Detect()
|
||||
{
|
||||
|
||||
@@ -57,10 +57,7 @@ namespace TBF.Rig.Keithley.Multimeter_2010_RS232
|
||||
ScanState scanState;
|
||||
|
||||
|
||||
public Multimeter()
|
||||
{
|
||||
Resistance = new double[ChannelTo + 1];
|
||||
}
|
||||
public Multimeter() { }
|
||||
|
||||
/// <summary>
|
||||
/// Keithley mulltimeter connected via serial interface (RS232)
|
||||
@@ -70,26 +67,38 @@ namespace TBF.Rig.Keithley.Multimeter_2010_RS232
|
||||
: base(cfg)
|
||||
{
|
||||
multimeterCfg = cfg as MultimeterCfg;
|
||||
serialPort = null;
|
||||
|
||||
receivedData = new StringBuilder();
|
||||
readAttemptsCount = 0;
|
||||
|
||||
Resistance = new double[ChannelTo + 1];
|
||||
for (int i = 0; i < Resistance.Length; i++) Resistance[i] = 0;
|
||||
|
||||
listOfReadOperations = new List<int>();
|
||||
listOfChannels = new List<int>();
|
||||
nextChannelIx = 0;
|
||||
currentChannel = 0; /// invalid, no :rout:clos command yet
|
||||
scanState = ScanState.Off;
|
||||
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
~Multimeter()
|
||||
{
|
||||
}
|
||||
public override void Initialize()
|
||||
{
|
||||
Resistance = new double[ChannelTo + 1];
|
||||
for (int i = 0; i < Resistance.Length; i++) Resistance[i] = 0;
|
||||
|
||||
receivedData = new StringBuilder();
|
||||
readAttemptsCount = 0;
|
||||
|
||||
listOfReadOperations = new List<int>();
|
||||
listOfChannels = new List<int>();
|
||||
nextChannelIx = 0;
|
||||
currentChannel = 0; /// invalid, no :rout:clos command yet
|
||||
scanState = ScanState.Off;
|
||||
|
||||
if (multimeterCfg.DebugLevel == DebugMode.Normal)
|
||||
{
|
||||
string comPortName = "COM" + multimeterCfg.ComPortNr.ToString();
|
||||
serialPort = new SerialPort(comPortName, multimeterCfg.BaudRate, multimeterCfg.Parity, multimeterCfg.DataBits, multimeterCfg.StopBits);
|
||||
serialPort.Handshake = multimeterCfg.Handshake;
|
||||
serialPort.Open();
|
||||
log.FatalFormat("{0} - Device successfully initialized", Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
serialPort = null;
|
||||
log.FatalFormat("{0} - Device simulated", Name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Start reading temperature from specified channel
|
||||
@@ -168,23 +177,6 @@ namespace TBF.Rig.Keithley.Multimeter_2010_RS232
|
||||
}
|
||||
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
if (multimeterCfg.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
log.FatalFormat("Simulated device {0}", ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
string comPortName = "COM" + multimeterCfg.ComPortNr.ToString();
|
||||
serialPort = new SerialPort(comPortName, multimeterCfg.BaudRate, multimeterCfg.Parity, multimeterCfg.DataBits, multimeterCfg.StopBits);
|
||||
serialPort.Handshake = multimeterCfg.Handshake;
|
||||
serialPort.Open();
|
||||
|
||||
log.FatalFormat("Successfully initialized device {0}", ToString());
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Send an ASCII string, appends <CR><LF> at the end.
|
||||
/// </summary>
|
||||
|
||||
@@ -41,13 +41,10 @@ namespace TBF.Rig.Modbus.Easytherm
|
||||
}
|
||||
|
||||
/// <summary>Initialize this device</summary>
|
||||
public void Initialize()
|
||||
public override void Initialize()
|
||||
{
|
||||
if (easythermCfg.DebugLevel == DebugMode.Simulate) return;
|
||||
|
||||
temperatureSetPointValid = false;
|
||||
temperatureSetPointRequested = false;
|
||||
actualTemperatureIsValid = false;
|
||||
ticketNumber = modbus.RegisterForPolling();
|
||||
}
|
||||
|
||||
@@ -56,7 +53,6 @@ namespace TBF.Rig.Modbus.Easytherm
|
||||
{
|
||||
if (easythermCfg.DebugLevel == DebugMode.Simulate) return;
|
||||
|
||||
|
||||
if (modbus.ReceivedTelegrams[easythermCfg.ModbusAddress].Count > 0)
|
||||
{
|
||||
byte[] telegram = modbus.ReceivedTelegrams[easythermCfg.ModbusAddress].Dequeue();
|
||||
@@ -72,7 +68,6 @@ namespace TBF.Rig.Modbus.Easytherm
|
||||
{
|
||||
ushort value = (ushort)(256 * telegram[3] + telegram[4]);
|
||||
actualTemperature = (double)value * 0.04;
|
||||
actualTemperatureIsValid = true;
|
||||
|
||||
log.InfoFormat("{0} - Received actual temperature = {1}", Name, actualTemperature);
|
||||
|
||||
@@ -184,7 +179,6 @@ namespace TBF.Rig.Modbus.Easytherm
|
||||
///
|
||||
|
||||
double actualTemperature;
|
||||
bool actualTemperatureIsValid;
|
||||
|
||||
public double ReadTemperature()
|
||||
{
|
||||
|
||||
@@ -43,13 +43,10 @@ namespace TBF.Rig.Modbus.Novus
|
||||
}
|
||||
|
||||
/// <summary>Initialize this device</summary>
|
||||
public void Initialize()
|
||||
public override void Initialize()
|
||||
{
|
||||
if (novusCfg.DebugLevel == DebugMode.Simulate) return;
|
||||
|
||||
temperatureSetPointValid = false;
|
||||
temperatureSetPointRequested = false;
|
||||
actualTemperatureIsValid = false;
|
||||
}
|
||||
|
||||
/// <summary>Run this device</summary>
|
||||
@@ -73,7 +70,6 @@ namespace TBF.Rig.Modbus.Novus
|
||||
{
|
||||
ushort value = (ushort)(256 * telegram[3] + telegram[4]);
|
||||
actualTemperature = (double)value * 0.1; /// temperature in 0.1 °C
|
||||
actualTemperatureIsValid = true;
|
||||
|
||||
log.InfoFormat("{0} - Received actual temperature = {1}", Name, actualTemperature);
|
||||
|
||||
@@ -178,7 +174,6 @@ namespace TBF.Rig.Modbus.Novus
|
||||
///
|
||||
|
||||
double actualTemperature;
|
||||
bool actualTemperatureIsValid;
|
||||
|
||||
public double ReadTemperature()
|
||||
{
|
||||
|
||||
@@ -118,17 +118,12 @@ namespace TBF.Rig.Modbus.PumpFM.DanfossVLT
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
readonly GenericDevices.IModbus modbus;
|
||||
readonly IControlBoard controlBoard;
|
||||
readonly int bitNr; /// 0 .. 63
|
||||
public readonly UInt128 Mask; /// derived from bitPosition in the constructor
|
||||
int bitNr; /// 0 .. 63
|
||||
public UInt128 Mask; /// derived from bitPosition in the constructor
|
||||
|
||||
|
||||
public bool State
|
||||
{
|
||||
get { return (controlBoard.Route & Mask) != 0; }
|
||||
}
|
||||
public bool State { get { return (controlBoard.Route & Mask) != 0; } }
|
||||
|
||||
|
||||
public Pump() { }
|
||||
@@ -153,31 +148,32 @@ namespace TBF.Rig.Modbus.PumpFM.DanfossVLT
|
||||
}
|
||||
if (controlBoard == null) throw new Exception("Cannot find a control board");
|
||||
|
||||
bitNr = pumpCfg.BitNr;
|
||||
Mask = (((UInt128)1) << bitNr);
|
||||
|
||||
TBF.UiBridge.Bridge.SetpointChangeHandler += delegate(object sndr, TBF.UiBridge.SetpointChangeArgs args)
|
||||
{
|
||||
if (args.Name == Name)
|
||||
{
|
||||
if (args.Increase)
|
||||
{
|
||||
IncreaseSetpoint();
|
||||
}
|
||||
else
|
||||
{
|
||||
DecreaseSetpoint();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
///
|
||||
/// IDevice interface
|
||||
///
|
||||
public void Initialize() { }
|
||||
public override void Initialize()
|
||||
{
|
||||
bitNr = pumpCfg.BitNr;
|
||||
Mask = (((UInt128)1) << bitNr);
|
||||
|
||||
TBF.UiBridge.Bridge.SetpointChangeHandler += delegate(object sndr, TBF.UiBridge.SetpointChangeArgs args)
|
||||
{
|
||||
if (args.Name == Name)
|
||||
{
|
||||
if (args.Increase)
|
||||
{
|
||||
IncreaseSetpoint();
|
||||
}
|
||||
else
|
||||
{
|
||||
DecreaseSetpoint();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void RunDeviceBefore()
|
||||
{
|
||||
|
||||
@@ -26,9 +26,8 @@ namespace TBF.Rig.Modbus.QuidoRS
|
||||
|
||||
UInt32 watchdogBitMask;
|
||||
|
||||
public QuidoRS()
|
||||
{
|
||||
}
|
||||
|
||||
public QuidoRS() { }
|
||||
|
||||
public QuidoRS(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
|
||||
: base(cfg)
|
||||
@@ -38,18 +37,17 @@ namespace TBF.Rig.Modbus.QuidoRS
|
||||
modbus = (GenericDevices.IModbus)TbfComponents.FindComponent(cfg.ParentName, components);
|
||||
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
|
||||
|
||||
watchdogBitMask = (ushort)(quidoRSCfg.WatchdogEnabled ? (1 << quidoRSCfg.WatchdogBitNr) : 0);
|
||||
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
watchdogBitMask = (ushort)(quidoRSCfg.WatchdogEnabled ? (1 << quidoRSCfg.WatchdogBitNr) : 0);
|
||||
}
|
||||
|
||||
///
|
||||
/// IDevice interface
|
||||
///
|
||||
public void Initialize() { }
|
||||
/// <summary>
|
||||
/// Run this device
|
||||
/// </summary>
|
||||
public void RunDeviceBefore()
|
||||
{
|
||||
if (quidoRSCfg.DebugLevel == Config.Entities.DebugMode.Simulate) return;
|
||||
@@ -78,8 +76,13 @@ namespace TBF.Rig.Modbus.QuidoRS
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RunDeviceAfter() { }
|
||||
public void StopDevice() { SendOutputs(0); }
|
||||
|
||||
public void StopDevice()
|
||||
{
|
||||
SendOutputs(0);
|
||||
}
|
||||
public void StopDevice2() { }
|
||||
|
||||
|
||||
|
||||
@@ -151,10 +151,7 @@ namespace TBF.Rig.Modbus.TankSelector
|
||||
}
|
||||
|
||||
|
||||
public TankSelector()
|
||||
{
|
||||
CreateConditions(false);
|
||||
}
|
||||
public TankSelector() { }
|
||||
|
||||
public TankSelector(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
|
||||
: base(cfg)
|
||||
@@ -176,13 +173,17 @@ namespace TBF.Rig.Modbus.TankSelector
|
||||
if (warmCooling == null) throw new Exception(string.Format("Component '{0}' cannot find temperature controller '{1}'", Name, tankSelectorCfg.WarmWaterCooling));
|
||||
if (coldCooling == null) throw new Exception(string.Format("Component '{0}' cannot find temperature controller '{1}'", Name, tankSelectorCfg.ColdWaterCooling));
|
||||
|
||||
CreateConditions(true);
|
||||
|
||||
State = State.Unknown;
|
||||
CreateConditions(true);
|
||||
|
||||
log.Fatal(this.ToString());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
State = State.Unknown;
|
||||
SetOutputs(0); /// Reset all Quido outputs
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Recover the TankSelector state from ContolBoard.DigitalInputs
|
||||
@@ -257,11 +258,6 @@ namespace TBF.Rig.Modbus.TankSelector
|
||||
///
|
||||
/// IDevice interface implementation
|
||||
///
|
||||
public void Initialize()
|
||||
{
|
||||
SetOutputs(0); /// Reset all Quido outputs
|
||||
}
|
||||
|
||||
public void RunDeviceBefore()
|
||||
{
|
||||
if (StateMachine.Time == 3)
|
||||
|
||||
@@ -17,10 +17,7 @@ namespace TBF.Rig.Modbus.UltrasoundLevelMeter
|
||||
public override string ToString() { return string.Format("LevelMeter({0})", Cfg.ToString(-1)); }
|
||||
|
||||
readonly LevelMeterCfg myCfg;
|
||||
readonly GenericDevices.IModbus modbus;
|
||||
|
||||
/// <summary>The state of the measurement</summary>
|
||||
MsrmntState msrmntState;
|
||||
readonly Common.Modbus modbus;
|
||||
|
||||
///
|
||||
/// Measured values when MsrmntState == MsrmntState.Valid
|
||||
@@ -46,17 +43,14 @@ namespace TBF.Rig.Modbus.UltrasoundLevelMeter
|
||||
{
|
||||
myCfg = cfg as LevelMeterCfg;
|
||||
|
||||
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");
|
||||
|
||||
/// Connect to handler
|
||||
//ModbusAddress.MeretRS485Address[Idx0] = ModbusAddress;
|
||||
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
/// <summary>Initialize this device</summary>
|
||||
public void Initialize()
|
||||
public override void Initialize()
|
||||
{
|
||||
if (myCfg.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
@@ -67,14 +61,13 @@ namespace TBF.Rig.Modbus.UltrasoundLevelMeter
|
||||
state = 0;
|
||||
|
||||
msrmntTimeStamp = StateMachine.Time;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
return;
|
||||
log.FatalFormat("{0} - Device simulated", Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
ticketNumber = modbus.RegisterForPolling();
|
||||
log.FatalFormat("{0} - Device successfully initialized", Name);
|
||||
}
|
||||
|
||||
msrmntState = MsrmntState.Busy;
|
||||
ticketNumber = modbus.RegisterForPolling();
|
||||
|
||||
log.FatalFormat("Successfully initialized device {0}", ToString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,10 +17,7 @@ namespace TBF.Rig.Modbus.WaterAnalyzer
|
||||
public override string ToString() { return string.Format("Analyzer({0})", Cfg.ToString(-1)); }
|
||||
|
||||
readonly AnalyzerCfg myCfg;
|
||||
readonly GenericDevices.IModbus modbus;
|
||||
|
||||
/// <summary>The state of the measurement</summary>
|
||||
MsrmntState msrmntState;
|
||||
readonly Common.Modbus modbus;
|
||||
|
||||
///
|
||||
/// Measured values when MsrmntState == MsrmntState.Valid
|
||||
@@ -41,19 +38,16 @@ namespace TBF.Rig.Modbus.WaterAnalyzer
|
||||
public Analyzer(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
|
||||
: base(cfg)
|
||||
{
|
||||
myCfg = cfg as AnalyzerCfg;
|
||||
myCfg = cfg as AnalyzerCfg;
|
||||
|
||||
modbus = (GenericDevices.IModbus)TbfComponents.FindComponent(cfg.ParentName, components);
|
||||
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
|
||||
|
||||
/// Connect to handler
|
||||
//ModbusAddress.MeretRS485Address[Idx0] = ModbusAddress;
|
||||
modbus = TbfComponents.FindComponent(cfg.ParentName, components) as Common.Modbus;
|
||||
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
|
||||
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
/// <summary>Initialize this device</summary>
|
||||
public void Initialize()
|
||||
public override void Initialize()
|
||||
{
|
||||
if (myCfg.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
@@ -61,11 +55,9 @@ namespace TBF.Rig.Modbus.WaterAnalyzer
|
||||
temperature = 0.0;
|
||||
|
||||
msrmntTimeStamp = StateMachine.Time;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
return;
|
||||
}
|
||||
|
||||
msrmntState = MsrmntState.Busy;
|
||||
ticketNumber = modbus.RegisterForPolling();
|
||||
|
||||
log.FatalFormat("Successfully initialized device {0}", ToString());
|
||||
|
||||
@@ -24,7 +24,6 @@ namespace TBF.Rig.Network.Comet.Ambient
|
||||
|
||||
readonly AmbientCfg myCfg;
|
||||
readonly IPAddress ipAddress;
|
||||
readonly int tcpPort;
|
||||
|
||||
TcpClient tcpClient;
|
||||
NetworkStream networkStream;
|
||||
@@ -39,9 +38,6 @@ namespace TBF.Rig.Network.Comet.Ambient
|
||||
|
||||
State state;
|
||||
|
||||
/// <summary>The state of the measurement</summary>
|
||||
MsrmntState msrmntState;
|
||||
|
||||
///
|
||||
/// Measured values when MsrmntState == MsrmntState.Valid
|
||||
///
|
||||
@@ -52,9 +48,8 @@ namespace TBF.Rig.Network.Comet.Ambient
|
||||
/// <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)
|
||||
@@ -63,35 +58,28 @@ namespace TBF.Rig.Network.Comet.Ambient
|
||||
: base(cfg)
|
||||
{
|
||||
myCfg = cfg as AmbientCfg;
|
||||
if (myCfg == null) throw new ArgumentNullException("No configuration");
|
||||
|
||||
ipAddress = IPAddress.Parse(myCfg.IPAddress);
|
||||
tcpPort = myCfg.TcpPort;
|
||||
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
public override void Initialize()
|
||||
{
|
||||
if (myCfg.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
temperature = 20.0;
|
||||
humidity = 40.0;
|
||||
pressure = 1.0;
|
||||
msrmntTimeStamp = StateMachine.Time;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.FatalFormat("Ambient: temperature = {0:F1} C, humidity = {1:F1} %, pressure = {2:F0} mbar", temperature, humidity, 1000 * pressure);
|
||||
return;
|
||||
}
|
||||
|
||||
tcpClient = new TcpClient();
|
||||
tcpClient.Connect(ipAddress, tcpPort);
|
||||
networkStream = tcpClient.GetStream();
|
||||
|
||||
state = State.Idle;
|
||||
msrmntState = MsrmntState.Busy;
|
||||
|
||||
log.FatalFormat("Initialization successful: {0}", this.ToString());
|
||||
if (myCfg.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
temperature = 20.0;
|
||||
humidity = 40.0;
|
||||
pressure = 1.0;
|
||||
msrmntTimeStamp = StateMachine.Time;
|
||||
log.FatalFormat("{0} - Device simulated", Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
tcpClient = new TcpClient();
|
||||
tcpClient.Connect(ipAddress, myCfg.TcpPort);
|
||||
networkStream = tcpClient.GetStream();
|
||||
state = State.Idle;
|
||||
log.FatalFormat("{0} - Device successfully initialized", Name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Run this device</summary>
|
||||
@@ -123,7 +111,6 @@ namespace TBF.Rig.Network.Comet.Ambient
|
||||
value = (int)bytes[9] * 256 + (int)bytes[10];
|
||||
temperature = value / 10.0; /// Conversion to °C
|
||||
msrmntTimeStamp = StateMachine.Time;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("Ambient temperature = {0:F1} C", temperature);
|
||||
state = State.Idle;
|
||||
break;
|
||||
@@ -131,7 +118,6 @@ namespace TBF.Rig.Network.Comet.Ambient
|
||||
value = (int)bytes[9] * 256 + (int)bytes[10];
|
||||
humidity = value / 10.0; /// Conversion to R%
|
||||
msrmntTimeStamp = StateMachine.Time;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("Ambient humidity = {0:F1} %", humidity);
|
||||
state = State.Idle;
|
||||
break;
|
||||
@@ -139,7 +125,6 @@ namespace TBF.Rig.Network.Comet.Ambient
|
||||
value = (int)bytes[9] * 256 + (int)bytes[10];
|
||||
pressure = value / 10000.0; /// Conversion to bar
|
||||
msrmntTimeStamp = StateMachine.Time;
|
||||
msrmntState = MsrmntState.Valid;
|
||||
log.InfoFormat("Ambient pressure = {0:F0} mbar", 1000 * pressure);
|
||||
state = State.Idle;
|
||||
break;
|
||||
|
||||
@@ -22,13 +22,17 @@ namespace TBF.Rig.Output.EventTriggers.Iperl
|
||||
: base(cfg)
|
||||
{
|
||||
triggerCfg = cfg as TriggerCfg;
|
||||
ApplyConfig();
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
ApplyConfig();
|
||||
}
|
||||
|
||||
void ApplyConfig()
|
||||
{
|
||||
/// TODO
|
||||
}
|
||||
|
||||
#region Configuration Change Handling
|
||||
|
||||
@@ -29,8 +29,6 @@ namespace TBF.Rig.Output.FileWriters.Basic
|
||||
|
||||
Results.Entities.Batch batch;
|
||||
|
||||
bool abort;
|
||||
|
||||
|
||||
public Writer() {}
|
||||
|
||||
@@ -38,10 +36,13 @@ namespace TBF.Rig.Output.FileWriters.Basic
|
||||
: base(cfg)
|
||||
{
|
||||
writerCfg = cfg as WriterCfg;
|
||||
ApplyConfig();
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
ApplyConfig();
|
||||
}
|
||||
|
||||
void ApplyConfig()
|
||||
{
|
||||
@@ -219,7 +220,6 @@ namespace TBF.Rig.Output.FileWriters.Basic
|
||||
Thread.CurrentThread.CurrentCulture = new CultureInfo(writerCfg.Culture.ToString());
|
||||
}
|
||||
|
||||
abort = false;
|
||||
WriteRslts(batch, writerCfg.DestinationPath);
|
||||
WriteRslts(batch, writerCfg.DestinationPath2);
|
||||
|
||||
@@ -296,8 +296,6 @@ namespace TBF.Rig.Output.FileWriters.Basic
|
||||
/// Write aligned columns
|
||||
for (int i = 0; i < Math.Min(leftColumn.Length, rightColumn.Length); i++)
|
||||
{
|
||||
if (abort) return;
|
||||
|
||||
wrtr.Write(leftColumn[i]);
|
||||
if (!writerCfg.EliminateSpaces)
|
||||
{
|
||||
@@ -334,8 +332,6 @@ namespace TBF.Rig.Output.FileWriters.Basic
|
||||
int totalWidth = 0;
|
||||
for (int i = 0; i < rsltItems.Count; i++)
|
||||
{
|
||||
if (abort) return;
|
||||
|
||||
columnWidths[i] = writerCfg.PrintCaption ? ElSpaces(rsltItems[i].Caption).Length : 0;
|
||||
foreach (var wm in batch.WaterMeters)
|
||||
{
|
||||
@@ -365,8 +361,6 @@ namespace TBF.Rig.Output.FileWriters.Basic
|
||||
/// Write column headers
|
||||
for (int i = 0; i < rsltItems.Count; i++)
|
||||
{
|
||||
if (abort) return;
|
||||
|
||||
string caption = ElSpaces(rsltItems[i].Caption);
|
||||
wr.Write(caption);
|
||||
|
||||
@@ -392,8 +386,6 @@ namespace TBF.Rig.Output.FileWriters.Basic
|
||||
{
|
||||
if (!writerCfg.SaveGoodOnly || wm.Passed)
|
||||
{
|
||||
if (abort) return;
|
||||
|
||||
Results.WMeterRsltItemSpec.TableRowNr = ++rowsCount;
|
||||
|
||||
for (int i = 0; i < rsltItems.Count; i++)
|
||||
|
||||
@@ -28,8 +28,6 @@ namespace TBF.Rig.Output.FileWriters.Elde
|
||||
|
||||
Results.Entities.Batch batch;
|
||||
|
||||
bool abort;
|
||||
|
||||
|
||||
public Writer() {}
|
||||
|
||||
@@ -37,10 +35,13 @@ namespace TBF.Rig.Output.FileWriters.Elde
|
||||
: base(cfg)
|
||||
{
|
||||
writerCfg = cfg as WriterCfg;
|
||||
ApplyConfig();
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
ApplyConfig();
|
||||
}
|
||||
|
||||
void ApplyConfig()
|
||||
{
|
||||
@@ -237,7 +238,6 @@ namespace TBF.Rig.Output.FileWriters.Elde
|
||||
Thread.CurrentThread.CurrentCulture = new CultureInfo(writerCfg.Culture.ToString());
|
||||
}
|
||||
|
||||
abort = false;
|
||||
WriteRslts(batch, writerCfg.DestinationPath);
|
||||
WriteRslts(batch, writerCfg.DestinationPath2);
|
||||
|
||||
@@ -327,8 +327,6 @@ namespace TBF.Rig.Output.FileWriters.Elde
|
||||
/// Write aligned columns
|
||||
for (int i = 0; i < Math.Min(leftColumn.Length, rightColumn.Length); i++)
|
||||
{
|
||||
if (abort) return;
|
||||
|
||||
wrtr.Write(leftColumn[i]);
|
||||
|
||||
if (!writerCfg.EliminateSpaces)
|
||||
|
||||
@@ -28,8 +28,6 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
|
||||
|
||||
Results.Entities.Batch batch;
|
||||
|
||||
bool abort;
|
||||
|
||||
|
||||
public Writer() {}
|
||||
|
||||
@@ -37,10 +35,13 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
|
||||
: base(cfg)
|
||||
{
|
||||
writerCfg = cfg as WriterCfg;
|
||||
ApplyConfig();
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
ApplyConfig();
|
||||
}
|
||||
|
||||
void ApplyConfig()
|
||||
{
|
||||
@@ -227,7 +228,6 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
|
||||
Thread.CurrentThread.CurrentCulture = new CultureInfo(writerCfg.Culture.ToString());
|
||||
}
|
||||
|
||||
abort = false;
|
||||
WriteRslts(batch, writerCfg.DestinationPath);
|
||||
WriteRslts(batch, writerCfg.DestinationPath2);
|
||||
|
||||
@@ -301,8 +301,6 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
|
||||
/// Write aligned columns
|
||||
for (int i = 0; i < Math.Min(leftColumn.Length, rightColumn.Length); i++)
|
||||
{
|
||||
if (abort) return;
|
||||
|
||||
wrtr.Write(leftColumn[i]);
|
||||
|
||||
if (!writerCfg.EliminateSpaces)
|
||||
@@ -321,7 +319,6 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
|
||||
{
|
||||
if (!writerCfg.SaveGoodOnly || wm.Passed)
|
||||
{
|
||||
if (abort) return;
|
||||
WriteWM(wrtr, wm);
|
||||
}
|
||||
}
|
||||
@@ -354,8 +351,6 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
|
||||
int totalWidth = 0;
|
||||
for (int i = 0; i < testItems.Count; i++)
|
||||
{
|
||||
if (abort) return;
|
||||
|
||||
columnWidths[i] = ElSpaces(testItems[i].Caption).Length;
|
||||
foreach (var mtr in wm.RegularMeterTestRslts())
|
||||
{
|
||||
@@ -386,8 +381,6 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
|
||||
/// Write column headers
|
||||
for (int i = 0; i < testItems.Count; i++)
|
||||
{
|
||||
if (abort) return;
|
||||
|
||||
string caption = ElSpaces(testItems[i].Caption);
|
||||
wr.Write(caption);
|
||||
|
||||
@@ -414,8 +407,6 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
|
||||
int rowsCount = 0;
|
||||
foreach (var mtr in wm.RegularMeterTestRslts())
|
||||
{
|
||||
if (abort) return;
|
||||
|
||||
if (mtr != null && mtr.IsPilotRslt() && mtr.Publish() == Config.Entities.Publish.Always)
|
||||
{
|
||||
Results.WMeterRsltItemSpec.TableRowNr = ++rowsCount;
|
||||
|
||||
@@ -30,8 +30,6 @@ namespace TBF.Rig.Output.FileWriters.OneFilePerMeter
|
||||
|
||||
Results.Entities.Batch batch;
|
||||
|
||||
bool abort; /// Set to 'true' by Stop() operation to abort writing to files
|
||||
|
||||
|
||||
public Writer() {}
|
||||
|
||||
@@ -39,10 +37,13 @@ namespace TBF.Rig.Output.FileWriters.OneFilePerMeter
|
||||
: base(cfg)
|
||||
{
|
||||
writerCfg = cfg as WriterCfg;
|
||||
ApplyConfig();
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
ApplyConfig();
|
||||
}
|
||||
|
||||
void ApplyConfig()
|
||||
{
|
||||
@@ -291,8 +292,6 @@ namespace TBF.Rig.Output.FileWriters.OneFilePerMeter
|
||||
/// Write aligned columns
|
||||
for (int i = 0; i < Math.Min(leftColumn.Length, rightColumn.Length); i++)
|
||||
{
|
||||
if (abort) return;
|
||||
|
||||
wrtr.Write(leftColumn[i]);
|
||||
wrtr.Write(new string(' ', maxLen - leftColumn[i].Length + 3));
|
||||
wrtr.WriteLine(rightColumn[i]);
|
||||
@@ -304,7 +303,6 @@ namespace TBF.Rig.Output.FileWriters.OneFilePerMeter
|
||||
foreach (var wm in batch.WaterMeters)
|
||||
{
|
||||
WriteWM(wrtr, wm);
|
||||
if (abort) return;
|
||||
}
|
||||
|
||||
///----------
|
||||
@@ -352,8 +350,6 @@ namespace TBF.Rig.Output.FileWriters.OneFilePerMeter
|
||||
int totalWidth = 0;
|
||||
for (int i = 0; i < testItems.Count; i++)
|
||||
{
|
||||
if (abort) return;
|
||||
|
||||
columnWidths[i] = ElSpaces(testItems[i].Caption).Length;
|
||||
foreach (var mtr in wm.RegularMeterTestRslts())
|
||||
{
|
||||
@@ -381,8 +377,6 @@ namespace TBF.Rig.Output.FileWriters.OneFilePerMeter
|
||||
/// Write column headers
|
||||
for (int i = 0; i < testItems.Count; i++)
|
||||
{
|
||||
if (abort) return;
|
||||
|
||||
string caption = ElSpaces(testItems[i].Caption);
|
||||
wr.Write(caption);
|
||||
|
||||
@@ -405,8 +399,6 @@ namespace TBF.Rig.Output.FileWriters.OneFilePerMeter
|
||||
/// Write table data
|
||||
foreach (var mtr in wm.RegularMeterTestRslts())
|
||||
{
|
||||
if (abort) return;
|
||||
|
||||
if (mtr != null && mtr.IsPilotRslt() && mtr.Publish() == Config.Entities.Publish.Always)
|
||||
{
|
||||
for (int i = 0; i < testItems.Count; i++)
|
||||
|
||||
@@ -31,8 +31,6 @@ namespace TBF.Rig.Output.FileWriters.Xml
|
||||
|
||||
Results.Entities.Batch batch;
|
||||
|
||||
bool abort;
|
||||
|
||||
|
||||
public Writer() {}
|
||||
|
||||
@@ -40,10 +38,13 @@ namespace TBF.Rig.Output.FileWriters.Xml
|
||||
: base(cfg)
|
||||
{
|
||||
writerCfg = cfg as WriterCfg;
|
||||
ApplyConfig();
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
ApplyConfig();
|
||||
}
|
||||
|
||||
void ApplyConfig()
|
||||
{
|
||||
@@ -254,8 +255,6 @@ namespace TBF.Rig.Output.FileWriters.Xml
|
||||
/// Common items 1
|
||||
foreach (var v in commonItems)
|
||||
{
|
||||
if (abort) return;
|
||||
|
||||
/// Fetch the item and strip color information
|
||||
string itemText = v.Print(wm);
|
||||
string[] texts = itemText.Split(new char[] { '|' });
|
||||
@@ -267,8 +266,6 @@ namespace TBF.Rig.Output.FileWriters.Xml
|
||||
/// Test items
|
||||
foreach (var mtr in wm.RegularMeterTestRslts())
|
||||
{
|
||||
if (abort) return;
|
||||
|
||||
if ((mtr != null) && (mtr.Publish() == Config.Entities.Publish.Always))
|
||||
{
|
||||
wr.WriteLine(string.Format(" <{0}>", testTag));
|
||||
|
||||
@@ -33,8 +33,6 @@ namespace TBF.Rig.Output.FileWriters.XmlBatch
|
||||
|
||||
Results.Entities.Batch batch;
|
||||
|
||||
bool abort;
|
||||
|
||||
|
||||
public Writer() {}
|
||||
|
||||
@@ -42,10 +40,13 @@ namespace TBF.Rig.Output.FileWriters.XmlBatch
|
||||
: base(cfg)
|
||||
{
|
||||
writerCfg = cfg as WriterCfg;
|
||||
ApplyConfig();
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
ApplyConfig();
|
||||
}
|
||||
|
||||
void ApplyConfig()
|
||||
{
|
||||
@@ -258,8 +259,6 @@ namespace TBF.Rig.Output.FileWriters.XmlBatch
|
||||
/// Common items
|
||||
foreach (var v in commonItems)
|
||||
{
|
||||
if (abort) return;
|
||||
|
||||
/// Fetch the item and strip color information
|
||||
string itemText = v.Print(batch.WaterMeters[0]);
|
||||
string[] texts = itemText.Split(new char[] { '|' });
|
||||
@@ -275,8 +274,6 @@ namespace TBF.Rig.Output.FileWriters.XmlBatch
|
||||
/// Meter items
|
||||
foreach (var v in meterItems)
|
||||
{
|
||||
if (abort) return;
|
||||
|
||||
/// Fetch the item and strip color information
|
||||
string itemText = v.Print(wm);
|
||||
string[] texts = itemText.Split(new char[] { '|' });
|
||||
@@ -288,8 +285,6 @@ namespace TBF.Rig.Output.FileWriters.XmlBatch
|
||||
/// Test items
|
||||
foreach (var mtr in wm.RegularMeterTestRslts())
|
||||
{
|
||||
if (abort) return;
|
||||
|
||||
if ((mtr != null) && (mtr.Publish() == Config.Entities.Publish.Always))
|
||||
{
|
||||
wr.WriteLine(string.Format(" <{0}>", testTag));
|
||||
|
||||
@@ -38,10 +38,13 @@ namespace TBF.Rig.Output.Printers.Enhanced
|
||||
: base(cfg)
|
||||
{
|
||||
printerCfg = cfg as PrinterCfg;
|
||||
ApplyConfig();
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
ApplyConfig();
|
||||
}
|
||||
|
||||
void ApplyConfig()
|
||||
{
|
||||
|
||||
@@ -34,10 +34,14 @@ namespace TBF.Rig.Output.Printers.Label
|
||||
: base(cfg)
|
||||
{
|
||||
printerCfg = cfg as PrinterCfg;
|
||||
ApplyConfig();
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
ApplyConfig();
|
||||
}
|
||||
|
||||
void ApplyConfig()
|
||||
{
|
||||
commonItems = Results.WMeterRsltItemSpec.FromStrArray(printerCfg.ItemsToPrint);
|
||||
|
||||
@@ -34,10 +34,14 @@ namespace TBF.Rig.Output.Printers.MultiLabel
|
||||
: base(cfg)
|
||||
{
|
||||
printerCfg = cfg as PrinterCfg;
|
||||
ApplyConfig();
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
ApplyConfig();
|
||||
}
|
||||
|
||||
void ApplyConfig()
|
||||
{
|
||||
commonItems = Results.WMeterRsltItemSpec.FromStrArray(printerCfg.ItemsToPrint);
|
||||
|
||||
@@ -38,10 +38,13 @@ namespace TBF.Rig.Output.Printers.OnePerBatch
|
||||
: base(cfg)
|
||||
{
|
||||
printerCfg = cfg as PrinterCfg;
|
||||
ApplyConfig();
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
ApplyConfig();
|
||||
}
|
||||
|
||||
void ApplyConfig()
|
||||
{
|
||||
|
||||
@@ -38,10 +38,13 @@ namespace TBF.Rig.Output.Printers.OnePerMeter
|
||||
: base(cfg)
|
||||
{
|
||||
printerCfg = cfg as PrinterCfg;
|
||||
ApplyConfig();
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
ApplyConfig();
|
||||
}
|
||||
|
||||
void ApplyConfig()
|
||||
{
|
||||
|
||||
@@ -37,10 +37,13 @@ namespace TBF.Rig.Output.Printers.Zapiska
|
||||
: base(cfg)
|
||||
{
|
||||
printerCfg = cfg as PrinterCfg;
|
||||
ApplyConfig();
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
ApplyConfig();
|
||||
}
|
||||
|
||||
void ApplyConfig()
|
||||
{
|
||||
|
||||
@@ -72,9 +72,7 @@ namespace TBF.Rig.RegisterReaders.KPackE.Radio
|
||||
public IReceivesDataFromRadio EntryForm;
|
||||
|
||||
|
||||
public Radio()
|
||||
{
|
||||
}
|
||||
public Radio() { }
|
||||
|
||||
/// <summary>
|
||||
/// Ambient temperature / humidity / pressure meter 'Greco' connected via serial interface (RS232)
|
||||
@@ -83,41 +81,29 @@ namespace TBF.Rig.RegisterReaders.KPackE.Radio
|
||||
public Radio(Generic.IComponentCfg cfg)
|
||||
: base(cfg)
|
||||
{
|
||||
RegReaders = new List<RegisterReader.RegisterReader>();
|
||||
|
||||
serialPort = null;
|
||||
radioCfg = cfg as RadioCfg;
|
||||
data = new List<byte>();
|
||||
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
~Radio()
|
||||
public override void Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
if (radioCfg.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
serialPort = null;
|
||||
log.FatalFormat("{0} - Device simulated", Name);
|
||||
return;
|
||||
}
|
||||
|
||||
RegReaders = new List<RegisterReader.RegisterReader>();
|
||||
data = new List<byte>();
|
||||
lastTelegramReceived = DateTime.MinValue;
|
||||
|
||||
string comPortName = "COM" + radioCfg.ComPortNr.ToString();
|
||||
serialPort = new SerialPort(comPortName, radioCfg.BaudRate, radioCfg.Parity, radioCfg.DataBits, radioCfg.StopBits);
|
||||
serialPort.Handshake = radioCfg.Handshake;
|
||||
serialPort.Open();
|
||||
|
||||
//stopWorkerThread = false;
|
||||
//workerThread = new Thread(Worker);
|
||||
//workerThread.Start();
|
||||
|
||||
log.FatalFormat("{0} - Device successfully initialized", Name);
|
||||
if (radioCfg.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
serialPort = null;
|
||||
log.FatalFormat("{0} - Device simulated", Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
string portName = "COM" + radioCfg.ComPortNr.ToString();
|
||||
serialPort = new SerialPort(portName, radioCfg.BaudRate, radioCfg.Parity, radioCfg.DataBits, radioCfg.StopBits);
|
||||
serialPort.Handshake = radioCfg.Handshake;
|
||||
serialPort.Open();
|
||||
log.FatalFormat("{0} - Device successfully initialized", Name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -121,7 +121,6 @@ namespace TBF.Rig.RegisterReaders.SerialStream
|
||||
///
|
||||
/// Timestamp from the opto telegram
|
||||
///
|
||||
bool lastTimestampValid;
|
||||
private Int64 lastTimestamp;
|
||||
private double timestampSec;
|
||||
private double timestampSec0;
|
||||
@@ -183,10 +182,7 @@ namespace TBF.Rig.RegisterReaders.SerialStream
|
||||
public SerialStream(Generic.IComponentCfg cfg)
|
||||
: base(cfg)
|
||||
{
|
||||
ClearData();
|
||||
|
||||
myCfg = cfg as SerialStreamCfg;
|
||||
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
@@ -199,7 +195,7 @@ namespace TBF.Rig.RegisterReaders.SerialStream
|
||||
datastreamFramesCount = 0;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
public override void Initialize()
|
||||
{
|
||||
ClearData();
|
||||
|
||||
|
||||
@@ -359,28 +359,22 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
|
||||
private SerialPort optoSerialPort;
|
||||
|
||||
|
||||
public IperlHead()
|
||||
{
|
||||
}
|
||||
public IperlHead() { }
|
||||
|
||||
public IperlHead(Generic.IComponentCfg cfg)
|
||||
: base(cfg)
|
||||
{
|
||||
flowDirectionDetection = new FlowDirectionDetection();
|
||||
|
||||
ClearData();
|
||||
|
||||
iperlHeadCfg = cfg as IperlHeadCfg;
|
||||
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
|
||||
public void Initialize()
|
||||
public override void Initialize()
|
||||
{
|
||||
ClearData();
|
||||
optoSerialPortParsingEnabled = false;
|
||||
|
||||
flowDirectionDetection = new FlowDirectionDetection();
|
||||
|
||||
/// Allocate memory for opto-data from iPerl
|
||||
optoData = new OptoTelegramRaw[MaxOptoDataCount];
|
||||
for (int i = 0; i < MaxOptoDataCount; i++) optoData[i] = new OptoTelegramRaw();
|
||||
@@ -394,11 +388,16 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
|
||||
if (DebugLevel == DebugMode.Normal)
|
||||
{
|
||||
/// Prepare serial port
|
||||
optoSerialPort = new SerialPort(string.Format("COM{0}", iperlHeadCfg.OptoComPortNr),
|
||||
9600, Parity.None, 8, StopBits.One);
|
||||
string portName = string.Format("COM{0}", iperlHeadCfg.OptoComPortNr);
|
||||
optoSerialPort = new SerialPort(portName, 9600, Parity.None, 8, StopBits.One);
|
||||
optoSerialPort.Handshake = Handshake.None;
|
||||
|
||||
optoSerialPort.Open();
|
||||
log.FatalFormat("{0} - Device successfully initialized", Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
optoSerialPort = null;
|
||||
log.FatalFormat("{0} - Device simulated", Name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,8 +47,8 @@ namespace TBF.Rig.Uni.Diverter
|
||||
public bool State { get { return (uniCB.Route & mask) != 0; } }
|
||||
|
||||
|
||||
readonly IOperation diverterToTankOp;
|
||||
readonly IOperation diverterToSinkOp;
|
||||
IOperation diverterToTankOp;
|
||||
IOperation diverterToSinkOp;
|
||||
|
||||
FloatBox switchTimeStart;
|
||||
FloatBox switchTimeEnd;
|
||||
@@ -74,32 +74,21 @@ namespace TBF.Rig.Uni.Diverter
|
||||
uniCB = TbfComponents.FindComponent(cfg.ParentName, components) as UniCB;
|
||||
if (uniCB == null) throw new Exception("Cannot find " + Name + " parent");
|
||||
|
||||
if (cfg.DebugLevel != Config.Entities.DebugMode.Off)
|
||||
{
|
||||
if (divCfg.BitNr < 0 || divCfg.BitNr >= 64) throw new ArgumentOutOfRangeException("position");
|
||||
this.mask = (((UInt128)1) << divCfg.BitNr);
|
||||
if (divCfg.BitNr < 0 || divCfg.BitNr > 127) throw new ArgumentOutOfRangeException("position");
|
||||
mask = (((UInt128)1) << divCfg.BitNr);
|
||||
|
||||
switchTimeStart = new FloatBox(divCfg.DfltSwithTimeStartMs / 1000.0f);
|
||||
switchTimeEnd = new FloatBox(divCfg.DfltSwithTimeEndMs / 1000.0f);
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
///// Prepare arguments of SendCalibData()
|
||||
//if (diverterCfg.AdcNr >= 0 && diverterCfg.AdcNr < cBoard.RegValveCalib.GetLength(0))
|
||||
//{
|
||||
// cBoard.RegValveCalib[diverterCfg.AdcNr, 0] = (uint)diverterCfg.AdcValueToSink;
|
||||
// cBoard.RegValveCalib[diverterCfg.AdcNr, 1] = (uint)diverterCfg.AdcValueToTank;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// log.ErrorFormat("Unable to set {0} ADC levels: RegValveCalib array size={1}, diverter AdcNr={2}",
|
||||
// Name, cBoard.RegValveCalib.GetLength(0), diverterCfg.AdcNr);
|
||||
//}
|
||||
public override void Initialize()
|
||||
{
|
||||
switchTimeStart = new FloatBox(divCfg.DfltSwithTimeStartMs / 1000.0f);
|
||||
switchTimeEnd = new FloatBox(divCfg.DfltSwithTimeEndMs / 1000.0f);
|
||||
diverterToTankOp = new SwitchDiverterOp(uniCB, DiverterNr, true);
|
||||
diverterToSinkOp = new SwitchDiverterOp(uniCB, DiverterNr, false);
|
||||
log.FatalFormat("{0} - Device successfully initialized", Name);
|
||||
}
|
||||
|
||||
diverterToTankOp = new SwitchDiverterOp(uniCB, DiverterNr, true);
|
||||
diverterToSinkOp = new SwitchDiverterOp(uniCB, DiverterNr, false);
|
||||
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Calendar support
|
||||
@@ -139,12 +128,12 @@ namespace TBF.Rig.Uni.Diverter
|
||||
///
|
||||
/// IDevice interface implementation
|
||||
///
|
||||
public void Initialize() { }
|
||||
public void RunDeviceBefore()
|
||||
{
|
||||
Int16 adcValue = uniCB.Data.AnalogInput[divCfg.AdcNr];
|
||||
Handlers.OnAdcChanged(this, new CmdResponseArgs(CfgChangeCmd.GetAdc, divCfg.BitNr, adcValue));
|
||||
}
|
||||
|
||||
public void RunDeviceAfter() { }
|
||||
public void StopDevice() { }
|
||||
public void StopDevice2() { }
|
||||
@@ -158,14 +147,26 @@ namespace TBF.Rig.Uni.Diverter
|
||||
/// Returned strings are added to the combo-box
|
||||
public string ConditionName(int i)
|
||||
{
|
||||
if (i == 0) return string.Format("{0} {1}", Name, Strings.Start);
|
||||
else return string.Format("{0} {1}", Name, Strings.End);
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
return string.Format("{0} {1}", Name, Strings.Start);
|
||||
case 1:
|
||||
default:
|
||||
return string.Format("{0} {1}", Name, Strings.End);
|
||||
}
|
||||
}
|
||||
|
||||
public IOperation ConditionOp(int i)
|
||||
{
|
||||
if (i == 0) return diverterToTankOp;
|
||||
else return diverterToSinkOp;
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
return diverterToTankOp;
|
||||
case 1:
|
||||
default:
|
||||
return diverterToSinkOp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ namespace TBF.Rig.Uni.RegValve
|
||||
public IDictionary<double, double> Dict { get { return dict; } }
|
||||
|
||||
public readonly UniCB UniCB;
|
||||
readonly int adcChannel;
|
||||
|
||||
public ValveCategory Category { get { return regValveCfg.Category; } }
|
||||
public int Idx1 { get { return regValveCfg.Idx1; } } /// 1 .. 8
|
||||
@@ -62,6 +61,7 @@ namespace TBF.Rig.Uni.RegValve
|
||||
/// TODO
|
||||
}
|
||||
|
||||
int adcChannel;
|
||||
public RegValveState RegValveState;
|
||||
public double TargetRegValvePosition;
|
||||
|
||||
@@ -129,29 +129,28 @@ namespace TBF.Rig.Uni.RegValve
|
||||
#endregion Configuration Change Handling
|
||||
|
||||
|
||||
public RegValve()
|
||||
{
|
||||
}
|
||||
public RegValve() { }
|
||||
|
||||
public RegValve(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
|
||||
: base(cfg)
|
||||
{
|
||||
regValveCfg = cfg as RegValveCfg;
|
||||
adcChannel = regValveCfg.Idx1 - 1;
|
||||
|
||||
this.UniCB = TbfComponents.FindComponent(cfg.ParentName, components) as UniCB;
|
||||
if (this.UniCB == null) throw new Exception(string.Format("Cannot find {0} (a parent of {1})", cfg.ParentName, Name));
|
||||
|
||||
this.dict = new Dictionary<double, double>();
|
||||
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
adcChannel = regValveCfg.Idx1 - 1;
|
||||
this.dict = new Dictionary<double, double>();
|
||||
}
|
||||
|
||||
///
|
||||
/// IDevice interface implementation
|
||||
///
|
||||
public void Initialize() { }
|
||||
public void RunDeviceBefore()
|
||||
{
|
||||
Int16 adcValue = UniCB.AnalogInput(adcChannel);
|
||||
|
||||
@@ -26,13 +26,17 @@ namespace TBF.Rig.Various.StatisticsMonitoring
|
||||
: base(cfg)
|
||||
{
|
||||
statisticsCfg = cfg as StatisticsCfg;
|
||||
ApplyConfig();
|
||||
log.Warn(this.ToString());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
ApplyConfig();
|
||||
}
|
||||
|
||||
void ApplyConfig()
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
#region Configuration Change Handling
|
||||
|
||||
Reference in New Issue
Block a user