Modbus.PressureMeter.Meret implemented, ver. 2.11.372
This commit is contained in:
parent
93e8328940
commit
08d854f6f8
@ -14,10 +14,10 @@ namespace TBF.BenchControl.Modbus.PressureMeter.Meret
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(PressureMeter));
|
||||
public override string ToString() { return string.Format("PressureMeter({0})", Cfg.ToString(1)); }
|
||||
|
||||
readonly PressureMeterCfg pressureMeterCfg;
|
||||
readonly PressureMeterCfg pressureMtrCfg;
|
||||
readonly GenericDevices.IModbus modbus;
|
||||
|
||||
private ushort currentOutputs;
|
||||
private float receivedPressure;
|
||||
|
||||
const ushort WatchdogBitMask = 0x0010;
|
||||
|
||||
@ -28,7 +28,7 @@ namespace TBF.BenchControl.Modbus.PressureMeter.Meret
|
||||
public PressureMeter(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
|
||||
: base(cfg)
|
||||
{
|
||||
pressureMeterCfg = cfg as PressureMeterCfg;
|
||||
pressureMtrCfg = cfg as PressureMeterCfg;
|
||||
|
||||
modbus = (GenericDevices.IModbus)TbfComponents.FindComponent(cfg.ParentName, components);
|
||||
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
|
||||
@ -51,7 +51,7 @@ namespace TBF.BenchControl.Modbus.PressureMeter.Meret
|
||||
/// <returns>Pressure in mBar</returns>
|
||||
public float ReadPressure()
|
||||
{
|
||||
return (float)Config.Units.ConvertFrom(Config.Unit.kPa, 1.0F);
|
||||
return (float)Config.Units.ConvertFrom(Config.Unit.kPa, receivedPressure);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -79,13 +79,32 @@ namespace TBF.BenchControl.Modbus.PressureMeter.Meret
|
||||
/// <summary>Run this device</summary>
|
||||
public void RunDeviceBefore()
|
||||
{
|
||||
if (modbus.ReceivedTelegrams[pressureMtrCfg.ModbusAddress].Count > 0)
|
||||
{
|
||||
byte[] telegram = modbus.ReceivedTelegrams[pressureMtrCfg.ModbusAddress].Dequeue();
|
||||
if (telegram.Length == 9 && telegram[1] == 4 && telegram[2] == 4)
|
||||
{
|
||||
/// Swap byte order
|
||||
byte t1 = telegram[3];
|
||||
byte t2 = telegram[4];
|
||||
byte t3 = telegram[5];
|
||||
byte t4 = telegram[6];
|
||||
telegram[3] = t4;
|
||||
telegram[4] = t3;
|
||||
telegram[5] = t2;
|
||||
telegram[6] = t1;
|
||||
|
||||
receivedPressure = System.BitConverter.ToSingle(telegram, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Run this device</summary>
|
||||
public void RunDeviceAfter()
|
||||
{
|
||||
currentOutputs = (UInt16)((Int32)currentOutputs ^ (Int32)WatchdogBitMask);
|
||||
//SendOutputs(currentOutputs);
|
||||
const byte Function = 4; /// Read input registers
|
||||
const ushort Address = 0; /// Pressure
|
||||
modbus.SendMessage(pressureMtrCfg.ModbusAddress, Function, Address, 2);
|
||||
}
|
||||
|
||||
/// <summary>Stop this device</summary>
|
||||
|
||||
@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("2.11.371.1")]
|
||||
[assembly: AssemblyFileVersion("2.11.371.1")]
|
||||
[assembly: AssemblyVersion("2.11.372.1")]
|
||||
[assembly: AssemblyFileVersion("2.11.372.1")]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user