108 lines
3.3 KiB
C#
108 lines
3.3 KiB
C#
using System;
|
|
using System.Xml.Serialization;
|
|
using Config.Entities;
|
|
using TBF.Rig.Generic;
|
|
|
|
namespace TBF.Rig.Modbus.ConductivityMeter
|
|
{
|
|
public enum ModbusReadFunction
|
|
{
|
|
ReadHoldingRegisters_03 = 3,
|
|
ReadInputRegisters_04 = 4
|
|
}
|
|
|
|
public enum RawFormat
|
|
{
|
|
Counts16bit,
|
|
Milliamps_x1000
|
|
}
|
|
|
|
public class ConductivityMeterCfg : ComponentCfgBase, Generic.IChildComponentCfg
|
|
{
|
|
public static XmlSerializer Serializer =
|
|
XmlSerializer.FromTypes(new[] { typeof(ConductivityMeterCfg) })[0];
|
|
|
|
public override XmlSerializer GetSerializer() { return Serializer; }
|
|
|
|
public IComponentCfgCtrl GetControl(System.Collections.Generic.IList<Component> cmpntEntities)
|
|
{
|
|
return new ConductivityMeterCfgCtrl();
|
|
}
|
|
|
|
/// Modbus link (parent component is Common.Modbus)
|
|
public string ParentName; // Modbus component name
|
|
public byte ModbusAddress; // 1..247
|
|
public ModbusReadFunction ReadFunction; // 03 or 04
|
|
public ushort FirstRegister; // start register address on AD4RS
|
|
public ushort RegisterCount; // 1..4 typically
|
|
public bool EnablePolling;
|
|
|
|
/// Which channel to use for conductivity value
|
|
public int Channel; // 0..(RegisterCount-1)
|
|
|
|
/// Raw format and scaling
|
|
public RawFormat RawFormat;
|
|
public double RawAt4mA; // used when RawFormat == Counts16bit
|
|
public double RawAt20mA; // used when RawFormat == Counts16bit
|
|
|
|
public double CondAt4mA; // e.g. 0 uS/cm
|
|
public double CondAt20mA; // e.g. 2000 uS/cm
|
|
|
|
public string MsrdUnit; // "uS/cm"
|
|
public string MsrdFormat; // "{0:0}"
|
|
public double MsrdValLimLo;
|
|
public double MsrdValLimHi;
|
|
|
|
public int FreshnessMs;
|
|
|
|
ConductivityMeterCfg()
|
|
{
|
|
Name = "ConductivityMeter";
|
|
ParentName = "Modbus";
|
|
ModbusAddress = 50;
|
|
|
|
ReadFunction = ModbusReadFunction.ReadInputRegisters_04;
|
|
FirstRegister = 0;
|
|
RegisterCount = 1;
|
|
EnablePolling = true;
|
|
|
|
Channel = 0;
|
|
|
|
RawFormat = RawFormat.Counts16bit;
|
|
RawAt4mA = 13107;
|
|
RawAt20mA = 65535;
|
|
|
|
CondAt4mA = 0;
|
|
CondAt20mA = 2000;
|
|
|
|
MsrdUnit = "uS/cm";
|
|
MsrdFormat = "{0:0}";
|
|
MsrdValLimLo = 0;
|
|
MsrdValLimHi = 5000;
|
|
|
|
FreshnessMs = 3000;
|
|
}
|
|
|
|
public ConductivityMeterCfg(IComponentFactory factory) : this()
|
|
{
|
|
this.Factory = factory;
|
|
}
|
|
|
|
public string ToString(int i)
|
|
{
|
|
return string.Format(
|
|
"{0}: Parent={1}, Addr={2}, Fn={3}, Reg={4}, Cnt={5}, Ch={6}, RawFormat={7}, Cond={8}..{9} {10}",
|
|
Name,
|
|
string.IsNullOrEmpty(ParentName) ? "-" : ParentName,
|
|
ModbusAddress,
|
|
(int)ReadFunction,
|
|
FirstRegister,
|
|
RegisterCount,
|
|
Channel,
|
|
RawFormat,
|
|
CondAt4mA,
|
|
CondAt20mA,
|
|
MsrdUnit);
|
|
}
|
|
}
|
|
} |