Modbus logging with child component names, ver. 3.1.1606

This commit is contained in:
Milan Hanajik
2021-04-09 16:29:24 +02:00
parent f33bc4f167
commit 9724e8779a
16 changed files with 183 additions and 164 deletions
+2 -2
View File
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number
// Revision
//
[assembly: AssemblyVersion("3.1.1605.0")]
[assembly: AssemblyFileVersion("3.1.1605.0")]
[assembly: AssemblyVersion("3.1.1606.0")]
[assembly: AssemblyFileVersion("3.1.1606.0")]
+27 -8
View File
@@ -23,7 +23,7 @@ namespace TBF.Rig.ControlBoard.Papouch
readonly PapouchCBCfg cbCfg;
GenericDevices.IModbus modbus;
TBF.Rig.Modbus.Common.Modbus modbus;
const int quidosCount = 4;
QuidoVariant[] quidoVariants;
@@ -74,8 +74,8 @@ namespace TBF.Rig.ControlBoard.Papouch
public override void Initialize()
{
modbus = (GenericDevices.IModbus)TbfComponents.FindComponent(cbCfg.ParentName);
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
modbus = TbfComponents.FindComponent(cbCfg.ParentName) as TBF.Rig.Modbus.Common.Modbus;
if (modbus == null) throw new Exception("Cannot find " + Name + " parent (Modbus)");
quidoVariants = new QuidoVariant[quidosCount] { cbCfg.Variant1, cbCfg.Variant2, cbCfg.Variant3, cbCfg.Variant4 };
modbusAddresses = new int[quidosCount] { cbCfg.ModbusAddress1, cbCfg.ModbusAddress2, cbCfg.ModbusAddress3, cbCfg.ModbusAddress4 };
@@ -85,6 +85,14 @@ namespace TBF.Rig.ControlBoard.Papouch
routeInputMasks = new UInt128[quidosCount] { 0, 0, 0, 0 };
lastStateMachineTimes = new int[quidosCount] { 0, 0, 0, 0 };
for (int quidoIx = 0; quidoIx < quidosCount; quidoIx++)
{
if (quidoVariants[quidoIx] != QuidoVariant.None)
{
modbus.ComponentNames[modbusAddresses[quidoIx]] = string.Format("{0}{1}", Name, quidoIx + 1);
}
}
for (int i = 0; i < 128; i++)
{
bool conflictAvoidanceFlag = false;
@@ -174,6 +182,8 @@ namespace TBF.Rig.ControlBoard.Papouch
else
{
for (int quidoIx = 0; quidoIx < quidosCount; quidoIx++)
{
if (quidoVariants[quidoIx] != QuidoVariant.None)
{
if ((currentOutputs & routeOutputMasks[quidoIx]) != (benchModelRoute & routeOutputMasks[quidoIx]) ||
(StateMachine.Time - lastStateMachineTimes[quidoIx]) >= 5)
@@ -186,6 +196,7 @@ namespace TBF.Rig.ControlBoard.Papouch
}
}
}
}
ProcessData.UpdateMeasuredValuesAndSetpoints();
TBF.UiBridge.Bridge.OnStateMachineTick(this, new TBF.UiBridge.StateMachineTickEventArgs(benchModelRoute,
@@ -207,16 +218,19 @@ namespace TBF.Rig.ControlBoard.Papouch
private void RequestAllInputs()
{
for (int quidoIx = 0; quidoIx < quidosCount; quidoIx++)
{
if (quidoVariants[quidoIx] != QuidoVariant.None)
{
RequestInputs(quidoIx);
}
}
}
private void RequestInputs(int quidoIx)
{
byte addr = (byte)modbusAddresses[quidoIx];
byte cmd = (byte)Function.ReadSingleInput;
modbus.SendMessage(new byte[] { addr, cmd, 0, 0, 0, 2, 0, 0 });
modbus.SendMessage(new byte[] { addr, cmd, 0, 0, 0, 2, 0, 0 }, string.Format("{0}{1}", Name, quidoIx + 1));
}
/// <summary>
@@ -226,10 +240,13 @@ namespace TBF.Rig.ControlBoard.Papouch
private void SendAllOutputs(UInt128 route)
{
for (int quidoIx = 0; quidoIx < quidosCount; quidoIx++)
{
if (quidoVariants[quidoIx] != QuidoVariant.None)
{
SendOutputs(quidoIx, route, offsetsOutputs[quidoIx]);
}
}
}
private void SendOutputs(int quidoIx, UInt128 outputs, int offset)
{
@@ -242,18 +259,20 @@ namespace TBF.Rig.ControlBoard.Papouch
switch (quidoVariants[quidoIx])
{
case QuidoVariant.QuidoRS_4_4:
modbus.SendMessage(new byte[] { addr, cmd, 0, 0, 0, 4, 1, loByte, 0, 0 });
modbus.SendMessage(new byte[] { addr, cmd, 0, 0, 0, 4, 1, loByte, 0, 0 }, string.Format("{0}{1}", Name, quidoIx + 1));
break;
case QuidoVariant.QuidoRS_8_8:
modbus.SendMessage(new byte[] { addr, cmd, 0, 0, 0, 8, 1, loByte, 0, 0 });
modbus.SendMessage(new byte[] { addr, cmd, 0, 0, 0, 8, 1, loByte, 0, 0 }, string.Format("{0}{1}", Name, quidoIx + 1));
break;
case QuidoVariant.QuidoRS_2_16:
modbus.SendMessage(new byte[] { addr, cmd, 0, 0, 0, 16, 2, loByte, (byte)(outputs >> (offset + 8)), 0, 0 });
modbus.SendMessage(new byte[] { addr, cmd, 0, 0, 0, 16, 2, loByte, (byte)(outputs >> (offset + 8)), 0, 0 },
string.Format("{0}{1}", Name, quidoIx + 1));
break;
case QuidoVariant.QuidoRS_2_32:
modbus.SendMessage(new byte[] { addr, cmd, 0, 0, 0, 32, 4, loByte, (byte)(outputs >> (offset + 8)),
(byte)(outputs >> (offset + 16)),
(byte)(outputs >> (offset + 24)), 0, 0 });
(byte)(outputs >> (offset + 24)), 0, 0 },
string.Format("{0}{1}", Name, quidoIx + 1));
break;
}
}
+4 -2
View File
@@ -15,7 +15,8 @@ namespace TBF.Rig.GenericDevices
/// They are calculated inside this function as required by Modbus specification.
/// </summary>
/// <param name="message">Message incl CRC fields, CRC bytes dont have to be set</param>
void SendMessage(byte[] message);
/// <param name="meno">Modbus child component name</param>
void SendMessage(byte[] message, string meno);
/// <summary>
/// Send a structured modbus message.
@@ -24,7 +25,8 @@ namespace TBF.Rig.GenericDevices
/// <param name="function">Function (0..127)</param>
/// <param name="dataAddress">Address of data to be transferred (0..65535)</param>
/// <param name="dataCount">Count of data bytes to be transferred (0..65535)</param>
void SendMessage(byte modbusAddress, byte function, ushort dataAddress, ushort dataCount);
/// <param name="meno">Modbus child component name</param>
void SendMessage(byte modbusAddress, byte function, ushort dataAddress, ushort dataCount, string meno);
Queue<byte[]>[] ReceivedTelegrams { get; }
+7 -8
View File
@@ -58,7 +58,7 @@ namespace TBF.Rig.Modbus.Ambient.Comet
}
}
readonly Common.Modbus modbus;
Common.Modbus modbus;
///
/// Measured values when MsrmntState == MsrmntState.Valid
@@ -83,21 +83,20 @@ namespace TBF.Rig.Modbus.Ambient.Comet
: base(cfg)
{
ambientCfg = cfg as AmbientCfg;
modbus = TbfComponents.FindComponent(cfg.ParentName, components) as Common.Modbus;
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
log.Warn(this.ToString());
}
public override void Initialize()
{
modbus = TbfComponents.FindComponent(ambientCfg.ParentName) as Common.Modbus;
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
temperature = DefaultTemperature;
pressure = DefaultPressure;
humidity = DefaultHumidity;
msrmntTimeStamp = 0;
modbus.ComponentNames[ambientCfg.ModbusAddress] = Name;
ticketNumber = modbus.RegisterForPolling();
log.FatalFormat("{0} - Device successfully initialized", Name);
log.FatalFormat("{0} initialized: {1}", Name, this);
}
/// <summary>Run this device</summary>
@@ -144,7 +143,7 @@ namespace TBF.Rig.Modbus.Ambient.Comet
msg[4] = (byte)(count >> 8); /// Serial Com Reference Hi
msg[5] = (byte)(count & 0xFF); /// Serial Com Reference Lo
modbus.SendMessage(msg);
modbus.SendMessage(msg, Name);
}
}
+27 -19
View File
@@ -21,7 +21,7 @@ namespace TBF.Rig.Modbus.Common
private static readonly ILog log = LogManager.GetLogger(typeof(Modbus));
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
const int MaxTelegramsPerSecond = 5; /// Max. number of telegrams to be sent per second (100 ms for each telegram)
const int MaxTelegramsPerSecond = 6; /// Max. number of telegrams to be sent per second (100 ms for each telegram)
const int RegTelegramsPerSecond = 2; /// Number of registered polling telegrams per second
const int MinTelegramLen = 4;
@@ -46,13 +46,16 @@ namespace TBF.Rig.Modbus.Common
int rcvdBytesCount; /// Count of valid bytes in rcvdData buffer
/// Queue for all telegrams to be sent by the serial port
Queue<byte[]> telegramsToSend;
Queue<TelegramMeno> telegramsToSend;
/// An array of queues of received telegrams, one queue for each modbus address
/// Queue<byte[]>[0] is erserved for Groch temperature meters
public Queue<byte[]>[] ReceivedTelegrams { get { return receivedTelegrams; } }
Queue<byte[]>[] receivedTelegrams;
public string[] ComponentNames { get { return componentNames; } }
string[] componentNames;
int registeredDevicesCount; /// Number of devices registered for poling
int firstScheduledTicketNo;
@@ -83,12 +86,14 @@ namespace TBF.Rig.Modbus.Common
modbusComponents[modbusComponentsCount - 1] = this;
}
telegramsToSend = new Queue<byte[]>();
telegramsToSend = new Queue<TelegramMeno>();
receivedTelegrams = new Queue<byte[]>[256];
for (int i = 0; i < receivedTelegrams.Length; i++)
{
receivedTelegrams[i] = new Queue<byte[]>();
}
for (int i = 0; i < receivedTelegrams.Length; i++) receivedTelegrams[i] = new Queue<byte[]>();
componentNames = new string[256];
for (int i = 0; i < componentNames.Length; i++) componentNames[i] = "?";
buffer = new byte[BUFFER_SIZE];
rcvdData = new byte[BUFFER_SIZE];
rcvdBytesCount = 0;
@@ -97,7 +102,7 @@ namespace TBF.Rig.Modbus.Common
/// Insert 'Search Quido RS modules' message into the queue
/// Causes search for Quido RS modules in the first RunDeviceAfter() call
SendMessage(new byte[] { 0xF8, 0x11, 0, 0 });
SendMessage(new byte[] { 0xF8, 0x11, 0, 0 }, "all");
if (modbusCfg.DebugLevel == DebugMode.Normal)
{
@@ -144,10 +149,10 @@ namespace TBF.Rig.Modbus.Common
/// <param name="function">Function (0..127)</param>
/// <param name="dataAddress">Address of data to be transferred (0..65535)</param>
/// <param name="dataCount">Count of data bytes to be transferred (0..65535)</param>
public void SendMessage(byte modbusAddress, byte function, ushort dataAddress, ushort dataCount)
public void SendMessage(byte modbusAddress, byte function, ushort dataAddress, ushort dataCount, string meno)
{
SendMessage(new byte[8] { modbusAddress, function, (byte)(dataAddress / 256), (byte)(dataAddress % 256),
(byte)(dataCount / 256), (byte)(dataCount % 256), 0, 0 });
(byte)(dataCount / 256), (byte)(dataCount % 256), 0, 0 }, meno);
}
/// <summary>
@@ -157,10 +162,10 @@ namespace TBF.Rig.Modbus.Common
/// They are calculated inside this function as required by Modbus specification.
/// </summary>
/// <param name="message">Message incl CRC fields, CRC bytes dont have to be set</param>
public void SendMessage(byte[] message)
public void SendMessage(byte[] message, string meno)
{
Telegram.UpdateTelegramCRC(message);
telegramsToSend.Enqueue(message);
telegramsToSend.Enqueue(new TelegramMeno(message, meno));
}
/// <summary>
@@ -170,9 +175,9 @@ namespace TBF.Rig.Modbus.Common
/// They are calculated inside this function as required by Modbus specification.
/// </summary>
/// <param name="message">Message incl CRC fields, CRC bytes dont have to be set</param>
public void SendMessageGroch(byte[] message)
public void SendMessageGroch(byte[] message, string meno)
{
telegramsToSend.Enqueue(message);
telegramsToSend.Enqueue(new TelegramMeno(message, meno));
}
@@ -231,7 +236,8 @@ namespace TBF.Rig.Modbus.Common
/// Enqueue
receivedTelegrams[0].Enqueue(receivedTelegram);
string s = string.Format("{0} queue size={1}", Telegram.LogTelegram("Received message ", receivedTelegram), receivedTelegrams[0].Count);
string s = string.Format("{0} queue size={1}", Telegram.LogTelegram(string.Format("Received message from {0} ", componentNames[0]),
receivedTelegram), receivedTelegrams[0].Count);
Debug.WriteLine(s);
log.Debug(s);
offset += 28;
@@ -254,7 +260,8 @@ namespace TBF.Rig.Modbus.Common
int deviceAddress = receivedTelegram[0];
receivedTelegrams[deviceAddress].Enqueue(receivedTelegram);
string s = string.Format("{0} queue size={1}", Telegram.LogTelegram("Received message ", receivedTelegram), receivedTelegrams[deviceAddress].Count);
string s = string.Format("{0} queue size={1}", Telegram.LogTelegram(string.Format("Received message from {0} ", componentNames[deviceAddress]),
receivedTelegram), receivedTelegrams[deviceAddress].Count);
Debug.WriteLine(s);
log.Debug(s);
offset += candidateLen;
@@ -309,7 +316,8 @@ namespace TBF.Rig.Modbus.Common
///
void WriteOneMessageToSerialPort()
{
WriteMessageToSerialPort(telegramsToSend.Dequeue());
TelegramMeno msg = telegramsToSend.Dequeue();
WriteMessageToSerialPort(msg.Telegram, msg.Meno, telegramsToSend.Count);
}
@@ -350,7 +358,7 @@ namespace TBF.Rig.Modbus.Common
public void StopDevice2() { }
public void WriteMessageToSerialPort(byte[] message)
public void WriteMessageToSerialPort(byte[] message, string meno, int queueCount)
{
if (modbusCfg.DebugLevel == DebugMode.Normal)
{
@@ -378,7 +386,7 @@ namespace TBF.Rig.Modbus.Common
serialPort.Write(message, 0, message.Length);
}
string s = Telegram.LogTelegram(string.Format("{0} - Sending message ", Name), message);
string s = Telegram.LogTelegram(string.Format("{0} - Sending message to {1} ", Name, meno), message);
Debug.WriteLine(s);
log.Debug(s);
}
+14
View File
@@ -0,0 +1,14 @@
namespace TBF.Rig.Modbus.Common
{
public class TelegramMeno
{
public byte[] Telegram;
public string Meno;
public TelegramMeno(byte[] telegram, string meno)
{
Telegram = telegram;
Meno = meno;
}
}
}
+9 -11
View File
@@ -16,7 +16,8 @@ namespace TBF.Rig.Modbus.Easytherm
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
readonly EasythermCfg easythermCfg;
readonly GenericDevices.IModbus modbus;
Common.Modbus modbus;
private float temperatureSetPoint;
private bool temperatureSetPointValid;
@@ -33,26 +34,24 @@ namespace TBF.Rig.Modbus.Easytherm
: base(cfg)
{
easythermCfg = cfg as EasythermCfg;
modbus = (GenericDevices.IModbus)TbfComponents.FindComponent(cfg.ParentName, components);
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
log.Warn(this.ToString());
}
/// <summary>Initialize this device</summary>
public override void Initialize()
{
modbus = TbfComponents.FindComponent(easythermCfg.ParentName) as Common.Modbus;
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
temperatureSetPointValid = false;
temperatureSetPointRequested = false;
modbus.ComponentNames[easythermCfg.ModbusAddress] = Name;
ticketNumber = modbus.RegisterForPolling();
log.FatalFormat("{0} initialized: {1}", Name, this);
}
/// <summary>Run this device</summary>
public void RunDeviceBefore()
{
if (easythermCfg.DebugLevel == DebugMode.Simulate) return;
if (modbus.ReceivedTelegrams[easythermCfg.ModbusAddress].Count > 0)
{
byte[] telegram = modbus.ReceivedTelegrams[easythermCfg.ModbusAddress].Dequeue();
@@ -83,8 +82,7 @@ namespace TBF.Rig.Modbus.Easytherm
public void RunDeviceAfter()
{
if (easythermCfg.DebugLevel != Config.Entities.DebugMode.Simulate &&
easythermCfg.DebugLevel != Config.Entities.DebugMode.FailureDuringOperation)
if (modbus.IsMyTurn(ticketNumber))
{
if (!temperatureSetPointValid && !temperatureSetPointRequested)
{
@@ -169,7 +167,7 @@ namespace TBF.Rig.Modbus.Easytherm
msg[4] = (byte)(value >> 8); /// Data Hi
msg[5] = (byte)(value & 0xFF); /// Data Lo
modbus.SendMessage(msg);
modbus.SendMessage(msg, Name);
}
+1 -1
View File
@@ -164,7 +164,7 @@ namespace TBF.Rig.Modbus.Novus
msg[4] = (byte)(value >> 8); /// Data Hi
msg[5] = (byte)(value & 0xFF); /// Data Lo
modbus.SendMessage(msg);
modbus.SendMessage(msg, Name);
}
@@ -18,7 +18,8 @@ namespace TBF.Rig.Modbus.PressureMeter.Meret
readonly PressureMeterCfg pressureMtrCfg;
public IDrawingItem DrawingItem { get { return pressureMtrCfg as IDrawingItem; } }
readonly GenericDevices.IModbus modbus;
Common.Modbus modbus;
double receivedPressure;
public bool MsrmntAvailable { get { return true; } }
@@ -34,11 +35,6 @@ namespace TBF.Rig.Modbus.PressureMeter.Meret
: base(cfg)
{
pressureMtrCfg = cfg as PressureMeterCfg;
modbus = (GenericDevices.IModbus)TbfComponents.FindComponent(cfg.ParentName, components);
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
log.Warn(this.ToString());
}
///
@@ -46,17 +42,16 @@ namespace TBF.Rig.Modbus.PressureMeter.Meret
///
public override void Initialize()
{
modbus = TbfComponents.FindComponent(pressureMtrCfg.ParentName) as Common.Modbus;
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
modbus.ComponentNames[pressureMtrCfg.ModbusAddress] = Name;
ticketNumber = modbus.RegisterForPolling();
log.FatalFormat("{0} initialized: {1}", Name, this);
}
public void RunDeviceBefore()
{
if (pressureMtrCfg.DebugLevel == Config.Entities.DebugMode.Simulate ||
pressureMtrCfg.DebugLevel == Config.Entities.DebugMode.FailureDuringOperation)
{
return;
}
if (modbus.ReceivedTelegrams[pressureMtrCfg.ModbusAddress].Count > 0)
{
byte[] telegram = modbus.ReceivedTelegrams[pressureMtrCfg.ModbusAddress].Dequeue();
@@ -80,13 +75,11 @@ namespace TBF.Rig.Modbus.PressureMeter.Meret
public void RunDeviceAfter()
{
if (pressureMtrCfg.DebugLevel != Config.Entities.DebugMode.Simulate &&
pressureMtrCfg.DebugLevel != Config.Entities.DebugMode.FailureDuringOperation &&
modbus.IsMyTurn(ticketNumber))
if (modbus.IsMyTurn(ticketNumber))
{
const byte Function = 4; /// Read input registers
const ushort Address = 0; /// Pressure
modbus.SendMessage((byte)pressureMtrCfg.ModbusAddress, Function, Address, 2);
modbus.SendMessage((byte)pressureMtrCfg.ModbusAddress, Function, Address, 2, Name);
}
}
+2 -2
View File
@@ -227,7 +227,7 @@ namespace TBF.Rig.Modbus.PumpFM.DanfossVLT
msg[9] = (byte)(reference & 0xFF); /// Serial Com Reference Lo
msg[10] = (byte)(reference >> 8); /// Serial Com Reference Hi
///
modbus.SendMessage(msg);
modbus.SendMessage(msg, Name);
}
}
@@ -265,7 +265,7 @@ namespace TBF.Rig.Modbus.PumpFM.DanfossVLT
msg[10] = (byte)(reference >> 8); /// Serial Com Reference Hi
Telegram.UpdateTelegramCRC(msg);
modbus.SendMessage(msg);
modbus.SendMessage(msg, Name);
}
}
+4 -4
View File
@@ -150,19 +150,19 @@ namespace TBF.Rig.Modbus.QuidoRS
if (quidoRSCfg.Variant == QuidoVariant.QuidoRS_4_4)
{
modbus.SendMessage(new byte[] { addr, cmd, 0, 0, 0, 4, 1, dataLo, 0, 0 });
modbus.SendMessage(new byte[] { addr, cmd, 0, 0, 0, 4, 1, dataLo, 0, 0 }, Name);
}
else if (quidoRSCfg.Variant == QuidoVariant.QuidoRS_8_8)
{
modbus.SendMessage(new byte[] { addr, cmd, 0, 0, 0, 8, 1, dataLo, 0, 0 });
modbus.SendMessage(new byte[] { addr, cmd, 0, 0, 0, 8, 1, dataLo, 0, 0 }, Name);
}
else if (quidoRSCfg.Variant == QuidoVariant.QuidoRS_2_16)
{
modbus.SendMessage(new byte[] { addr, cmd, 0, 0, 0, 16, 2, dataLo, data2, 0, 0 });
modbus.SendMessage(new byte[] { addr, cmd, 0, 0, 0, 16, 2, dataLo, data2, 0, 0 }, Name);
}
else if (quidoRSCfg.Variant == QuidoVariant.QuidoRS_2_32)
{
modbus.SendMessage(new byte[] { addr, cmd, 0, 0, 0, 32, 4, dataLo, data2, data3, dataHi, 0, 0 });
modbus.SendMessage(new byte[] { addr, cmd, 0, 0, 0, 32, 4, dataLo, data2, data3, dataHi, 0, 0 }, Name);
}
lastOutputsChange = DateTime.Now;
+11 -14
View File
@@ -34,7 +34,7 @@ namespace TBF.Rig.Modbus.TempMeter.Groch
public SchematicDrawing.IDrawingItem DrawingItem { get { return tempMtrCfg as SchematicDrawing.IDrawingItem; } }
readonly Common.Modbus modbus;
Common.Modbus modbus;
static int[] tempRaw = new int[TempMeterCfg.ChannelsCount];
@@ -51,11 +51,6 @@ namespace TBF.Rig.Modbus.TempMeter.Groch
: base(cfg)
{
tempMtrCfg = cfg as TempMeterCfg;
modbus = TbfComponents.FindComponent(cfg.ParentName, components) as Common.Modbus;
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
log.Warn(this.ToString());
}
public override void Initialize()
@@ -63,8 +58,13 @@ namespace TBF.Rig.Modbus.TempMeter.Groch
/// Only TempMeter with Channel == 0 communicates via the parent Modbus component
if (Channel == 0)
{
modbus = TbfComponents.FindComponent(tempMtrCfg.ParentName) as Common.Modbus;
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
modbus.ComponentNames[0] = Name;
ticketNumber = modbus.RegisterForPolling();
}
log.FatalFormat("{0} initialized: {1}", Name, this);
}
@@ -101,14 +101,8 @@ namespace TBF.Rig.Modbus.TempMeter.Groch
public void RunDeviceBefore()
{
if (Channel != 0 ||
tempMtrCfg.DebugLevel == Config.Entities.DebugMode.Simulate ||
tempMtrCfg.DebugLevel == Config.Entities.DebugMode.FailureDuringOperation)
if (Channel == 0)
{
return;
}
///
/// Only TempMeter with Channel == 0 communicates via the parent Modbus component
///
if (modbus.ReceivedTelegrams[0].Count > 0)
@@ -145,6 +139,8 @@ namespace TBF.Rig.Modbus.TempMeter.Groch
}
}
}
}
public void RunDeviceAfter()
{
/// Only TempMeter with Channel == 0 communicates via the parent Modbus component
@@ -154,9 +150,10 @@ namespace TBF.Rig.Modbus.TempMeter.Groch
tempMtrCfg.DebugLevel != Config.Entities.DebugMode.FailureDuringOperation &&
modbus.IsMyTurn(ticketNumber))
{
modbus.SendMessageGroch(new byte[] { 0x20, 0x20, 0x20, 0x20, 0x10, 2, 1, 3, 6, 0x16 });
modbus.SendMessageGroch(new byte[] { 0x20, 0x20, 0x20, 0x20, 0x10, 2, 1, 3, 6, 0x16 }, Name);
}
}
public void StopDevice() { }
public void StopDevice2() { }
+8 -13
View File
@@ -18,7 +18,8 @@ namespace TBF.Rig.Modbus.TempMeter.Meret
readonly TempMeterCfg tempMtrCfg;
public IDrawingItem DrawingItem { get { return tempMtrCfg as IDrawingItem; } }
readonly GenericDevices.IModbus modbus;
Common.Modbus modbus;
double receivedTemp;
public bool MsrmntAvailable { get { return true; } }
@@ -34,16 +35,16 @@ namespace TBF.Rig.Modbus.TempMeter.Meret
: base(cfg)
{
tempMtrCfg = cfg as TempMeterCfg;
modbus = TbfComponents.FindComponent(cfg.ParentName, components) as GenericDevices.IModbus;
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
log.Warn(this.ToString());
}
public override void Initialize()
{
modbus = TbfComponents.FindComponent(tempMtrCfg.ParentName) as Common.Modbus;
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
modbus.ComponentNames[tempMtrCfg.ModbusAddress] = Name;
ticketNumber = modbus.RegisterForPolling();
log.FatalFormat("{0} initialized: {1}", Name, this);
}
///
@@ -52,12 +53,6 @@ namespace TBF.Rig.Modbus.TempMeter.Meret
/// <summary>Run this device</summary>
public void RunDeviceBefore()
{
if (tempMtrCfg.DebugLevel == Config.Entities.DebugMode.Simulate ||
tempMtrCfg.DebugLevel == Config.Entities.DebugMode.FailureDuringOperation)
{
return;
}
if (modbus.ReceivedTelegrams[tempMtrCfg.ModbusAddress].Count > 0)
{
byte[] telegram = modbus.ReceivedTelegrams[tempMtrCfg.ModbusAddress].Dequeue();
@@ -87,7 +82,7 @@ namespace TBF.Rig.Modbus.TempMeter.Meret
{
const byte Function = 4; /// Read input registers
const ushort Address = 0; /// Temperature
modbus.SendMessage((byte)tempMtrCfg.ModbusAddress, Function, Address, 2);
modbus.SendMessage((byte)tempMtrCfg.ModbusAddress, Function, Address, 2, Name);
}
}
@@ -17,7 +17,8 @@ namespace TBF.Rig.Modbus.UltrasoundLevelMeter
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
readonly LevelMeterCfg myCfg;
readonly Common.Modbus modbus;
Common.Modbus modbus;
///
/// Measured values when MsrmntState == MsrmntState.Valid
@@ -42,16 +43,14 @@ namespace TBF.Rig.Modbus.UltrasoundLevelMeter
: base(cfg)
{
myCfg = cfg as LevelMeterCfg;
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 override void Initialize()
{
modbus = TbfComponents.FindComponent(myCfg.ParentName) as Common.Modbus;
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
if (myCfg.DebugLevel == DebugMode.Simulate)
{
distance = 200.0;
@@ -61,12 +60,12 @@ namespace TBF.Rig.Modbus.UltrasoundLevelMeter
state = 0;
msrmntTimeStamp = StateMachine.Time;
log.FatalFormat("{0} - Device simulated", Name);
log.FatalFormat("{0} simulated: {1}", Name, this);
}
else
{
ticketNumber = modbus.RegisterForPolling();
log.FatalFormat("{0} - Device successfully initialized", Name);
log.FatalFormat("{0} initialized: {1}", Name, this);
}
}
@@ -140,7 +139,7 @@ namespace TBF.Rig.Modbus.UltrasoundLevelMeter
msg[3] = (byte)(regAddr & 0xFF); /// Control Word Lo
msg[4] = (byte)(count >> 8); /// Serial Com Reference Hi
msg[5] = (byte)(count & 0xFF); /// Serial Com Reference Lo
modbus.SendMessage(msg);
modbus.SendMessage(msg, Name);
/////
///// Read STATUS1
+9 -15
View File
@@ -17,7 +17,8 @@ namespace TBF.Rig.Modbus.WaterAnalyzer
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
readonly AnalyzerCfg myCfg;
readonly Common.Modbus modbus;
Common.Modbus modbus;
///
/// Measured values when MsrmntState == MsrmntState.Valid
@@ -39,28 +40,21 @@ namespace TBF.Rig.Modbus.WaterAnalyzer
: base(cfg)
{
myCfg = cfg as AnalyzerCfg;
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 override void Initialize()
{
if (myCfg.DebugLevel == DebugMode.Simulate)
{
modbus = TbfComponents.FindComponent(myCfg.ParentName) as Common.Modbus;
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
conductivity = 0.0F;
temperature = 0.0;
msrmntTimeStamp = 0;
msrmntTimeStamp = StateMachine.Time;
return;
}
modbus.ComponentNames[myCfg.ModbusAddress] = Name;
ticketNumber = modbus.RegisterForPolling();
log.FatalFormat("Successfully initialized device {0}", ToString());
log.FatalFormat("{0} initialized: {1}", Name, this);
}
@@ -123,7 +117,7 @@ namespace TBF.Rig.Modbus.WaterAnalyzer
msg[4] = (byte)(count >> 8); /// Serial Com Reference Hi
msg[5] = (byte)(count & 0xFF); /// Serial Com Reference Lo
modbus.SendMessage(msg);
modbus.SendMessage(msg, Name);
}
}
+1
View File
@@ -639,6 +639,7 @@
<Compile Include="Rig\Modbus\Ambient\Comet\Ambient.cs" />
<Compile Include="Rig\Modbus\Ambient\Comet\AmbientCfg.cs" />
<Compile Include="Rig\Modbus\Ambient\Comet\Factory.cs" />
<Compile Include="Rig\Modbus\Common\TelegramMeno.cs" />
<Compile Include="Rig\Modbus\Easytherm\Factory.cs" />
<Compile Include="Rig\Modbus\Easytherm\Easytherm.cs" />
<Compile Include="Rig\Modbus\Easytherm\EasythermCfg.cs" />