2020-08-24 09:51:44 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2020 Sensus Slovensko a.s.
|
|
|
|
|
|
///
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Xml.Serialization;
|
2021-09-23 09:46:40 +00:00
|
|
|
|
using Common;
|
2020-08-24 09:51:44 +00:00
|
|
|
|
using Config.Entities;
|
2021-10-26 09:23:57 +00:00
|
|
|
|
using TBF.Rig.Generic;
|
2020-08-24 09:51:44 +00:00
|
|
|
|
|
2021-10-26 09:23:57 +00:00
|
|
|
|
namespace TBF.Rig.Modbus.WaterAnalyzer2
|
2020-08-24 09:51:44 +00:00
|
|
|
|
{
|
2022-01-23 18:56:15 +00:00
|
|
|
|
public class AnalyzerCfg : ComponentCfgBase, Generic.IChildComponentCfg, IParamsProvider
|
2020-08-24 09:51:44 +00:00
|
|
|
|
{
|
|
|
|
|
|
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(AnalyzerCfg) })[0];
|
|
|
|
|
|
public override XmlSerializer GetSerializer() { return Serializer; }
|
|
|
|
|
|
|
2021-08-29 11:01:34 +00:00
|
|
|
|
public IComponentCfgCtrl GetControl(IList<Config.Entities.Component> cmpntEntities)
|
2020-08-24 09:51:44 +00:00
|
|
|
|
{
|
|
|
|
|
|
IList<string> parents = new List<string>();
|
|
|
|
|
|
// TODO:
|
|
|
|
|
|
//if (StateMachine.Components != null)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// foreach (var cmpnt in StateMachine.Components)
|
|
|
|
|
|
// {
|
2021-10-26 09:23:57 +00:00
|
|
|
|
// if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is TBF.Rig.Modbus.Common.Factory)
|
2020-08-24 09:51:44 +00:00
|
|
|
|
// {
|
|
|
|
|
|
// parents.Add(cmpnt.Name);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
|
|
parents.Add("Modbus");
|
|
|
|
|
|
parents.Add("ModbusUSB");
|
|
|
|
|
|
|
|
|
|
|
|
return new Configs.ParamsProvider.ComponentCfgCtrl(this, parents);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Serialized parameters
|
|
|
|
|
|
///
|
|
|
|
|
|
public byte ModbusAddress; /// 1..247
|
|
|
|
|
|
public double ConductiviyAt4mA;
|
|
|
|
|
|
public double ConductiviyAt20mA;
|
|
|
|
|
|
|
|
|
|
|
|
/// Private parameterless constructor invoked by all other (public) constructors
|
|
|
|
|
|
AnalyzerCfg() {}
|
|
|
|
|
|
|
|
|
|
|
|
public AnalyzerCfg(string name, IComponentFactory factory)
|
|
|
|
|
|
: this()
|
|
|
|
|
|
{
|
|
|
|
|
|
Factory = factory;
|
|
|
|
|
|
Name = name;
|
|
|
|
|
|
ParentName = "ModbusUSB";
|
|
|
|
|
|
InitializeAll();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string ComponentName { get { return Name; } }
|
|
|
|
|
|
|
|
|
|
|
|
public void InitializeAll()
|
|
|
|
|
|
{
|
|
|
|
|
|
ModbusAddress = 51;
|
|
|
|
|
|
ConductiviyAt4mA = 0; /// uS/cm
|
|
|
|
|
|
ConductiviyAt20mA = 1200; /// uS/cm
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string[] paramNames = new string[]
|
|
|
|
|
|
{
|
|
|
|
|
|
"Modbus address",
|
|
|
|
|
|
"Conductivity @4mA in uS/cm",
|
|
|
|
|
|
"Conductivity @20mA in uS/cm",
|
|
|
|
|
|
};
|
|
|
|
|
|
public string ParamName(int i) { return paramNames[i]; }
|
|
|
|
|
|
public int ParamsCount() { return paramNames.Length; }
|
2021-07-28 11:31:18 +00:00
|
|
|
|
public ICollection<string> ParamValues(int i) { return null; }
|
2020-08-24 09:51:44 +00:00
|
|
|
|
|
|
|
|
|
|
public string ToString(int i)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (i == -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
return string.Format("ModbusAddr={0}", ModbusAddress);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 0: return ModbusAddress.ToString();
|
|
|
|
|
|
case 1: return ConductiviyAt4mA.ToString();
|
|
|
|
|
|
case 2: return ConductiviyAt20mA.ToString();
|
|
|
|
|
|
default: return string.Empty;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (i)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
byte addr = byte.Parse(strValue);
|
|
|
|
|
|
if (ModbusAddress != addr)
|
|
|
|
|
|
{
|
|
|
|
|
|
ModbusAddress = addr;
|
|
|
|
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return CfgUpdateFlags.None;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
ConductiviyAt4mA = Utils.ParseUDouble(strValue);
|
|
|
|
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
ConductiviyAt20mA = Utils.ParseUDouble(strValue);
|
|
|
|
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
return CfgUpdateFlags.None;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool ValidateParam(int i, string strValue, out string message)
|
|
|
|
|
|
{
|
|
|
|
|
|
message = string.Empty;
|
|
|
|
|
|
int dummy;
|
|
|
|
|
|
double ddummy;
|
|
|
|
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
if (int.TryParse(strValue, out dummy) && dummy >= 1 && dummy <= 247) return true;
|
|
|
|
|
|
message = ParamName(i) + " is invalid. Address range is 1 .. 247";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
if (Utils.TryParseUDouble(strValue, out ddummy)) return true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
message = "Invalid index";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
message = ParamName(i) + " is invalid";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CopyContentTo(AnalyzerCfg prms)
|
|
|
|
|
|
{
|
|
|
|
|
|
prms.ParentName = this.ParentName;
|
|
|
|
|
|
prms.ModbusAddress = this.ModbusAddress;
|
|
|
|
|
|
prms.ConductiviyAt4mA = this.ConductiviyAt4mA;
|
|
|
|
|
|
prms.ConductiviyAt20mA = this.ConductiviyAt20mA;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-01-23 18:56:15 +00:00
|
|
|
|
public IParamsProvider Clone()
|
2020-08-24 09:51:44 +00:00
|
|
|
|
{
|
|
|
|
|
|
AnalyzerCfg pars = new AnalyzerCfg();
|
|
|
|
|
|
CopyContentTo(pars);
|
|
|
|
|
|
return pars;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool UpdateEmbeddedDbEntity()
|
|
|
|
|
|
{
|
|
|
|
|
|
return true; /// =OK, do nothing
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|