Refactorization : BenchControl -> Rig
This commit is contained in:
@@ -0,0 +1,217 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using log4net;
|
||||
using TBF.Rig.Generic;
|
||||
using TBF.Boxes;
|
||||
using Config.Entities;
|
||||
|
||||
namespace TBF.Rig.Modbus.Easytherm
|
||||
{
|
||||
public class Easytherm : ComponentBase, IDevice, GenericDevices.ITempMeter
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(Easytherm));
|
||||
public override string ToString() { return string.Format("Easytherm({0})", Cfg.ToString(1)); }
|
||||
|
||||
readonly EasythermCfg easythermCfg;
|
||||
readonly GenericDevices.IModbus modbus;
|
||||
|
||||
private float temperatureSetPoint;
|
||||
private bool temperatureSetPointValid;
|
||||
private bool temperatureSetPointRequested;
|
||||
|
||||
public float requiredTemp { get { return easythermCfg.ProcParams.RequiredTemp; } }
|
||||
|
||||
public Easytherm()
|
||||
{
|
||||
}
|
||||
|
||||
public Easytherm(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
|
||||
: 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 void Initialize()
|
||||
{
|
||||
if (easythermCfg.DebugLevel == DebugMode.Simulate) return;
|
||||
|
||||
temperatureSetPointValid = false;
|
||||
temperatureSetPointRequested = false;
|
||||
actualTemperatureIsValid = false;
|
||||
}
|
||||
|
||||
/// <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();
|
||||
if (telegram.Length == 7 && telegram[1] == (byte)Function.ReadHoldingRegisters && telegram[2] == 2)
|
||||
{
|
||||
ushort value = (ushort)(256 * telegram[3] + telegram[4]);
|
||||
temperatureSetPoint = (float)value * 0.04f;
|
||||
temperatureSetPointValid = true;
|
||||
|
||||
log.InfoFormat("{0} - Received current temperature setpoint = {1}", Name, temperatureSetPoint);
|
||||
}
|
||||
else if (telegram.Length == 7 && telegram[1] == (byte)Function.ReadInputRegister && telegram[2] == 2)
|
||||
{
|
||||
ushort value = (ushort)(256 * telegram[3] + telegram[4]);
|
||||
actualTemperature = (double)value * 0.04;
|
||||
actualTemperatureIsValid = true;
|
||||
|
||||
log.InfoFormat("{0} - Received actual temperature = {1}", Name, actualTemperature);
|
||||
|
||||
if (easythermCfg.ReservoirNr > 0 && easythermCfg.ReservoirNr <= 3)
|
||||
{
|
||||
// TODO: Reimplement IControlBoard.UpradateUI()
|
||||
//
|
||||
// StateMachine.ControlBoard.UpdateUI("ReservoirTemp", easythermCfg.ReservoirNr, actualTemperature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!temperatureSetPointValid && !temperatureSetPointRequested)
|
||||
{
|
||||
RequestTemperatureSetpoint();
|
||||
temperatureSetPointRequested = true;
|
||||
}
|
||||
else if (temperatureSetPointValid && requiredTemp != temperatureSetPoint)
|
||||
{
|
||||
SetTemperatureSetpoint(requiredTemp);
|
||||
log.InfoFormat("{0} - Set new temperature setpoint = {1}", Name, requiredTemp);
|
||||
}
|
||||
else if ((StateMachine.Time % 10) == (easythermCfg.ModbusAddress % 10)) /// This is to prevent overflow of the Modbus component queue for sending data
|
||||
{
|
||||
RequestActualTemperature();
|
||||
}
|
||||
}
|
||||
|
||||
public void RunDeviceAfter() { }
|
||||
public void StopDevice() { }
|
||||
public void StopDevice2() { }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Set Easytherm controller to required temperature procedure parameter
|
||||
/// </summary>
|
||||
/// <returns>true = OK, false = any error</returns>
|
||||
public bool SetTemperatureSetpoint()
|
||||
{
|
||||
return SetTemperatureSetpoint(requiredTemp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set Easytherm controller to specified temperature
|
||||
/// </summary>
|
||||
/// <param name="temperature">Temperature in °C</param>
|
||||
/// <returns>true = OK, false = any error</returns>
|
||||
public bool SetTemperatureSetpoint(float temperature)
|
||||
{
|
||||
if (temperature != 0 && (temperature < 5 || temperature > 95.0f))
|
||||
{
|
||||
return false; /// required temperature out of range
|
||||
}
|
||||
|
||||
if (temperatureSetPointValid && (temperature == temperatureSetPoint))
|
||||
{
|
||||
return true; /// already set to the required temperature
|
||||
}
|
||||
|
||||
if (temperature != 0) /// temperature==0 disables sending the setpoint
|
||||
{
|
||||
//ushort temperatureSetpoint = (ushort)temperature; // in °C
|
||||
//ushort destAddress = (ushort)1002;
|
||||
ushort usTempSetpoint = (ushort)((10000.0f / 400.0f) * temperature); // in 0.01% of range (400 °C)
|
||||
ushort destAddress = (ushort)2;
|
||||
///
|
||||
SendValueToEasytherm(Function.PresetSingleRegister, destAddress, usTempSetpoint);
|
||||
}
|
||||
|
||||
temperatureSetPoint = temperature;
|
||||
temperatureSetPointValid = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void RequestTemperatureSetpoint()
|
||||
{
|
||||
SendValueToEasytherm(Function.ReadHoldingRegisters, (ushort)2, (ushort)1); // rel.address=2, 1 word
|
||||
}
|
||||
|
||||
public void RequestActualTemperature()
|
||||
{
|
||||
SendValueToEasytherm(Function.ReadInputRegister, (ushort)0, (ushort)1); // rel.address=x, 1 word
|
||||
}
|
||||
|
||||
void SendValueToEasytherm(Function function, ushort address, ushort value)
|
||||
{
|
||||
byte[] msg = new byte[8];
|
||||
|
||||
msg[0] = easythermCfg.ModbusAddress;
|
||||
msg[1] = (byte)function;
|
||||
msg[2] = (byte)(address >> 8); /// Relative address Hi
|
||||
msg[3] = (byte)(address & 0xFF); /// Relative address Lo
|
||||
msg[4] = (byte)(value >> 8); /// Data Hi
|
||||
msg[5] = (byte)(value & 0xFF); /// Data Lo
|
||||
|
||||
modbus.SendMessage(msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
///
|
||||
/// Operations, etc.
|
||||
///
|
||||
|
||||
double actualTemperature;
|
||||
bool actualTemperatureIsValid;
|
||||
|
||||
public double ReadTemperature()
|
||||
{
|
||||
return actualTemperature;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Events: SetOpututsDone, Error
|
||||
/// </summary>
|
||||
/// <returns>SetOutputsOp instance reference casted to IOperaton</returns>
|
||||
public IOperation SetRequiredTemperatureOp()
|
||||
{
|
||||
return new SetRequiredTemperatureOp(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Events: SetOpututsDone, Error
|
||||
/// </summary>
|
||||
/// <param name="temperature">Reference to a variable for the pressure in Bar</param>
|
||||
/// <returns>SetOutputsOp instance reference casted to IOperaton</returns>
|
||||
public IOperation SetTemperatureOp(float temperature)
|
||||
{
|
||||
return new SetTemperatureOp(this, temperature);
|
||||
}
|
||||
|
||||
public IOperation ReadTempOp(ref DoubleBox temp)
|
||||
{
|
||||
return new ReadTempOp(this, ref temp);
|
||||
}
|
||||
|
||||
public IOperation ReadTempOp(ref DoubleBox temp, Event eventDone)
|
||||
{
|
||||
return new ReadTempOp(this, ref temp, eventDone);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
using Config.Entities;
|
||||
using TBF.Rig.Generic;
|
||||
|
||||
namespace TBF.Rig.Modbus.Easytherm
|
||||
{
|
||||
public class EasythermCfg : ComponentCfgBase, Generic.IChildComponentCfg
|
||||
{
|
||||
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(EasythermCfg) })[0];
|
||||
public override XmlSerializer GetSerializer() { return Serializer; }
|
||||
|
||||
public IComponentCfgCtrl GetControl(IList<Config.Entities.Component> cmpntEntities) { return new EasythermCfgCtrl(); }
|
||||
|
||||
///
|
||||
/// Serialized parameters
|
||||
///
|
||||
public byte ModbusAddress; /// 1..255
|
||||
public int ReservoirNr;
|
||||
|
||||
|
||||
/// <summary> Procedure parameters </summary>
|
||||
[XmlIgnore]
|
||||
public ProcParams ProcParams;
|
||||
public override IParamsProvider GetRuntimeProcParamsProvider() { return ProcParams; }
|
||||
public override IParamsProvider CreateProcParamsProvider() { return new ProcParams(true); }
|
||||
|
||||
|
||||
/// Private parameterless constructor invoked by all other (public) constructors
|
||||
EasythermCfg()
|
||||
{
|
||||
Name = "Easytherm";
|
||||
ParentName = "Modbus";
|
||||
ModbusAddress = 49;
|
||||
ProcParams = CreateProcParamsProvider() as ProcParams;
|
||||
}
|
||||
|
||||
public EasythermCfg(IComponentFactory factory)
|
||||
: this()
|
||||
{
|
||||
this.Factory = factory;
|
||||
}
|
||||
|
||||
public string ToString(int i)
|
||||
{
|
||||
return string.Format("Name={0}, ModbusAddr={1}, Parent={2}",
|
||||
Name,
|
||||
ModbusAddress,
|
||||
(string.IsNullOrEmpty(ParentName) ? "-" : ParentName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using Config.Entities;
|
||||
using TBF.Rig.Generic;
|
||||
using TBF.UI.Bench.Components;
|
||||
|
||||
namespace TBF.Rig.Modbus.Easytherm
|
||||
{
|
||||
public partial class EasythermCfgCtrl : UserControl, IComponentCfgCtrl
|
||||
{
|
||||
ComponentParametersDlg parent;
|
||||
|
||||
public bool ShowMore { get { return false; } }
|
||||
|
||||
EasythermCfg config;
|
||||
public IComponentCfg Config
|
||||
{
|
||||
get { return config as IComponentCfg; }
|
||||
set
|
||||
{
|
||||
config = value as EasythermCfg;
|
||||
Redraw();
|
||||
}
|
||||
}
|
||||
|
||||
public EasythermCfgCtrl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void QuidoRSCfgCtrl_Load(object sender, EventArgs e)
|
||||
{
|
||||
parent = ParentForm as ComponentParametersDlg;
|
||||
if (parent == null) return;
|
||||
|
||||
if (parent.CmpntEntities != null)
|
||||
{
|
||||
foreach (var cmpnt in parent.CmpntEntities)
|
||||
{
|
||||
if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is Modbus.Common.Factory)
|
||||
{
|
||||
parentNameComboBox.Items.Add(cmpnt.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Redraw();
|
||||
}
|
||||
|
||||
public void Closing()
|
||||
{
|
||||
}
|
||||
|
||||
void Redraw()
|
||||
{
|
||||
if (config == null) return; /// Control was not loaded, settings were not changed
|
||||
|
||||
componentNameLabel.Text = config.Factory.ClassName;
|
||||
nameTextBox.Text = config.Name;
|
||||
parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName;
|
||||
modbusAddressTextBox.Text = config.ModbusAddress.ToString();
|
||||
reservoirNrTextBox.Text = config.ReservoirNr.ToString();
|
||||
}
|
||||
|
||||
public void Unlock()
|
||||
{
|
||||
nameTextBox.Enabled = true;
|
||||
parentNameComboBox.Enabled = true;
|
||||
modbusAddressTextBox.Enabled = true;
|
||||
reservoirNrTextBox.Enabled = true;
|
||||
}
|
||||
|
||||
public CfgUpdateFlags VerifyCfg(ref string message)
|
||||
{
|
||||
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
||||
|
||||
int dummy;
|
||||
if (!parentNameComboBox.Items.Contains(parentNameComboBox.Text))
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "Invalid 'Parent Name'";
|
||||
}
|
||||
if (!int.TryParse(modbusAddressTextBox.Text, out dummy) || dummy < 0 || dummy > 255)
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "'Modbus Address' should be between 0 and 255";
|
||||
}
|
||||
if (!int.TryParse(reservoirNrTextBox.Text, out dummy) || dummy < 0 || dummy > 3)
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "'Reservoir Nr.' should be between 0 and 3";
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
public CfgUpdateFlags UpdateCfg()
|
||||
{
|
||||
CfgUpdateFlags flags = CfgUpdateFlags.RestartRqrd;
|
||||
|
||||
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
|
||||
|
||||
config.Name = nameTextBox.Text;
|
||||
config.ParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text;
|
||||
config.ModbusAddress = (byte)int.Parse(modbusAddressTextBox.Text);
|
||||
config.ReservoirNr = int.Parse(reservoirNrTextBox.Text);
|
||||
|
||||
return flags;
|
||||
}
|
||||
}
|
||||
}
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
namespace TBF.Rig.Modbus.Easytherm
|
||||
{
|
||||
partial class EasythermCfgCtrl
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Component Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.parentNameLabel = new System.Windows.Forms.Label();
|
||||
this.nameTextBox = new System.Windows.Forms.TextBox();
|
||||
this.nameLabel = new System.Windows.Forms.Label();
|
||||
this.componentNameLabel = new System.Windows.Forms.Label();
|
||||
this.modbusAddressLabel = new System.Windows.Forms.Label();
|
||||
this.modbusAddressTextBox = new System.Windows.Forms.TextBox();
|
||||
this.parentNameComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.reservoirNrTextBox = new System.Windows.Forms.TextBox();
|
||||
this.reservoirNrLabel = new System.Windows.Forms.Label();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// parentNameLabel
|
||||
//
|
||||
this.parentNameLabel.AutoSize = true;
|
||||
this.parentNameLabel.Location = new System.Drawing.Point(28, 81);
|
||||
this.parentNameLabel.Name = "parentNameLabel";
|
||||
this.parentNameLabel.Size = new System.Drawing.Size(69, 13);
|
||||
this.parentNameLabel.TabIndex = 3;
|
||||
this.parentNameLabel.Text = "Parent Name";
|
||||
//
|
||||
// nameTextBox
|
||||
//
|
||||
this.nameTextBox.Enabled = false;
|
||||
this.nameTextBox.Location = new System.Drawing.Point(138, 52);
|
||||
this.nameTextBox.Name = "nameTextBox";
|
||||
this.nameTextBox.Size = new System.Drawing.Size(130, 20);
|
||||
this.nameTextBox.TabIndex = 2;
|
||||
//
|
||||
// nameLabel
|
||||
//
|
||||
this.nameLabel.AutoSize = true;
|
||||
this.nameLabel.Location = new System.Drawing.Point(28, 55);
|
||||
this.nameLabel.Name = "nameLabel";
|
||||
this.nameLabel.Size = new System.Drawing.Size(35, 13);
|
||||
this.nameLabel.TabIndex = 1;
|
||||
this.nameLabel.Text = "Name";
|
||||
//
|
||||
// componentNameLabel
|
||||
//
|
||||
this.componentNameLabel.AutoSize = true;
|
||||
this.componentNameLabel.Location = new System.Drawing.Point(135, 28);
|
||||
this.componentNameLabel.Name = "componentNameLabel";
|
||||
this.componentNameLabel.Size = new System.Drawing.Size(83, 13);
|
||||
this.componentNameLabel.TabIndex = 0;
|
||||
this.componentNameLabel.Text = "ComonentName";
|
||||
//
|
||||
// modbusAddressLabel
|
||||
//
|
||||
this.modbusAddressLabel.AutoSize = true;
|
||||
this.modbusAddressLabel.Location = new System.Drawing.Point(28, 108);
|
||||
this.modbusAddressLabel.Name = "modbusAddressLabel";
|
||||
this.modbusAddressLabel.Size = new System.Drawing.Size(86, 13);
|
||||
this.modbusAddressLabel.TabIndex = 7;
|
||||
this.modbusAddressLabel.Text = "Modbus Address";
|
||||
//
|
||||
// modbusAddressTextBox
|
||||
//
|
||||
this.modbusAddressTextBox.Enabled = false;
|
||||
this.modbusAddressTextBox.Location = new System.Drawing.Point(138, 105);
|
||||
this.modbusAddressTextBox.Name = "modbusAddressTextBox";
|
||||
this.modbusAddressTextBox.Size = new System.Drawing.Size(46, 20);
|
||||
this.modbusAddressTextBox.TabIndex = 8;
|
||||
//
|
||||
// parentNameComboBox
|
||||
//
|
||||
this.parentNameComboBox.Enabled = false;
|
||||
this.parentNameComboBox.FormattingEnabled = true;
|
||||
this.parentNameComboBox.Location = new System.Drawing.Point(138, 78);
|
||||
this.parentNameComboBox.Name = "parentNameComboBox";
|
||||
this.parentNameComboBox.Size = new System.Drawing.Size(130, 21);
|
||||
this.parentNameComboBox.TabIndex = 4;
|
||||
//
|
||||
// reservoirNrTextBox
|
||||
//
|
||||
this.reservoirNrTextBox.Enabled = false;
|
||||
this.reservoirNrTextBox.Location = new System.Drawing.Point(138, 130);
|
||||
this.reservoirNrTextBox.Name = "reservoirNrTextBox";
|
||||
this.reservoirNrTextBox.Size = new System.Drawing.Size(46, 20);
|
||||
this.reservoirNrTextBox.TabIndex = 10;
|
||||
//
|
||||
// reservoirNrLabel
|
||||
//
|
||||
this.reservoirNrLabel.AutoSize = true;
|
||||
this.reservoirNrLabel.Location = new System.Drawing.Point(28, 133);
|
||||
this.reservoirNrLabel.Name = "reservoirNrLabel";
|
||||
this.reservoirNrLabel.Size = new System.Drawing.Size(67, 13);
|
||||
this.reservoirNrLabel.TabIndex = 9;
|
||||
this.reservoirNrLabel.Text = "Reservoir nr.";
|
||||
//
|
||||
// EasythermCfgCtrl
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.Controls.Add(this.reservoirNrTextBox);
|
||||
this.Controls.Add(this.reservoirNrLabel);
|
||||
this.Controls.Add(this.parentNameComboBox);
|
||||
this.Controls.Add(this.modbusAddressTextBox);
|
||||
this.Controls.Add(this.modbusAddressLabel);
|
||||
this.Controls.Add(this.parentNameLabel);
|
||||
this.Controls.Add(this.nameTextBox);
|
||||
this.Controls.Add(this.nameLabel);
|
||||
this.Controls.Add(this.componentNameLabel);
|
||||
this.Name = "EasythermCfgCtrl";
|
||||
this.Size = new System.Drawing.Size(300, 200);
|
||||
this.Load += new System.EventHandler(this.QuidoRSCfgCtrl_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Label parentNameLabel;
|
||||
private System.Windows.Forms.TextBox nameTextBox;
|
||||
private System.Windows.Forms.Label nameLabel;
|
||||
private System.Windows.Forms.Label componentNameLabel;
|
||||
private System.Windows.Forms.Label modbusAddressLabel;
|
||||
private System.Windows.Forms.TextBox modbusAddressTextBox;
|
||||
private System.Windows.Forms.ComboBox parentNameComboBox;
|
||||
private System.Windows.Forms.TextBox reservoirNrTextBox;
|
||||
private System.Windows.Forms.Label reservoirNrLabel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -0,0 +1,27 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
using System.Collections.Generic;
|
||||
using TBF.Rig.Generic;
|
||||
|
||||
namespace TBF.Rig.Modbus.Easytherm
|
||||
{
|
||||
public class Factory : IComponentFactory
|
||||
{
|
||||
public string ClassName { get { return this.GetType().Namespace.Substring(8); } }
|
||||
public override string ToString() { return ClassName; }
|
||||
|
||||
public void ResetStaticProperties() { Easytherm.ResetStaticProperties(); }
|
||||
|
||||
public IComponent DummyComponent() { return new Easytherm(); }
|
||||
|
||||
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new Easytherm(cfg, components); }
|
||||
|
||||
public IComponentCfg DefaultConfig() { return new EasythermCfg(this); }
|
||||
|
||||
public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component)
|
||||
{
|
||||
return ComponentCfgBase.CreateFromDbEntity(EasythermCfg.Serializer, component, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
using System.IO;
|
||||
using System.Xml.Serialization;
|
||||
using Config.Entities;
|
||||
using TBF.Rig.Generic;
|
||||
using TBF.Resources;
|
||||
|
||||
namespace TBF.Rig.Modbus.Easytherm
|
||||
{
|
||||
public class ProcParams : ProcedureParamsBase, IParamsProvider, IProcedureParams
|
||||
{
|
||||
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(ProcParams) })[0];
|
||||
public override XmlSerializer GetSerializer() { return Serializer; }
|
||||
|
||||
public float RequiredTemp; /// [°C] target temperature for a temperature controller or 0=not communicated to the controller
|
||||
|
||||
|
||||
public override void InitializeAll()
|
||||
{
|
||||
RequiredTemp = 0.0f;
|
||||
}
|
||||
|
||||
string[] paramNames = new string[]
|
||||
{
|
||||
Strings.Required_temperature_C,
|
||||
};
|
||||
public override string ParamName(int i) { return paramNames[i]; }
|
||||
public override int ParamsCount() { return paramNames.Length; }
|
||||
|
||||
public override string ToString(int i)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0: return (RequiredTemp == 0) ? "---" : RequiredTemp.ToString();
|
||||
default: return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
if (strValue == "-" || strValue == "--" || strValue == "---")
|
||||
{
|
||||
RequiredTemp = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
RequiredTemp = Utils.ParseUFloat(strValue);
|
||||
}
|
||||
return CfgUpdateFlags.None;
|
||||
default:
|
||||
return CfgUpdateFlags.None;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifiy the string representation of the parameter
|
||||
/// </summary>
|
||||
/// <param name="i">Parameter ID</param>
|
||||
/// <param name="strValue">String representation of the parameter</param>
|
||||
/// <param name="message">In case false is returned this is the error messsage to be displayed</param>
|
||||
/// <returns>true = parameter OK, false = parameter NOK</returns>
|
||||
public bool ValidateParam(int i, string strValue, out string message)
|
||||
{
|
||||
message = string.Empty;
|
||||
|
||||
float temp;
|
||||
switch (i)
|
||||
{
|
||||
case 0: /// T_hot_heating
|
||||
if (strValue == "-" || strValue == "--" || strValue == "---" ||
|
||||
(Utils.TryParseUFloat(strValue, out temp) && (temp == 0 || (temp >= 5 && temp <= 95.0f))))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
message = "Invalid index";
|
||||
return false;
|
||||
}
|
||||
|
||||
message = ParamName(i) + " is invalid";
|
||||
return false;
|
||||
}
|
||||
|
||||
void CopyContentTo(ProcParams prms)
|
||||
{
|
||||
prms.RequiredTemp = this.RequiredTemp;
|
||||
}
|
||||
|
||||
public IParamsProvider Clone()
|
||||
{
|
||||
ProcParams pars = new ProcParams();
|
||||
CopyContentTo(pars);
|
||||
return pars;
|
||||
}
|
||||
|
||||
public override void UpdateFromDbEntity(ComponentProcedure dbEntity)
|
||||
{
|
||||
if (dbEntity == null) return;
|
||||
try
|
||||
{
|
||||
ProcParams tmp = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as ProcParams;
|
||||
|
||||
procedureParamsEntity = dbEntity;
|
||||
componentName = dbEntity.CmpntName;
|
||||
procedure = dbEntity.Procedure;
|
||||
|
||||
if (tmp != null) tmp.CopyContentTo(this);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parameterless constructor initializes the parameters
|
||||
/// </summary>
|
||||
public ProcParams()
|
||||
{
|
||||
}
|
||||
|
||||
public ProcParams(bool initialize)
|
||||
{
|
||||
if (initialize) InitializeAll();
|
||||
}
|
||||
|
||||
public ProcParams(ComponentProcedure procParamsEntity, string componentName, Procedure procedure)
|
||||
{
|
||||
this.procedureParamsEntity = procParamsEntity;
|
||||
this.componentName = componentName;
|
||||
this.procedure = procedure;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using log4net;
|
||||
using TBF.Boxes;
|
||||
|
||||
namespace TBF.Rig.Modbus.Easytherm
|
||||
{
|
||||
public class ReadTempOp : IOperation
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(ReadTempOp));
|
||||
public override string ToString() { return string.Format("ReadTempOp({0},.,{1})", easytherm.Name, eventDone); }
|
||||
|
||||
/// Set by the constructor
|
||||
Easytherm easytherm;
|
||||
Event eventDone;
|
||||
DoubleBox temp;
|
||||
|
||||
/// <summary>
|
||||
/// Events: TempInDone, TempOutDone, TempDivDone or Error
|
||||
/// </summary>
|
||||
/// <param name="easytherm">TempMeter reference</param>
|
||||
/// <param name="temp">Reference to the variable, value is in degree Celsius</param>
|
||||
/// <param name="eventDone">Event to be returned by Run() when completed OK</param>
|
||||
public ReadTempOp(Easytherm easytherm, ref DoubleBox temp, Event eventDone)
|
||||
{
|
||||
if (easytherm == null) throw new ArgumentNullException("easytherm");
|
||||
this.easytherm = easytherm;
|
||||
this.temp = temp;
|
||||
this.eventDone = eventDone;
|
||||
log.Debug(this.ToString());
|
||||
}
|
||||
|
||||
public ReadTempOp(Easytherm tempMeter, ref DoubleBox temp)
|
||||
: this(tempMeter, ref temp, Event.TempDone)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>Start this operation</summary>
|
||||
public void Start()
|
||||
{
|
||||
temp.Val = easytherm.ReadTemperature();
|
||||
}
|
||||
|
||||
/// <summary>Run this operation</summary>
|
||||
/// <returns>
|
||||
/// Event.TempInDone, Event.TempOutDone or Event.TempDivDone
|
||||
/// </returns>
|
||||
public Event Run()
|
||||
{
|
||||
temp.Val = easytherm.ReadTemperature();
|
||||
return eventDone;
|
||||
}
|
||||
|
||||
/// <summary>Stop this operation</summary>
|
||||
public void Stop()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using log4net;
|
||||
using TBF.Boxes;
|
||||
|
||||
namespace TBF.Rig.Modbus.Easytherm
|
||||
{
|
||||
public class SetRequiredTemperatureOp : IOperation
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(SetRequiredTemperatureOp));
|
||||
public override string ToString() { return string.Format("SetRequiredTemperatureOp({0})", eventDone); }
|
||||
|
||||
/// Set by the constructor
|
||||
readonly Easytherm easytherm;
|
||||
readonly Event eventDone;
|
||||
|
||||
/// <summary>
|
||||
/// Events: PressureInDone, PressureOutDone or Error
|
||||
/// </summary>
|
||||
/// <param name="easytherm">Pressure meter reference</param>
|
||||
/// <param name="pressure">Reference to the measured pressure variable, value is in bar</param>
|
||||
/// <param name="eventDone">Event to be returned by Run() when completed OK</param>
|
||||
public SetRequiredTemperatureOp(Easytherm easytherm, Event eventDone)
|
||||
{
|
||||
if (easytherm == null) throw new ArgumentNullException("easytherm");
|
||||
this.easytherm = easytherm;
|
||||
this.eventDone = eventDone;
|
||||
|
||||
log.Debug(this.ToString());
|
||||
}
|
||||
public SetRequiredTemperatureOp(Easytherm easytherm)
|
||||
: this(easytherm, Event.ConditionMet)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>Start this operation</summary>
|
||||
public void Start()
|
||||
{
|
||||
easytherm.SetTemperatureSetpoint();
|
||||
}
|
||||
|
||||
/// <summary>Run this operation</summary>
|
||||
public Event Run()
|
||||
{
|
||||
return eventDone;
|
||||
}
|
||||
|
||||
/// <summary>Stop this operation</summary>
|
||||
public void Stop()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using log4net;
|
||||
using TBF.Boxes;
|
||||
|
||||
namespace TBF.Rig.Modbus.Easytherm
|
||||
{
|
||||
public class SetTemperatureOp : IOperation
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(SetTemperatureOp));
|
||||
public override string ToString() { return string.Format("SetTemperatureOp({0},{1})", temperatureSetpoint, eventDone); }
|
||||
|
||||
/// Set by the constructor
|
||||
readonly Easytherm easytherm;
|
||||
readonly Event eventDone;
|
||||
float temperatureSetpoint;
|
||||
|
||||
/// <summary>
|
||||
/// Events: PressureInDone, PressureOutDone or Error
|
||||
/// </summary>
|
||||
/// <param name="easytherm">Pressure meter reference</param>
|
||||
/// <param name="pressure">Reference to the measured pressure variable, value is in bar</param>
|
||||
/// <param name="eventDone">Event to be returned by Run() when completed OK</param>
|
||||
public SetTemperatureOp(Easytherm easytherm, float temperatureSetpoint, Event eventDone)
|
||||
{
|
||||
if (easytherm == null) throw new ArgumentNullException("easytherm");
|
||||
this.easytherm = easytherm;
|
||||
this.temperatureSetpoint = temperatureSetpoint;
|
||||
this.eventDone = eventDone;
|
||||
|
||||
log.Debug(this.ToString());
|
||||
}
|
||||
public SetTemperatureOp(Easytherm easytherm, float temperatureSetpoint)
|
||||
: this(easytherm, temperatureSetpoint, Event.SetOutputsDone)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>Start this operation</summary>
|
||||
public void Start()
|
||||
{
|
||||
easytherm.SetTemperatureSetpoint(temperatureSetpoint);
|
||||
}
|
||||
|
||||
/// <summary>Run this operation</summary>
|
||||
public Event Run()
|
||||
{
|
||||
return eventDone;
|
||||
}
|
||||
|
||||
/// <summary>Stop this operation</summary>
|
||||
public void Stop()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user