BenchControl.Uni.Diverter/FlowMeter/RegReader added, etc. (many changes and refactorization).

This commit is contained in:
Milan Hanajik
2021-02-24 14:15:10 +01:00
parent 5325d7f6ee
commit 4cf4192ebb
163 changed files with 6766 additions and 1041 deletions
@@ -8,7 +8,7 @@ using Config.Entities;
using TBF.BenchControl.Generic;
using TBF.Boxes;
namespace TBF.BenchControl.Modbus.CometAmbient
namespace TBF.BenchControl.Modbus.Ambient.Comet
{
/// <summary>
/// Ambient temperature / humidity / pressure meter 'Greco' connected via serial interface (RS232)
@@ -6,7 +6,7 @@ using System.Xml.Serialization;
using Config.Entities;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Modbus.CometAmbient
namespace TBF.BenchControl.Modbus.Ambient.Comet
{
public class AmbientCfg : ComponentCfgBase, Generic.IChildComponentCfg
{
@@ -1,7 +1,7 @@
///
/// Copyright (c) 2017 Sensus Metering Systems
///
namespace TBF.BenchControl.Modbus.CometAmbient
namespace TBF.BenchControl.Modbus.Ambient.Comet
{
partial class AmbientCfgCtrl
{
@@ -7,7 +7,7 @@ using Config.Entities;
using TBF.BenchControl.Generic;
using TBF.UI.Bench.Components;
namespace TBF.BenchControl.Modbus.CometAmbient
namespace TBF.BenchControl.Modbus.Ambient.Comet
{
public partial class AmbientCfgCtrl : UserControl, IComponentCfgCtrl
{
@@ -4,7 +4,7 @@
using System.Collections.Generic;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Modbus.CometAmbient
namespace TBF.BenchControl.Modbus.Ambient.Comet
{
public class Factory : IComponentFactory
{
@@ -4,7 +4,7 @@
using System.Collections.Generic;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Modbus.Meret.PressureMeter
namespace TBF.BenchControl.Modbus.PressureMeter.Meret
{
public class Factory : IComponentFactory
{
@@ -8,7 +8,7 @@ using SchematicDrawing;
using TBF.BenchControl.Generic;
using TBF.Boxes;
namespace TBF.BenchControl.Modbus.Meret.PressureMeter
namespace TBF.BenchControl.Modbus.PressureMeter.Meret
{
public class PressureMeter : ComponentBase, GenericDevices.IPressureMeter, IDevice, IDrawingItCmpntWithMeasuredVal
{
@@ -7,7 +7,7 @@ using SchematicDrawing;
using TBF.BenchControl.Generic;
using System.Collections.Generic;
namespace TBF.BenchControl.Modbus.Meret.PressureMeter
namespace TBF.BenchControl.Modbus.PressureMeter.Meret
{
public class PressureMeterCfg : ComponentCfgBase, Generic.IChildComponentCfg, IDrawingItemWithMeasuredVal
{
@@ -7,7 +7,7 @@ using Config.Entities;
using TBF.BenchControl.Generic;
using TBF.UI.Bench.Components;
namespace TBF.BenchControl.Modbus.Meret.PressureMeter
namespace TBF.BenchControl.Modbus.PressureMeter.Meret
{
public partial class PressureMeterCfgCtrl : UserControl, IComponentCfgCtrl
{
@@ -1,7 +1,7 @@
///
/// Copyright (c) 2016-2020 Sensus Slovensko a.s.
///
namespace TBF.BenchControl.Modbus.Meret.PressureMeter
namespace TBF.BenchControl.Modbus.PressureMeter.Meret
{
partial class PressureMeterCfgCtrl
{
@@ -5,7 +5,7 @@ using System;
using log4net;
using TBF.Boxes;
namespace TBF.BenchControl.Modbus.Meret.PressureMeter
namespace TBF.BenchControl.Modbus.PressureMeter.Meret
{
public class ReadPressureOp : IOperation
{
@@ -4,7 +4,7 @@
using System.Collections.Generic;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Modbus.Danfoss.VLT
namespace TBF.BenchControl.Modbus.PumpFM.DanfossVLT
{
public class Factory : IComponentFactory
{
@@ -13,7 +13,7 @@ using SchematicDrawing;
using TBF.BenchControl.ControlBoard;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Modbus.Danfoss.VLT
namespace TBF.BenchControl.Modbus.PumpFM.DanfossVLT
{
/// <summary>
/// See page 20 of MG10S202 Operational Instructions Modbus RTU
@@ -7,7 +7,7 @@ using SchematicDrawing;
using TBF.BenchControl.Generic;
using System.Collections.Generic;
namespace TBF.BenchControl.Modbus.Danfoss.VLT
namespace TBF.BenchControl.Modbus.PumpFM.DanfossVLT
{
public class PumpCfg : ComponentCfgBase, Generic.IChildComponentCfg, IRouteBasedDrawingItem, IDrawingItemWithSetpoint
{
@@ -7,7 +7,7 @@ using Config.Entities;
using TBF.BenchControl.Generic;
using TBF.UI.Bench.Components;
namespace TBF.BenchControl.Modbus.Danfoss.VLT
namespace TBF.BenchControl.Modbus.PumpFM.DanfossVLT
{
public partial class PumpCfgCtrl : UserControl, IComponentCfgCtrl
{
@@ -1,7 +1,7 @@
///
/// Copyright (c) 2020 Sensus Slovensko a.s.
///
namespace TBF.BenchControl.Modbus.Danfoss.VLT
namespace TBF.BenchControl.Modbus.PumpFM.DanfossVLT
{
partial class PumpCfgCtrl
{
@@ -0,0 +1,27 @@
///
/// Copyright (c) 2021 Sensus Metering Systems
///
using System.Collections.Generic;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Modbus.TempMeter.Groch
{
public class Factory : IComponentFactory
{
public string ClassName { get { return this.GetType().Namespace.Substring(17); } }
public override string ToString() { return ClassName; }
public void ResetStaticProperties() { TempMeter.ResetStaticProperties(); }
public IComponent DummyComponent() { return new TempMeter(); }
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new TempMeter(cfg, components); }
public IComponentCfg DefaultConfig() { return new TempMeterCfg(this); }
public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component)
{
return ComponentCfgBase.CreateFromDbEntity(TempMeterCfg.Serializer, component, this);
}
}
}
@@ -0,0 +1,62 @@
///
/// Copyright (c) 2021 Sensus Metering Systems
///
using System;
using log4net;
using TBF.Boxes;
namespace TBF.BenchControl.Modbus.TempMeter.Groch
{
public class ReadTempOp : IOperation
{
private static readonly ILog log = LogManager.GetLogger(typeof(ReadTempOp));
public override string ToString() { return string.Format("ReadTempOp({0},.,{1})", tempMeter.Name, eventDone); }
/// Set by the constructor
readonly TempMeter tempMeter;
readonly DoubleBox temp; /// Box for the measured value
readonly Event eventDone;
/// <summary>
/// Events: TempDone or Error
/// </summary>
/// <param name="tempMeter">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(TempMeter tempMeter, ref DoubleBox temp, Event eventDone)
{
if (tempMeter == null) throw new ArgumentNullException("tempMeter");
this.tempMeter = tempMeter;
this.temp = temp;
this.eventDone = eventDone;
log.Debug(this.ToString());
}
public ReadTempOp(TempMeter tempMeter, ref DoubleBox temp)
: this(tempMeter, ref temp, Event.TempDone)
{
}
/// <summary>Start this operation</summary>
public void Start()
{
if (temp != null) temp.Val = tempMeter.ReadTemperature();
}
/// <summary>Run this operation</summary>
/// <returns>
/// Event.TempInDone, Event.TempOutDone or Event.TempDivDone
/// </returns>
public Event Run()
{
if (temp != null) temp.Val = tempMeter.ReadTemperature();
return eventDone;
}
/// <summary>Stop this operation</summary>
public void Stop()
{
}
}
}
@@ -0,0 +1,122 @@
///
/// Copyright (c) 2021 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using log4net;
using TBF.BenchControl.ControlBoard.Legacy;
using TBF.BenchControl.Generic;
using TBF.Boxes;
using TBF.Resources;
namespace TBF.BenchControl.Modbus.TempMeter.Groch
{
public class TempMeter : ComponentBase, GenericDevices.ITempMeter, GenericDevices.IHasCalendarEvents, SchematicDrawing.IDrawingItCmpnt
{
private static readonly ILog log = LogManager.GetLogger(typeof(TempMeter));
public override string ToString() { return string.Format("TempMeter({0})", Cfg.ToString(1)); }
readonly TempMeterCfg tempMtrCfg;
public SchematicDrawing.IDrawingItem DrawingItem { get { return tempMtrCfg as SchematicDrawing.IDrawingItem; } }
public readonly CBoard ControlBoard;
public int Idx0 { get { return tempMtrCfg.Idx0; } } /// 0..15
public double A1 { get { return tempMtrCfg.A1; } }
public double A2 { get { return tempMtrCfg.A2; } }
public double A3 { get { return tempMtrCfg.A3; } }
public double A4 { get { return tempMtrCfg.A4; } }
public double A5 { get { return tempMtrCfg.A5; } }
public TempMeter()
{
}
public TempMeter(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
: base(cfg)
{
tempMtrCfg = cfg as TempMeterCfg;
ControlBoard = (CBoard)TbfComponents.FindComponent(cfg.ParentName, components);
if (ControlBoard == null) throw new Exception("Cannot find " + Name + " parent");
/// Prepare data for SendCalibData() control board component method
ControlBoard.TempCalibData[Idx0, 0] = (float)A1;
ControlBoard.TempCalibData[Idx0, 1] = (float)A2;
ControlBoard.TempCalibData[Idx0, 2] = (float)A3;
ControlBoard.TempCalibData[Idx0, 3] = (float)A4;
ControlBoard.TempCalibData[Idx0, 4] = (float)A5;
log.Warn(this.ToString());
}
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{
DateTime calibrationDue = tempMtrCfg.CalibValidDate;
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = new List<Config.CalendarEvent.ICalendarEvent>();
if (calibrationDue > TBF.UI.Constants.MinDate)
{
/// Calibration due date calendar event
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
{
/// Weekly reminders (last 5 weeks)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
false));
}
if (DateTime.Now.Date <= calibrationDue.Date)
{
/// Daily reminders (last 5 days)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
true));
}
}
return calendarEvents;
}
public double ReadTemperature()
{
if (Cfg.DebugLevel == Config.Entities.DebugMode.Normal)
{
return Config.Formulas.CorrectedValue((double)ControlBoard.Temperature(Idx0), Corrections);
}
else if (Cfg.DebugLevel == Config.Entities.DebugMode.Simulate)
{
return tempMtrCfg.DefaultTemperature;
}
else
{
return 0;
}
}
/// <summary>
/// Events: TempDone, Error
/// </summary>
/// <param name="temp">Reference to a variable for the temperature in Celsius</param>
/// <returns>ReadTempOp instance reference casted to IOperaton</returns>
public IOperation ReadTempOp(ref DoubleBox temp)
{
return new ReadTempOp(this, ref temp);
}
/// <summary>
/// Events: tempDone, Error
/// </summary>
/// <param name="temp">Reference to a variable for the temperature in Celsius</param>
/// <param name="tempDone">Event returned when measurement done</param>
/// <returns>ReadTempOp instance reference casted to IOperaton</returns>
public IOperation ReadTempOp(ref DoubleBox temp, Event tempDone)
{
return new ReadTempOp(this, ref temp, tempDone);
}
}
}
@@ -0,0 +1,94 @@
///
/// Copyright (c) 2021 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
using SchematicDrawing;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Modbus.TempMeter.Groch
{
public class TempMeterCfg : ComponentCfgBase, IChildComponentCfg, TBF.BenchControl.GenericDevices.ICalibInfoCfg, IDrawingItemWithMeasuredVal
{
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(TempMeterCfg) })[0];
public override XmlSerializer GetSerializer() { return Serializer; }
public IComponentCfgCtrl GetControl() { return new TempMeterCfgCtrl(); }
///
/// Serialized parameters
///
public int Idx0; /// 0 .. 15
public double A1;
public double A2;
public double A3;
public double A4;
public double A5;
public double DefaultTemperature;
/// Calibration info serialized parameters displayed in Metrology tab page
public string CalibCertificateNr { get; set; }
public DateTime CalibDate { get; set; }
public DateTime CalibValidDate { get; set; }
/// Schematic drawing info
public SchematicDrawing.Shape Shape { get; set; }
public int X { get; set; }
public int Y { get; set; }
public Sz Sz { get; set; }
public Orient Orient { get; set; }
public bool Flip { get; set; }
public int LblX { get; set; }
public int LblY { get; set; }
public Orient LblOrient { get; set; }
public int MsrdX { get; set; }
public int MsrdY { get; set; }
public Orient MsrdOrient { get; set; }
public Config.Unit MsrdUnits { get; set; }
public string MsrdFormat { get; set; }
public double MsrdValLimLo { get; set; }
public double MsrdValLimHi { get; set; }
[XmlIgnore]
public IList<GNode> GNodes { get; set; }
/// Private parameterless constructor invoked by all other (public) constructors
TempMeterCfg()
{
GNodes = new List<GNode>();
}
public TempMeterCfg(IComponentFactory factory)
: this()
{
Shape = Shape.TempM;
Sz = Sz.M;
MsrdUnits = Config.Unit.C;
MsrdFormat = "{0:F1} °C";
Factory = factory;
Name = "T";
ParentName = "CB";
Idx0 = 0;
A1 = 0;
A2 = 0;
A3 = 0;
A4 = 0;
A5 = 0;
DefaultTemperature = 20.0;
}
public string ToString(int i)
{
return string.Format("Name={0}, Parent={1}, Idx0={2}, A1={3}, A2={4}, A3={5}, A4={6}, A5={7}, Default={8}",
Name,
(string.IsNullOrEmpty(ParentName) ? "-" : ParentName),
Idx0,
A1, A2, A3, A4, A5, DefaultTemperature);
}
}
}
@@ -0,0 +1,285 @@
///
/// Copyright (c) 2021 Sensus Metering Systems
///
namespace TBF.BenchControl.Modbus.TempMeter.Groch
{
partial class TempMeterCfgCtrl
{
/// <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.positionTextBox = new System.Windows.Forms.TextBox();
this.positionLabel = new System.Windows.Forms.Label();
this.parentNameLabel = new System.Windows.Forms.Label();
this.nameTextBox = new System.Windows.Forms.TextBox();
this.nameLabel = new System.Windows.Forms.Label();
this.classNameLabel = new System.Windows.Forms.Label();
this.a1TextBox = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.a2TextBox = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.a3TextBox = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.a5TextBox = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.a4TextBox = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.parentNameComboBox = new System.Windows.Forms.ComboBox();
this.defaultTempTextBox = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.importButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// positionTextBox
//
this.positionTextBox.Enabled = false;
this.positionTextBox.Location = new System.Drawing.Point(130, 83);
this.positionTextBox.Name = "positionTextBox";
this.positionTextBox.Size = new System.Drawing.Size(46, 20);
this.positionTextBox.TabIndex = 6;
//
// positionLabel
//
this.positionLabel.AutoSize = true;
this.positionLabel.Location = new System.Drawing.Point(20, 86);
this.positionLabel.Name = "positionLabel";
this.positionLabel.Size = new System.Drawing.Size(44, 13);
this.positionLabel.TabIndex = 5;
this.positionLabel.Text = "Position";
//
// parentNameLabel
//
this.parentNameLabel.AutoSize = true;
this.parentNameLabel.Location = new System.Drawing.Point(20, 61);
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(130, 34);
this.nameTextBox.Name = "nameTextBox";
this.nameTextBox.Size = new System.Drawing.Size(160, 20);
this.nameTextBox.TabIndex = 2;
//
// nameLabel
//
this.nameLabel.AutoSize = true;
this.nameLabel.Location = new System.Drawing.Point(20, 37);
this.nameLabel.Name = "nameLabel";
this.nameLabel.Size = new System.Drawing.Size(35, 13);
this.nameLabel.TabIndex = 1;
this.nameLabel.Text = "Name";
//
// classNameLabel
//
this.classNameLabel.AutoSize = true;
this.classNameLabel.Location = new System.Drawing.Point(127, 10);
this.classNameLabel.Name = "classNameLabel";
this.classNameLabel.Size = new System.Drawing.Size(83, 13);
this.classNameLabel.TabIndex = 0;
this.classNameLabel.Text = "ComonentName";
//
// a1TextBox
//
this.a1TextBox.Enabled = false;
this.a1TextBox.Location = new System.Drawing.Point(130, 107);
this.a1TextBox.Name = "a1TextBox";
this.a1TextBox.Size = new System.Drawing.Size(160, 20);
this.a1TextBox.TabIndex = 9;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(20, 110);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(20, 13);
this.label1.TabIndex = 8;
this.label1.Text = "A1";
//
// a2TextBox
//
this.a2TextBox.Enabled = false;
this.a2TextBox.Location = new System.Drawing.Point(130, 128);
this.a2TextBox.Name = "a2TextBox";
this.a2TextBox.Size = new System.Drawing.Size(160, 20);
this.a2TextBox.TabIndex = 11;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(20, 131);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(20, 13);
this.label2.TabIndex = 10;
this.label2.Text = "A2";
//
// a3TextBox
//
this.a3TextBox.Enabled = false;
this.a3TextBox.Location = new System.Drawing.Point(130, 149);
this.a3TextBox.Name = "a3TextBox";
this.a3TextBox.Size = new System.Drawing.Size(160, 20);
this.a3TextBox.TabIndex = 13;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(20, 152);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(20, 13);
this.label3.TabIndex = 12;
this.label3.Text = "A3";
//
// a5TextBox
//
this.a5TextBox.Enabled = false;
this.a5TextBox.Location = new System.Drawing.Point(130, 191);
this.a5TextBox.Name = "a5TextBox";
this.a5TextBox.Size = new System.Drawing.Size(160, 20);
this.a5TextBox.TabIndex = 17;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(20, 194);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(20, 13);
this.label5.TabIndex = 16;
this.label5.Text = "A5";
//
// a4TextBox
//
this.a4TextBox.Enabled = false;
this.a4TextBox.Location = new System.Drawing.Point(130, 170);
this.a4TextBox.Name = "a4TextBox";
this.a4TextBox.Size = new System.Drawing.Size(160, 20);
this.a4TextBox.TabIndex = 15;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(20, 173);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(20, 13);
this.label4.TabIndex = 14;
this.label4.Text = "A4";
//
// parentNameComboBox
//
this.parentNameComboBox.Enabled = false;
this.parentNameComboBox.FormattingEnabled = true;
this.parentNameComboBox.Location = new System.Drawing.Point(130, 58);
this.parentNameComboBox.Name = "parentNameComboBox";
this.parentNameComboBox.Size = new System.Drawing.Size(160, 21);
this.parentNameComboBox.TabIndex = 4;
//
// defaultTempTextBox
//
this.defaultTempTextBox.Enabled = false;
this.defaultTempTextBox.Location = new System.Drawing.Point(130, 217);
this.defaultTempTextBox.Name = "defaultTempTextBox";
this.defaultTempTextBox.Size = new System.Drawing.Size(46, 20);
this.defaultTempTextBox.TabIndex = 19;
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(20, 220);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(100, 13);
this.label6.TabIndex = 18;
this.label6.Text = "Default temperature";
//
// importButton
//
this.importButton.Enabled = false;
this.importButton.Location = new System.Drawing.Point(182, 81);
this.importButton.Name = "importButton";
this.importButton.Size = new System.Drawing.Size(108, 23);
this.importButton.TabIndex = 7;
this.importButton.Text = "Import A1 ... A5";
this.importButton.UseVisualStyleBackColor = true;
this.importButton.Click += new System.EventHandler(this.importButton_Click);
//
// TempMeterCfgCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.importButton);
this.Controls.Add(this.label6);
this.Controls.Add(this.defaultTempTextBox);
this.Controls.Add(this.parentNameComboBox);
this.Controls.Add(this.a5TextBox);
this.Controls.Add(this.label5);
this.Controls.Add(this.a4TextBox);
this.Controls.Add(this.label4);
this.Controls.Add(this.a3TextBox);
this.Controls.Add(this.label3);
this.Controls.Add(this.a2TextBox);
this.Controls.Add(this.label2);
this.Controls.Add(this.a1TextBox);
this.Controls.Add(this.label1);
this.Controls.Add(this.positionTextBox);
this.Controls.Add(this.positionLabel);
this.Controls.Add(this.parentNameLabel);
this.Controls.Add(this.nameTextBox);
this.Controls.Add(this.nameLabel);
this.Controls.Add(this.classNameLabel);
this.Name = "TempMeterCfgCtrl";
this.Size = new System.Drawing.Size(350, 240);
this.Load += new System.EventHandler(this.TempMeterCfgCtrl_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox positionTextBox;
private System.Windows.Forms.Label positionLabel;
private System.Windows.Forms.Label parentNameLabel;
private System.Windows.Forms.TextBox nameTextBox;
private System.Windows.Forms.Label nameLabel;
private System.Windows.Forms.Label classNameLabel;
private System.Windows.Forms.TextBox a1TextBox;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox a2TextBox;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox a3TextBox;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox a5TextBox;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox a4TextBox;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.ComboBox parentNameComboBox;
private System.Windows.Forms.TextBox defaultTempTextBox;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Button importButton;
}
}
@@ -0,0 +1,214 @@
///
/// Copyright (c) 2021 Sensus Slovensko a.s.
///
using System;
using System.IO;
using System.Windows.Forms;
using Config.Entities;
using TBF.BenchControl.Generic;
using TBF.UI.Bench.Components;
namespace TBF.BenchControl.Modbus.TempMeter.Groch
{
public partial class TempMeterCfgCtrl : UserControl, IComponentCfgCtrl
{
static string lastImportFileName;
ComponentParametersDlg parent;
public bool ShowMore { get { return false; } }
TempMeterCfg config;
public IComponentCfg Config
{
get { return config as IComponentCfg; }
set
{
config = value as TempMeterCfg;
Redraw();
}
}
public TempMeterCfgCtrl()
{
InitializeComponent();
}
private void TempMeterCfgCtrl_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 ControlBoard.Legacy.ControlBoardFactory)
{
parentNameComboBox.Items.Add(cmpnt.Name);
}
}
}
Redraw();
}
public void Closing()
{
}
void Redraw()
{
if (config == null) return; /// Control was not loaded, settings were not changed
classNameLabel.Text = config.Factory.ClassName;
nameTextBox.Text = config.Name;
parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName;
positionTextBox.Text = config.Idx0.ToString();
a1TextBox.Text = config.A1.ToString();
a2TextBox.Text = config.A2.ToString();
a3TextBox.Text = config.A3.ToString();
a4TextBox.Text = config.A4.ToString();
a5TextBox.Text = config.A5.ToString();
defaultTempTextBox.Text = config.DefaultTemperature.ToString();
}
public void Unlock()
{
nameTextBox.Enabled = true;
parentNameComboBox.Enabled = true;
positionTextBox.Enabled = true;
importButton.Enabled = true;
a1TextBox.Enabled = true;
a2TextBox.Enabled = true;
a3TextBox.Enabled = true;
a4TextBox.Enabled = true;
a5TextBox.Enabled = true;
defaultTempTextBox.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(positionTextBox.Text, out dummy) || dummy < 0 || dummy > 15)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Position' should be between 0 and 15";
}
double fdummy;
if (!Utils.TryParseEDouble(a1TextBox.Text, out fdummy))
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'A1' is not valid";
}
if (!Utils.TryParseEDouble(a2TextBox.Text, out fdummy))
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'A2' is not valid";
}
if (!Utils.TryParseEDouble(a3TextBox.Text, out fdummy))
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'A3' is not valid";
}
if (!Utils.TryParseEDouble(a4TextBox.Text, out fdummy))
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'A4' is not valid";
}
if (!Utils.TryParseEDouble(a5TextBox.Text, out fdummy))
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'A5' is not valid";
}
if (!Utils.TryParseEDouble(defaultTempTextBox.Text, out fdummy))
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Default temperature' is not valid";
}
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.Idx0 = int.Parse(positionTextBox.Text);
bool updateOk = Utils.TryParseEDouble(a1TextBox.Text, out config.A1) &&
Utils.TryParseEDouble(a2TextBox.Text, out config.A2) &&
Utils.TryParseEDouble(a3TextBox.Text, out config.A3) &&
Utils.TryParseEDouble(a4TextBox.Text, out config.A4) &&
Utils.TryParseEDouble(a5TextBox.Text, out config.A5) &&
Utils.TryParseEDouble(defaultTempTextBox.Text, out config.DefaultTemperature);
return flags;
}
private void importButton_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
if (!string.IsNullOrEmpty(lastImportFileName)) dlg.FileName = lastImportFileName;
if (dlg.ShowDialog() == DialogResult.OK)
{
using (TextReader reader = new StreamReader(dlg.FileName))
{
try
{
string startOfLine = string.Format("Calch{0} =", positionTextBox.Text);
bool channelFound = false;
string line;
do
{
line = reader.ReadLine();
if (!string.IsNullOrEmpty(line) && (line.IndexOf(startOfLine) == 0))
{
string[] factors = line.Substring(startOfLine.Length).Split(new char[] { ',' });
int count = factors.Length;
double tmp;
if (count >= 1 && Utils.TryParseEDouble(factors[0].Trim(), out tmp)) a1TextBox.Text = factors[0].Trim();
if (count >= 2 && Utils.TryParseEDouble(factors[1].Trim(), out tmp)) a2TextBox.Text = factors[1].Trim();
if (count >= 3 && Utils.TryParseEDouble(factors[2].Trim(), out tmp)) a3TextBox.Text = factors[2].Trim();
if (count >= 4 && Utils.TryParseEDouble(factors[3].Trim(), out tmp)) a4TextBox.Text = factors[3].Trim();
if (count >= 5 && Utils.TryParseEDouble(factors[4].Trim(), out tmp)) a5TextBox.Text = factors[4].Trim();
channelFound = true;
lastImportFileName = dlg.FileName;
break;
}
}
while (line != null);
if (!channelFound)
{
MessageBox.Show(string.Format("Calibration factors for channel {0} not found.", positionTextBox.Text),
"Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
catch
{
MessageBox.Show("Wrong file format, import failed.",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
}
}
}
@@ -4,7 +4,7 @@
using System.Collections.Generic;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Modbus.Meret.TempMeter
namespace TBF.BenchControl.Modbus.TempMeter.Meret
{
public class Factory : IComponentFactory
{
@@ -5,7 +5,7 @@ using System;
using log4net;
using TBF.Boxes;
namespace TBF.BenchControl.Modbus.Meret.TempMeter
namespace TBF.BenchControl.Modbus.TempMeter.Meret
{
public class ReadTempOp : IOperation
{
@@ -8,7 +8,7 @@ using SchematicDrawing;
using TBF.BenchControl.Generic;
using TBF.Boxes;
namespace TBF.BenchControl.Modbus.Meret.TempMeter
namespace TBF.BenchControl.Modbus.TempMeter.Meret
{
public class TempMeter : ComponentBase, GenericDevices.ITempMeter, IDevice, IDrawingItCmpntWithMeasuredVal
{
@@ -7,7 +7,7 @@ using SchematicDrawing;
using TBF.BenchControl.Generic;
using System.Collections.Generic;
namespace TBF.BenchControl.Modbus.Meret.TempMeter
namespace TBF.BenchControl.Modbus.TempMeter.Meret
{
public class TempMeterCfg : ComponentCfgBase, Generic.IChildComponentCfg, IDrawingItemWithMeasuredVal
{
@@ -7,7 +7,7 @@ using Config.Entities;
using TBF.BenchControl.Generic;
using TBF.UI.Bench.Components;
namespace TBF.BenchControl.Modbus.Meret.TempMeter
namespace TBF.BenchControl.Modbus.TempMeter.Meret
{
public partial class TempMeterCfgCtrl : UserControl, IComponentCfgCtrl
{
@@ -1,7 +1,7 @@
///
/// Copyright (c) 2020 Sensus Slovensko a.s.
///
namespace TBF.BenchControl.Modbus.Meret.TempMeter
namespace TBF.BenchControl.Modbus.TempMeter.Meret
{
partial class TempMeterCfgCtrl
{
@@ -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>