PressureMeter : Protocol selection in component properties (Meret, Modbus), ver. 2.18.1102

This commit is contained in:
Milan Hanajik
2018-12-18 10:28:34 +01:00
parent 7d968ba9b4
commit 97c041801f
11 changed files with 196 additions and 125 deletions
+3 -1
View File
@@ -124,6 +124,7 @@ namespace TBF.BenchControl.Elde
///
public float[,] TempCalibData = new float[8, 5];
public uint[] DiverterEdge; /// Created and initialized in this.Initialize()
public byte MeretProtocol = 0;
// Array length is the reference flowmeters count plus one
#if DN100 || FUZHOU_150 || FUZHOU_300 || IZRAEL_200 || PUCHONG_200 || SLM_150 || SENTEC || CEVAK_200
@@ -344,7 +345,8 @@ namespace TBF.BenchControl.Elde
TempCalibData,
EtCalib,
DiverterEdge,
BalanceRange);
BalanceRange,
MeretProtocol);
log.FatalFormat("Successfully initialized device {0}", ToString());
}
+3 -1
View File
@@ -99,6 +99,7 @@ namespace TBF.BenchControl.Elde
float[] etCalib;
uint[] diverterEdge;
uint[] balanceRange;
byte meretProtocol;
uint[] cyclePar;
@@ -147,7 +148,7 @@ namespace TBF.BenchControl.Elde
/// <param name="tempCalib">Temp.calc.coefs, ix1 = temp.sens.nr. (0..7 ???), ix2 = coef.nr</param>
/// <param name="etCalib">Etalon nominal values</param>
/// <param name="divEdge">Percentages for switching of diverters, ix = diverter nr.(0,1), typ.value 50 (%)</param>
public void SendCalibData(uint[,] rvCalib, byte[] meretA, int usedCom, float[,] tempCalib, float[] etCalib, uint[] divEdge, uint[] balanceRange)
public void SendCalibData(uint[,] rvCalib, byte[] meretA, int usedCom, float[,] tempCalib, float[] etCalib, uint[] divEdge, uint[] balanceRange, byte meretProtocol)
{
log.Info("SendCalibData(...)");
@@ -157,6 +158,7 @@ namespace TBF.BenchControl.Elde
this.etCalib = etCalib;
this.diverterEdge = divEdge;
this.balanceRange = balanceRange;
this.meretProtocol = meretProtocol;
}
/// <summary>
+5 -5
View File
@@ -195,7 +195,7 @@ namespace TBF.BenchControl.Elde
/// <param name="divEdge">Percentages for switching of diverters, ix = diverter nr.(0,1), typ.value 50 (%)</param>
/// <param name="balanceRange">Balance range = volume of the tanks on the balaces (ix=0,1)</param>
public void SendCalibData(uint[,] rvCalib, byte[] meretA, int usedCom, float[,] tempCalib,
float[] etCalib, uint[] divEdge, uint[] balanceRange)
float[] etCalib, uint[] divEdge, uint[] balanceRange, byte meretProtocol)
{
if (Program.MainWnd.InvokeRequired)
{
@@ -206,15 +206,15 @@ namespace TBF.BenchControl.Elde
else
{
/// When SendCalibData(...) called from the UI thread
DoSendCalibData(rvCalib, meretA, usedCom, tempCalib, etCalib, divEdge, balanceRange);
DoSendCalibData(rvCalib, meretA, usedCom, tempCalib, etCalib, divEdge, balanceRange, meretProtocol);
}
}
///
delegate void SendCalibDataDlgt(uint[,] rvCalib, byte[] meretA, int usedCom, float[,] tempCalib,
float[] etCalib, uint[] divEdge, uint[] balanceRange);
float[] etCalib, uint[] divEdge, uint[] balanceRange, byte meretProtocol);
///
private void DoSendCalibData(uint[,] rvCalib, byte[] meretA, int usedCom, float[,] tempCalib,
float[] etCalib, uint[] divEdge, uint[] balanceRange)
float[] etCalib, uint[] divEdge, uint[] balanceRange, byte meretProtocol)
{
//TBF.UiBridge.Bridge.OnLog(this, string.Format("{0} SendCalibData(COM{1}) rvCalib[0,0]={2} rvCalib[0,1]={3} rvCalib[1,0]={4} rvCalib[1,1]={5}\r\n",
// DateTime.Now.ToLongTimeString(), usedCom,
@@ -246,7 +246,7 @@ namespace TBF.BenchControl.Elde
ctrlBrdComponent.ExternalCom = true;
#if SENTEC || CEVAK_200 || FUZHOU_100 || IZRAEL_25
ctrlBrdComponent.SendCalibData(rvCalib, meretA, (byte)usedCom, tempCalib, etCalib, divEdge, balanceRange, (byte)0Xff);
ctrlBrdComponent.SendCalibData(rvCalib, meretA, (byte)usedCom, tempCalib, etCalib, divEdge, balanceRange, meretProtocol);
#else
ctrlBrdComponent.SendCalibData(rvCalib, meretA, (byte)usedCom, tempCalib, etCalib, divEdge, balanceRange);
#endif
+3 -1
View File
@@ -51,7 +51,9 @@ namespace TBF.BenchControl.Elde
/// <param name="tempCalib">Temp.calc.coefs, ix1 = temp.sens.nr. (0..7 ???), ix2 = coef.nr</param>
/// <param name="etCalib">Etalon nominal values</param>
/// <param name="divEdge">Percentages for switching of diverters, ix = diverter nr.(0,1), typ.value 50 (%)</param>
void SendCalibData(uint[,] rvCalib, byte[] meretA, int usedCom, float[,] tempCalib, float[] etCalib, uint[] divEdge, uint[] balanceRange);
/// <param name="balanceRange">TODO</param>
/// <param name="meretProtocol">TODO</param>
void SendCalibData(uint[,] rvCalib, byte[] meretA, int usedCom, float[,] tempCalib, float[] etCalib, uint[] divEdge, uint[] balanceRange, byte meretProtocol);
/// <summary>
/// Updates a command that is regularly sent to the control board by SendCommand.
@@ -34,11 +34,20 @@ namespace TBF.BenchControl.Elde.PressureMeter
if (ControlBoard == null) throw new Exception("Cannot find " + Name + " parent");
Idx0 = pressureMeterCfg.Idx0;
RS485Address = pressureMeterCfg.RS485Address;
RS485Address = pressureMeterCfg.RS485Address;
/// Prepare data for SendCalibData() control board component method
ControlBoard.MeretRS485Address[Idx0] = RS485Address;
if (pressureMeterCfg.Protocol == Config.Entities.MeretProtocol.Undefined)
{
throw new Exception("Metret protocol not defined");
}
else if (pressureMeterCfg.Protocol == Config.Entities.MeretProtocol.Modbus)
{
ControlBoard.MeretProtocol |= (byte)(1 << Idx0);
}
log.Debug(this.ToString());
}
@@ -1,10 +1,11 @@
///
/// Copyright (c) 2013-2016 Sensus Metering Systems
/// Copyright (c) 2013-2018 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
using Config.Entities;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Elde.PressureMeter
@@ -19,8 +20,9 @@ namespace TBF.BenchControl.Elde.PressureMeter
///
/// Serialized parameters
///
public int Idx0; /// 0..3
public byte RS485Address; /// 0..255
public int Idx0; /// 0..3
public MeretProtocol Protocol; /// Meret or Modbus
public byte RS485Address; /// 0..255
/// Private parameterless constructor invoked by all other (public) constructors
PressureMeterCfg()
@@ -28,6 +30,7 @@ namespace TBF.BenchControl.Elde.PressureMeter
Name = "Pr";
ParentName = "CB";
Idx0 = 0;
Protocol = MeretProtocol.Modbus;
RS485Address = 99;
}
@@ -39,10 +42,11 @@ namespace TBF.BenchControl.Elde.PressureMeter
public string ToString(int i)
{
return string.Format("Name={0}, Parent={1}, Idx0={2}, Address={3}",
return string.Format("Name={0}, Parent={1}, Idx0={2}, Protocol={3}, Address={4}",
Name,
(string.IsNullOrEmpty(ParentName) ? "-" : ParentName),
Idx0,
Protocol.ToDescription(),
RS485Address);
}
}
@@ -31,113 +31,135 @@ namespace TBF.BenchControl.Elde.PressureMeter
/// </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.componentNameLabel = new System.Windows.Forms.Label();
this.rs485AddressLabel = new System.Windows.Forms.Label();
this.rs485AddressTextBox = new System.Windows.Forms.TextBox();
this.parentNameComboBox = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// positionTextBox
//
this.positionTextBox.Enabled = false;
this.positionTextBox.Location = new System.Drawing.Point(138, 104);
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(28, 107);
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(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";
//
// rs485AddressLabel
//
this.rs485AddressLabel.AutoSize = true;
this.rs485AddressLabel.Location = new System.Drawing.Point(28, 133);
this.rs485AddressLabel.Name = "rs485AddressLabel";
this.rs485AddressLabel.Size = new System.Drawing.Size(81, 13);
this.rs485AddressLabel.TabIndex = 7;
this.rs485AddressLabel.Text = "RS485 Address";
//
// rs485AddressTextBox
//
this.rs485AddressTextBox.Enabled = false;
this.rs485AddressTextBox.Location = new System.Drawing.Point(138, 130);
this.rs485AddressTextBox.Name = "rs485AddressTextBox";
this.rs485AddressTextBox.Size = new System.Drawing.Size(46, 20);
this.rs485AddressTextBox.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;
//
// PressureMeterCfgCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.parentNameComboBox);
this.Controls.Add(this.rs485AddressTextBox);
this.Controls.Add(this.rs485AddressLabel);
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.componentNameLabel);
this.Name = "PressureMeterCfgCtrl";
this.Size = new System.Drawing.Size(300, 200);
this.Load += new System.EventHandler(this.PressureMeterCfgCtrl_Load);
this.ResumeLayout(false);
this.PerformLayout();
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.componentNameLabel = new System.Windows.Forms.Label();
this.rs485AddressLabel = new System.Windows.Forms.Label();
this.rs485AddressTextBox = new System.Windows.Forms.TextBox();
this.parentNameComboBox = new System.Windows.Forms.ComboBox();
this.protocolComboBox = new System.Windows.Forms.ComboBox();
this.protocolLabel = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// positionTextBox
//
this.positionTextBox.Enabled = false;
this.positionTextBox.Location = new System.Drawing.Point(138, 104);
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(28, 107);
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(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";
//
// rs485AddressLabel
//
this.rs485AddressLabel.AutoSize = true;
this.rs485AddressLabel.Location = new System.Drawing.Point(28, 159);
this.rs485AddressLabel.Name = "rs485AddressLabel";
this.rs485AddressLabel.Size = new System.Drawing.Size(81, 13);
this.rs485AddressLabel.TabIndex = 9;
this.rs485AddressLabel.Text = "RS485 Address";
//
// rs485AddressTextBox
//
this.rs485AddressTextBox.Enabled = false;
this.rs485AddressTextBox.Location = new System.Drawing.Point(138, 156);
this.rs485AddressTextBox.Name = "rs485AddressTextBox";
this.rs485AddressTextBox.Size = new System.Drawing.Size(46, 20);
this.rs485AddressTextBox.TabIndex = 10;
//
// 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;
//
// protocolComboBox
//
this.protocolComboBox.Enabled = false;
this.protocolComboBox.FormattingEnabled = true;
this.protocolComboBox.Location = new System.Drawing.Point(138, 130);
this.protocolComboBox.Name = "protocolComboBox";
this.protocolComboBox.Size = new System.Drawing.Size(130, 21);
this.protocolComboBox.TabIndex = 8;
//
// protocolLabel
//
this.protocolLabel.AutoSize = true;
this.protocolLabel.Location = new System.Drawing.Point(28, 133);
this.protocolLabel.Name = "protocolLabel";
this.protocolLabel.Size = new System.Drawing.Size(46, 13);
this.protocolLabel.TabIndex = 7;
this.protocolLabel.Text = "Protocol";
//
// PressureMeterCfgCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.protocolComboBox);
this.Controls.Add(this.protocolLabel);
this.Controls.Add(this.parentNameComboBox);
this.Controls.Add(this.rs485AddressTextBox);
this.Controls.Add(this.rs485AddressLabel);
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.componentNameLabel);
this.Name = "PressureMeterCfgCtrl";
this.Size = new System.Drawing.Size(300, 200);
this.Load += new System.EventHandler(this.PressureMeterCfgCtrl_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
@@ -152,5 +174,7 @@ namespace TBF.BenchControl.Elde.PressureMeter
private System.Windows.Forms.Label rs485AddressLabel;
private System.Windows.Forms.TextBox rs485AddressTextBox;
private System.Windows.Forms.ComboBox parentNameComboBox;
private System.Windows.Forms.ComboBox protocolComboBox;
private System.Windows.Forms.Label protocolLabel;
}
}
@@ -46,6 +46,11 @@ namespace TBF.BenchControl.Elde.PressureMeter
}
}
for (MeretProtocol prot = MeretProtocol.Meret; prot < MeretProtocol.Count; prot++)
{
protocolComboBox.Items.Add(prot.ToDescription());
}
Redraw();
}
@@ -61,6 +66,7 @@ namespace TBF.BenchControl.Elde.PressureMeter
nameTextBox.Text = config.Name;
parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName;
positionTextBox.Text = config.Idx0.ToString();
protocolComboBox.Text = config.Protocol.ToDescription();
rs485AddressTextBox.Text = config.RS485Address.ToString();
}
@@ -69,6 +75,7 @@ namespace TBF.BenchControl.Elde.PressureMeter
nameTextBox.Enabled = true;
parentNameComboBox.Enabled = true;
positionTextBox.Enabled = true;
protocolComboBox.Enabled = true;
rs485AddressTextBox.Enabled = true;
}
@@ -87,9 +94,15 @@ namespace TBF.BenchControl.Elde.PressureMeter
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Position' should be between 0 and 15";
}
if (!protocolComboBox.Items.Contains(protocolComboBox.Text))
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "Invalid 'Protocol'";
}
if (!int.TryParse(rs485AddressTextBox.Text, out dummy) || dummy < 0 || dummy > 255)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'RS485 Address' should be between 0 and 255";
}
return flags;
@@ -104,7 +117,14 @@ namespace TBF.BenchControl.Elde.PressureMeter
config.Name = nameTextBox.Text;
config.ParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text;
config.Idx0 = int.Parse(positionTextBox.Text);
config.RS485Address = (byte)int.Parse(rs485AddressTextBox.Text);
config.Protocol = MeretProtocol.Undefined;
for (MeretProtocol prot = MeretProtocol.Meret; prot < MeretProtocol.Count; prot++)
{
if (protocolComboBox.Text == prot.ToDescription()) { config.Protocol = prot; break; }
}
config.RS485Address = (byte)int.Parse(rs485AddressTextBox.Text);
return flags;
}