MettlerToledo.Multi added to the project

This commit is contained in:
Milan Hanajik 2015-05-07 16:20:22 +02:00
parent 21d0adb089
commit d45da29ef7
13 changed files with 1669 additions and 0 deletions

View File

@ -0,0 +1,65 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System.IO;
using System.Collections.Generic;
using System.IO.Ports;
using System.Xml.Serialization;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.MettlerToledo.Multi
{
public class BalanceCfg : ComponentCfgBase, Generic.IComponentCfg
{
public IComponent GetComponent(IList<IComponent> components) { return new BalanceDev(this); }
public IComponentCfgCtrl GetControl() { return new BalanceCfgCtrl(); }
///
/// Serialized parameters
///
public int IdNr; /// Identification number 1..3
public float Capacity; /// Max. water mass in 'kg' or volume in 'l'
public float Empty; /// 'Empty' water mass in 'kg' or volume in 'l'
public string Format;
public int EmptyTimeSec; /// s
public int ComPortNr;
public int BaudRate;
public Parity Parity;
public int DataBits;
public StopBits StopBits;
public Handshake Handshake;
/// Private parameterless constructor invoked by all other (public) constructors
BalanceCfg()
{
Name = "Balance";
ParentName = string.Empty;
IdNr = 1;
Capacity = 200.0f;
Empty = 20.0f;
Format = "F3";
EmptyTimeSec = 180;
ComPortNr = 3;
BaudRate = 2400;
Parity = System.IO.Ports.Parity.Even;
DataBits = 7;
StopBits = System.IO.Ports.StopBits.One;
Handshake = System.IO.Ports.Handshake.XOnXOff;
}
public BalanceCfg(IComponentFactory factory)
: this()
{
this.Factory = factory;
}
public string ToString(int i)
{
return string.Format("Name={0}, Id#={1}, {2}kg, empty={3}kg, fmt.={4}, emptyTm={5}s, Com{6}, {7}Bd, {8}-bits, parity={9}, stopBits={10}, {11}",
Name, IdNr, Capacity, Empty, Format, EmptyTimeSec, ComPortNr, BaudRate, DataBits, Parity, StopBits, Handshake);
}
}
}

View File

@ -0,0 +1,379 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
namespace TBF.BenchControl.MettlerToledo.Multi
{
partial class BalanceCfgCtrl
{
/// <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.handshakeComboBox = new System.Windows.Forms.ComboBox();
this.stopBitsComboBox = new System.Windows.Forms.ComboBox();
this.parityComboBox = new System.Windows.Forms.ComboBox();
this.nameTextBox = new System.Windows.Forms.TextBox();
this.nameLabel = new System.Windows.Forms.Label();
this.classNameLabel = new System.Windows.Forms.Label();
this.handshakeLabel = new System.Windows.Forms.Label();
this.stopBitsLabel = new System.Windows.Forms.Label();
this.dataBitsTextBox = new System.Windows.Forms.TextBox();
this.dataBitsLabel = new System.Windows.Forms.Label();
this.partityLabel = new System.Windows.Forms.Label();
this.baudRateTextBox = new System.Windows.Forms.TextBox();
this.baudRateLabel = new System.Windows.Forms.Label();
this.comPortNrTextBox = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.capacityLabel = new System.Windows.Forms.Label();
this.capacityTextBox = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.emptyTextBox = new System.Windows.Forms.TextBox();
this.emptyLabel = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.emptyTimeTextBox = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.formatTextBox = new System.Windows.Forms.TextBox();
this.formatLabel = new System.Windows.Forms.Label();
this.idNrTextBox = new System.Windows.Forms.TextBox();
this.idNrLabel = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// handshakeComboBox
//
this.handshakeComboBox.Enabled = false;
this.handshakeComboBox.FormattingEnabled = true;
this.handshakeComboBox.Location = new System.Drawing.Point(236, 216);
this.handshakeComboBox.Name = "handshakeComboBox";
this.handshakeComboBox.Size = new System.Drawing.Size(43, 21);
this.handshakeComboBox.TabIndex = 27;
//
// stopBitsComboBox
//
this.stopBitsComboBox.Enabled = false;
this.stopBitsComboBox.FormattingEnabled = true;
this.stopBitsComboBox.Location = new System.Drawing.Point(236, 193);
this.stopBitsComboBox.Name = "stopBitsComboBox";
this.stopBitsComboBox.Size = new System.Drawing.Size(43, 21);
this.stopBitsComboBox.TabIndex = 25;
//
// parityComboBox
//
this.parityComboBox.Enabled = false;
this.parityComboBox.FormattingEnabled = true;
this.parityComboBox.Location = new System.Drawing.Point(100, 216);
this.parityComboBox.Name = "parityComboBox";
this.parityComboBox.Size = new System.Drawing.Size(43, 21);
this.parityComboBox.TabIndex = 21;
//
// nameTextBox
//
this.nameTextBox.Enabled = false;
this.nameTextBox.Location = new System.Drawing.Point(136, 27);
this.nameTextBox.Name = "nameTextBox";
this.nameTextBox.Size = new System.Drawing.Size(143, 20);
this.nameTextBox.TabIndex = 2;
//
// nameLabel
//
this.nameLabel.AutoSize = true;
this.nameLabel.Location = new System.Drawing.Point(26, 30);
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(133, 7);
this.classNameLabel.Name = "classNameLabel";
this.classNameLabel.Size = new System.Drawing.Size(89, 13);
this.classNameLabel.TabIndex = 0;
this.classNameLabel.Text = "ComponentName";
//
// handshakeLabel
//
this.handshakeLabel.AutoSize = true;
this.handshakeLabel.Location = new System.Drawing.Point(162, 219);
this.handshakeLabel.Name = "handshakeLabel";
this.handshakeLabel.Size = new System.Drawing.Size(62, 13);
this.handshakeLabel.TabIndex = 26;
this.handshakeLabel.Text = "Handshake";
//
// stopBitsLabel
//
this.stopBitsLabel.AutoSize = true;
this.stopBitsLabel.Location = new System.Drawing.Point(162, 196);
this.stopBitsLabel.Name = "stopBitsLabel";
this.stopBitsLabel.Size = new System.Drawing.Size(49, 13);
this.stopBitsLabel.TabIndex = 24;
this.stopBitsLabel.Text = "Stop Bits";
//
// dataBitsTextBox
//
this.dataBitsTextBox.Enabled = false;
this.dataBitsTextBox.Location = new System.Drawing.Point(236, 170);
this.dataBitsTextBox.Name = "dataBitsTextBox";
this.dataBitsTextBox.Size = new System.Drawing.Size(43, 20);
this.dataBitsTextBox.TabIndex = 23;
//
// dataBitsLabel
//
this.dataBitsLabel.AutoSize = true;
this.dataBitsLabel.Location = new System.Drawing.Point(162, 173);
this.dataBitsLabel.Name = "dataBitsLabel";
this.dataBitsLabel.Size = new System.Drawing.Size(50, 13);
this.dataBitsLabel.TabIndex = 22;
this.dataBitsLabel.Text = "Data Bits";
//
// partityLabel
//
this.partityLabel.AutoSize = true;
this.partityLabel.Location = new System.Drawing.Point(26, 221);
this.partityLabel.Name = "partityLabel";
this.partityLabel.Size = new System.Drawing.Size(33, 13);
this.partityLabel.TabIndex = 20;
this.partityLabel.Text = "Parity";
//
// baudRateTextBox
//
this.baudRateTextBox.Enabled = false;
this.baudRateTextBox.Location = new System.Drawing.Point(100, 193);
this.baudRateTextBox.Name = "baudRateTextBox";
this.baudRateTextBox.Size = new System.Drawing.Size(43, 20);
this.baudRateTextBox.TabIndex = 19;
//
// baudRateLabel
//
this.baudRateLabel.AutoSize = true;
this.baudRateLabel.Location = new System.Drawing.Point(26, 196);
this.baudRateLabel.Name = "baudRateLabel";
this.baudRateLabel.Size = new System.Drawing.Size(58, 13);
this.baudRateLabel.TabIndex = 18;
this.baudRateLabel.Text = "Baud Rate";
//
// comPortNrTextBox
//
this.comPortNrTextBox.Enabled = false;
this.comPortNrTextBox.Location = new System.Drawing.Point(100, 170);
this.comPortNrTextBox.Name = "comPortNrTextBox";
this.comPortNrTextBox.Size = new System.Drawing.Size(43, 20);
this.comPortNrTextBox.TabIndex = 17;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(26, 173);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(68, 13);
this.label1.TabIndex = 16;
this.label1.Text = "Serial Port #:";
//
// capacityLabel
//
this.capacityLabel.AutoSize = true;
this.capacityLabel.Location = new System.Drawing.Point(26, 76);
this.capacityLabel.Name = "capacityLabel";
this.capacityLabel.Size = new System.Drawing.Size(76, 13);
this.capacityLabel.TabIndex = 5;
this.capacityLabel.Text = "Tank Capacity";
//
// capacityTextBox
//
this.capacityTextBox.Enabled = false;
this.capacityTextBox.Location = new System.Drawing.Point(137, 73);
this.capacityTextBox.Name = "capacityTextBox";
this.capacityTextBox.Size = new System.Drawing.Size(43, 20);
this.capacityTextBox.TabIndex = 6;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(186, 76);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(19, 13);
this.label2.TabIndex = 7;
this.label2.Text = "kg";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(186, 99);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(19, 13);
this.label3.TabIndex = 10;
this.label3.Text = "kg";
//
// emptyTextBox
//
this.emptyTextBox.Enabled = false;
this.emptyTextBox.Location = new System.Drawing.Point(137, 96);
this.emptyTextBox.Name = "emptyTextBox";
this.emptyTextBox.Size = new System.Drawing.Size(43, 20);
this.emptyTextBox.TabIndex = 9;
//
// emptyLabel
//
this.emptyLabel.AutoSize = true;
this.emptyLabel.Location = new System.Drawing.Point(26, 99);
this.emptyLabel.Name = "emptyLabel";
this.emptyLabel.Size = new System.Drawing.Size(64, 13);
this.emptyLabel.TabIndex = 8;
this.emptyLabel.Text = "Tank Empty";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(186, 145);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(24, 13);
this.label4.TabIndex = 15;
this.label4.Text = "sec";
//
// emptyTimeTextBox
//
this.emptyTimeTextBox.Enabled = false;
this.emptyTimeTextBox.Location = new System.Drawing.Point(137, 142);
this.emptyTimeTextBox.Name = "emptyTimeTextBox";
this.emptyTimeTextBox.Size = new System.Drawing.Size(43, 20);
this.emptyTimeTextBox.TabIndex = 14;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(26, 145);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(90, 13);
this.label5.TabIndex = 13;
this.label5.Text = "Tank Empty Time";
//
// formatTextBox
//
this.formatTextBox.Enabled = false;
this.formatTextBox.Location = new System.Drawing.Point(137, 119);
this.formatTextBox.Name = "formatTextBox";
this.formatTextBox.Size = new System.Drawing.Size(43, 20);
this.formatTextBox.TabIndex = 12;
//
// formatLabel
//
this.formatLabel.AutoSize = true;
this.formatLabel.Location = new System.Drawing.Point(26, 122);
this.formatLabel.Name = "formatLabel";
this.formatLabel.Size = new System.Drawing.Size(76, 13);
this.formatLabel.TabIndex = 11;
this.formatLabel.Text = "Decimal points";
//
// idNrTextBox
//
this.idNrTextBox.Enabled = false;
this.idNrTextBox.Location = new System.Drawing.Point(137, 50);
this.idNrTextBox.Name = "idNrTextBox";
this.idNrTextBox.Size = new System.Drawing.Size(43, 20);
this.idNrTextBox.TabIndex = 4;
this.idNrTextBox.TextChanged += new System.EventHandler(this.idNrTextBox_TextChanged);
//
// idNrLabel
//
this.idNrLabel.AutoSize = true;
this.idNrLabel.Location = new System.Drawing.Point(26, 53);
this.idNrLabel.Name = "idNrLabel";
this.idNrLabel.Size = new System.Drawing.Size(85, 13);
this.idNrLabel.TabIndex = 3;
this.idNrLabel.Text = "ID Number (1..3)";
//
// BalanceCfgCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.idNrTextBox);
this.Controls.Add(this.idNrLabel);
this.Controls.Add(this.formatTextBox);
this.Controls.Add(this.formatLabel);
this.Controls.Add(this.label4);
this.Controls.Add(this.emptyTimeTextBox);
this.Controls.Add(this.label5);
this.Controls.Add(this.label3);
this.Controls.Add(this.emptyTextBox);
this.Controls.Add(this.emptyLabel);
this.Controls.Add(this.label2);
this.Controls.Add(this.capacityTextBox);
this.Controls.Add(this.capacityLabel);
this.Controls.Add(this.handshakeComboBox);
this.Controls.Add(this.stopBitsComboBox);
this.Controls.Add(this.parityComboBox);
this.Controls.Add(this.nameTextBox);
this.Controls.Add(this.nameLabel);
this.Controls.Add(this.classNameLabel);
this.Controls.Add(this.handshakeLabel);
this.Controls.Add(this.stopBitsLabel);
this.Controls.Add(this.dataBitsTextBox);
this.Controls.Add(this.dataBitsLabel);
this.Controls.Add(this.partityLabel);
this.Controls.Add(this.baudRateTextBox);
this.Controls.Add(this.baudRateLabel);
this.Controls.Add(this.comPortNrTextBox);
this.Controls.Add(this.label1);
this.Name = "BalanceCfgCtrl";
this.Size = new System.Drawing.Size(300, 250);
this.Load += new System.EventHandler(this.BalanceCfgCtrl_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ComboBox handshakeComboBox;
private System.Windows.Forms.ComboBox stopBitsComboBox;
private System.Windows.Forms.ComboBox parityComboBox;
private System.Windows.Forms.TextBox nameTextBox;
private System.Windows.Forms.Label nameLabel;
private System.Windows.Forms.Label classNameLabel;
private System.Windows.Forms.Label handshakeLabel;
private System.Windows.Forms.Label stopBitsLabel;
private System.Windows.Forms.TextBox dataBitsTextBox;
private System.Windows.Forms.Label dataBitsLabel;
private System.Windows.Forms.Label partityLabel;
private System.Windows.Forms.TextBox baudRateTextBox;
private System.Windows.Forms.Label baudRateLabel;
private System.Windows.Forms.TextBox comPortNrTextBox;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label capacityLabel;
private System.Windows.Forms.TextBox capacityTextBox;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox emptyTextBox;
private System.Windows.Forms.Label emptyLabel;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox emptyTimeTextBox;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox formatTextBox;
private System.Windows.Forms.Label formatLabel;
private System.Windows.Forms.TextBox idNrTextBox;
private System.Windows.Forms.Label idNrLabel;
}
}

View File

@ -0,0 +1,242 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using System.Globalization;
using System.Windows.Forms;
using System.IO.Ports;
using log4net;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.MettlerToledo.Multi
{
public partial class BalanceCfgCtrl : UserControl, IComponentCfgCtrl
{
static readonly ILog log = LogManager.GetLogger(typeof(BalanceCfgCtrl));
public bool ShowMore { get { return false; } }
BalanceCfg config;
public IComponentCfg Config
{
get { return config as IComponentCfg; }
set
{
config = value as BalanceCfg;
Redraw();
}
}
public BalanceCfgCtrl()
{
InitializeComponent();
parityComboBox.Items.Add(Parity.None.ToString());
parityComboBox.Items.Add(Parity.Even.ToString());
parityComboBox.Items.Add(Parity.Odd.ToString());
stopBitsComboBox.Items.Add(StopBits.None.ToString());
stopBitsComboBox.Items.Add(StopBits.One.ToString());
stopBitsComboBox.Items.Add(StopBits.OnePointFive.ToString());
stopBitsComboBox.Items.Add(StopBits.Two.ToString());
handshakeComboBox.Items.Add(Handshake.None.ToString());
handshakeComboBox.Items.Add(Handshake.RequestToSend.ToString());
handshakeComboBox.Items.Add(Handshake.XOnXOff.ToString());
}
int GetParityIx(Parity par)
{
if (par == Parity.None) return 0;
if (par == Parity.Even) return 0;
if (par == Parity.Odd) return 0;
return -1;
}
Parity GetParity(string str)
{
if (str.Equals(Parity.None.ToString())) return Parity.None;
if (str.Equals(Parity.Even.ToString())) return Parity.Even;
if (str.Equals(Parity.Odd.ToString())) return Parity.Odd;
return (Parity)(-1);
}
int GetStopBitsIx(StopBits sb)
{
if (sb == StopBits.None) return 0;
if (sb == StopBits.One) return 1;
if (sb == StopBits.OnePointFive) return 2;
if (sb == StopBits.Two) return 3;
return -1;
}
StopBits GetStopBits(string str)
{
if (str.Equals(StopBits.None.ToString())) return StopBits.None;
if (str.Equals(StopBits.One.ToString())) return StopBits.One;
if (str.Equals(StopBits.OnePointFive.ToString())) return StopBits.OnePointFive;
if (str.Equals(StopBits.Two.ToString())) return StopBits.Two;
return (StopBits)(-1);
}
int GetHandshakeIx(Handshake par)
{
if (par == Handshake.None) return 0;
if (par == Handshake.RequestToSend) return 0;
if (par == Handshake.XOnXOff) return 0;
return -1;
}
Handshake GetHandshake(string str)
{
if (str.Equals(Handshake.None.ToString())) return Handshake.None;
if (str.Equals(Handshake.RequestToSend.ToString())) return Handshake.RequestToSend;
if (str.Equals(Handshake.XOnXOff.ToString())) return Handshake.XOnXOff;
return (Handshake)(-1);
}
private void BalanceCfgCtrl_Load(object sender, EventArgs e)
{
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;
idNrTextBox.Text = config.IdNr.ToString();
capacityTextBox.Text = config.Capacity.ToString();
emptyTextBox.Text = config.Empty.ToString();
formatTextBox.Text = (config.Format.Length > 1) ? config.Format.Substring(1) : config.Format;
emptyTimeTextBox.Text = config.EmptyTimeSec.ToString();
comPortNrTextBox.Text = config.ComPortNr.ToString();
baudRateTextBox.Text = config.BaudRate.ToString();
parityComboBox.Text = config.Parity.ToString();
dataBitsTextBox.Text = config.DataBits.ToString();
stopBitsComboBox.Text = config.StopBits.ToString();
handshakeComboBox.Text = config.Handshake.ToString();
}
public void Unlock()
{
nameTextBox.Enabled = true;
idNrTextBox.Enabled = true;
capacityTextBox.Enabled = true;
emptyTextBox.Enabled = true;
formatTextBox.Enabled = true;
emptyTimeTextBox.Enabled = true;
comPortNrTextBox.Enabled = true;
baudRateTextBox.Enabled = true;
parityComboBox.Enabled = true;
dataBitsTextBox.Enabled = true;
stopBitsComboBox.Enabled = true;
handshakeComboBox.Enabled = true;
}
public CfgUpdateFlags VerifyCfg(ref string message)
{
CfgUpdateFlags flags = CfgUpdateFlags.None;
int idNr;
if (!int.TryParse(idNrTextBox.Text, out idNr) || idNr < 1 || idNr > 3)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Id Number' is not valid";
}
float mass;
if (!Utils.TryParseUFloat(capacityTextBox.Text, out mass) || mass <= 0)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Tank Capacity' is not valid";
}
if (!Utils.TryParseUFloat(emptyTextBox.Text, out mass) || mass <= 0)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Tank Empty' is not valid";
}
int dummy;
if (!int.TryParse(formatTextBox.Text, out dummy) || dummy < 0 || dummy > 9)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Decimal points' should be between 0 and 9";
}
if (!int.TryParse(emptyTimeTextBox.Text, out dummy) || dummy < 1 || dummy > 999)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Tank Empty Time' should be between 1 and 999 sec";
}
if (idNr == 1)
{
if (!int.TryParse(comPortNrTextBox.Text, out dummy) || dummy < 1 || dummy > 999)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Serial Port Number' is not valid";
}
if (!int.TryParse(baudRateTextBox.Text, out dummy) || dummy < 150 || dummy > 115200)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Baud Rate' is not valid";
}
if (!int.TryParse(dataBitsTextBox.Text, out dummy) || dummy < 7 || dummy > 8)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Data Bits' 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.IdNr = int.Parse(idNrTextBox.Text);
config.Capacity = Utils.ParseUFloat(capacityTextBox.Text);
config.Empty = Utils.ParseUFloat(emptyTextBox.Text);
config.Format = "F" + formatTextBox.Text;
config.EmptyTimeSec = int.Parse(emptyTimeTextBox.Text);
if (config.IdNr == 1)
{
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
config.BaudRate = int.Parse(baudRateTextBox.Text);
config.Parity = GetParity(parityComboBox.SelectedItem.ToString());
config.DataBits = int.Parse(dataBitsTextBox.Text);
config.StopBits = GetStopBits(stopBitsComboBox.SelectedItem.ToString());
config.Handshake = GetHandshake(handshakeComboBox.SelectedItem.ToString());
}
return flags;
}
private void idNrTextBox_TextChanged(object sender, EventArgs e)
{
int idNr;
if (int.TryParse(idNrTextBox.Text, out idNr))
{
bool visible = (idNr == 1);
comPortNrTextBox.Visible = visible;
baudRateTextBox.Visible = visible;
parityComboBox.Visible = visible;
dataBitsTextBox.Visible = visible;
stopBitsComboBox.Visible = visible;
handshakeComboBox.Visible = visible;
}
}
}
}

View File

@ -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>

View File

@ -0,0 +1,436 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.IO.Ports;
using log4net;
using TBF.BenchControl.Generic;
using TBF.Boxes;
namespace TBF.BenchControl.MettlerToledo.Multi
{
/// <summary>
/// Mettler Toledo ICS4_5 Weighting terminal connected via serial interface (RS232)
/// </summary>
/// <note>
/// Implemented and tested on 15.10.2013 by Milan Hanajik
/// </note>
public class BalanceDev : ComponentBase, IDevice, GenericDevices.IBalance
{
/// <summary>
/// Info: StartMassMeasurement() and "Balnce response = .., Mass = ..."
/// Warn: Start measurement when busy is true
/// </summary>
private static readonly ILog log = LogManager.GetLogger(typeof(BalanceDev));
public override string ToString() { return string.Format("MettlerToledo.Balance({0})", Cfg.ToString(1)); }
protected readonly BalanceCfg balanceCfg;
/// <summary>
/// Enumeration of balances via static fields and methods
/// </summary>
static int nextBalanceIdx = 0;
public static new void ResetStaticProperties()
{
nextBalanceIdx = 0;
}
public static int BalancesCount { get { return nextBalanceIdx; } }
public static BalanceDev[] Balances;
public static float[] Masses;
///
protected int balanceNr; /// 0-based balance number
protected SerialPort serialPort;
protected StringBuilder stringBuilder;
public int BalanceNr { get { return balanceNr; } }
public float Capacity { get { return balanceCfg.Capacity; } }
public int EmptyTimeSec { get { return balanceCfg.EmptyTimeSec; } }
/// <summary>The state of the mass measurement</summary>
public MsrmntState MsrmntState { get { return msrmntState; } }
protected MsrmntState msrmntState;
/// <summary>The mass after StartMassMeasurement() when MsrmntState == MsrmntState.Valid</summary>
public float Mass { get { return mass; } }
protected float mass;
/// <summary>The time stamp after StartMassMeasurement() when MsrmntState == MsrmntState.Valid</summary>
public int MsrmntTimeStamp { get { return msrmntTimeStamp; } }
protected int msrmntTimeStamp;
public string Format { get { return balanceCfg.Format; } }
/// <summary>
/// Constructor
/// </summary>
/// <param name="cfg">Balance properties</param>
/// <param components="cfg">A list of components loaded so far</param>
public BalanceDev(BalanceCfg cfg)
: base(cfg)
{
balanceCfg = cfg;
balanceNr = nextBalanceIdx++;
Masses = new float[nextBalanceIdx]; /// (re)initialize the static array of masses of all balances
///
if (Balances == null || Balances.Length < nextBalanceIdx)
{
BalanceDev[] balancesSoFar = Balances;
Balances = new BalanceDev[nextBalanceIdx];
if (balancesSoFar != null) for (int i = 0; i < balancesSoFar.Length; i++) Balances[i] = balancesSoFar[i];
Balances[nextBalanceIdx - 1] = this;
}
log.Debug(this.ToString());
}
public void Initialize()
{
msrmntState = MsrmntState.Failed; /// Data not valid yet
if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate) return;
if (balanceCfg.IdNr == 1)
{
stringBuilder = new StringBuilder(40);
string comPortName = "COM" + balanceCfg.ComPortNr.ToString();
serialPort = new SerialPort(comPortName, balanceCfg.BaudRate, balanceCfg.Parity, balanceCfg.DataBits, balanceCfg.StopBits);
serialPort.Handshake = balanceCfg.Handshake;
serialPort.Open();
}
log.FatalFormat("Successfully initialized device {0}", ToString());
}
public bool IsEmpty(float mass)
{
return (mass <= balanceCfg.Empty);
}
public void ZeroWhenStable()
{
if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate) return;
if (msrmntState == MsrmntState.Busy)
{
log.Warn("ZeroWhenStable() returns without starting zeroing the scale because measurementState == MeasurementState.Busy");
return;
}
log.Info("ZeroWhenStable()");
msrmntState = MsrmntState.Busy;
stringBuilder.Clear();
serialPort.Write("Z\r\n");
}
public void Taring()
{
if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate) return;
if (msrmntState == MsrmntState.Busy)
{
log.Warn("Taring() returns without starting taring the scale because measurementState == MeasurementState.Busy");
return;
}
log.Info("Taring()");
msrmntState = MsrmntState.Busy;
stringBuilder.Clear();
serialPort.Write("T\r\n");
}
/// <summary>
/// Get a stable mass measurement
/// </summary>
public void GetStableMassMeasurement()
{
if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate) return;
if (msrmntState == MsrmntState.Busy)
{
log.Warn("GetStableMassMeasurement() returns without starting a measurement because measurementState == MeasurementState.Busy");
return;
}
log.Info("GetStableMassMeasurement()");
msrmntState = MsrmntState.Busy;
stringBuilder.Clear();
serialPort.Write("S\r\n");
}
/// <summary>
/// Get an immediate mass measurement
/// </summary>
public void GetImmediateMassMeasurement()
{
if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate) return;
if (msrmntState == MsrmntState.Busy)
{
log.Warn("GetImmediateMassMeasurement() returns without starting a measurement because measurementState == MeasurementState.Busy");
return;
}
log.Info("GetImmediateMassMeasurement()");
msrmntState = MsrmntState.Busy;
stringBuilder.Clear();
serialPort.Write("SI\r\n");
}
/// <summary>Units for SetUnits() argument</summary>
public enum Units
{
g,
kg,
t,
lb,
oz
}
/// <summary>
/// Get the serial number
/// </summary>
/// <remarks>After a successful SetUnits(kg) mass is still sent in g. MH 15.10.2013</remarks>
public void SetUnits(Units unit)
{
if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate) return;
if (msrmntState == MsrmntState.Busy)
{
log.Warn("SetUnits() returns without setting the units because measurementState == MeasurementState.Busy");
return;
}
log.InfoFormat("SetUnits({0})", unit);
msrmntState = MsrmntState.Busy;
stringBuilder.Clear();
switch (unit)
{
case Units.g: serialPort.Write("U g\r\n"); break;
case Units.kg: serialPort.Write("U kg\r\n"); break;
case Units.t: serialPort.Write("U t\r\n"); break;
case Units.lb: serialPort.Write("U lb\r\n"); break;
case Units.oz: serialPort.Write("U oz\r\n"); break;
}
}
/// <summary>
/// Parse characters received from the serial port
/// </summary>
public virtual void RunDeviceBefore()
{
if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate)
{
mass = TestBenchSim.GetSimMass(balanceNr);
Masses[balanceNr] = mass;
msrmntState = MsrmntState.Valid;
msrmntTimeStamp = StateMachine.Time;
return;
}
if (balanceCfg.IdNr != 1) return;
log.Debug("RunDevice()");
if (msrmntState != MsrmntState.Busy) return; /// No measurement in progress
string justReceived = serialPort.ReadExisting();
if (justReceived != null && justReceived.Length > 0)
{
log.Debug("RunDevice() received " + justReceived);
stringBuilder.Append(justReceived);
}
string currentBuffer = stringBuilder.ToString();
int eolPos = currentBuffer.IndexOf("\r\n");
if (eolPos >= 0)
{
msrmntTimeStamp = StateMachine.Time;
/// Get part of theh string before EOL
string received = currentBuffer.Substring(0, eolPos);
/// Put the rest back to the string builder
stringBuilder.Clear();
if (currentBuffer.Length > eolPos + 2)
{
stringBuilder.Append(currentBuffer.Substring(eolPos + 2));
}
while (true)
{
string tmp = received.Replace(" ", " ");
if (tmp.Length == received.Length) break;
received = tmp;
}
string[] fields = received.Split(new char[] { ' ' });
if (fields.Length == 1 && fields[0].Equals("ZA")) /// Zero when stable
{
mass = 0;
Masses[balanceNr] = mass;
//msrmntState = MsrmntState.Valid;
log.InfoFormat("Balance response = \"{0}<cr><lf>\"", received);
return;
}
else if (fields.Length < 2)
{
msrmntState = MsrmntState.Failed;
log.WarnFormat("Balance response = \"{0}<cr><lf>\", Unexpected error !!!", received);
return;
}
if (fields[0].Equals("Z")) /// Zero when stable
{
if (fields.Length == 2 && fields[1].Equals("A"))
{
mass = 0;
Masses[balanceNr] = mass;
//msrmntState = MsrmntState.Valid;
log.InfoFormat("Balance response = \"{0}<cr><lf>\"", received);
return;
}
else
{
msrmntState = MsrmntState.Failed;
log.WarnFormat("Balance response = \"{0}<cr><lf>\", error !!!", received);
}
}
else if (fields[0].Equals("S")) /// Stable mass: field[1] = <mass> field[2] = "kg"
{
if (fields.Length >= 3 &&
float.TryParse(fields[1],
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
CultureInfo.InvariantCulture,
out mass))
{
if (fields[2].Equals("g")) mass /= 1000.0f;
if (fields[2].Equals("t")) mass *= 1000.0f;
Masses[balanceNr] = mass;
msrmntState = MsrmntState.Valid;
log.InfoFormat("Balance response = \"{0}<cr><lf>\", Mass = {1}", received, mass);
}
else if (fields.Length == 2 && fields[1].Equals("-"))
{
mass = 0;
Masses[balanceNr] = mass;
msrmntState = MsrmntState.Valid;
log.InfoFormat("Balance response = \"{0}<cr><lf>\", Mass = {1}", received, mass);
}
else
{
msrmntState = MsrmntState.Failed;
log.WarnFormat("Balance response = \"{0}<cr><lf>\", Overload or and unexpected error !!!", received);
bool b = float.TryParse(fields[1], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out mass);
}
}
else if (fields[0].Equals("SD")) /// Dynamic mass: field[1] = <mass> field[2] = "kg"
{
if (fields.Length >= 3 &&
float.TryParse(fields[1],
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
CultureInfo.InvariantCulture,
out mass))
{
if (fields[2].Equals("g")) mass /= 1000.0f;
if (fields[2].Equals("t")) mass *= 1000.0f;
Masses[balanceNr] = mass;
msrmntState = MsrmntState.Valid;
log.InfoFormat("Balance response = \"{0}<cr><lf>\", Mass = {1}", received, mass);
}
else if (fields.Length == 2 && fields[1].Equals("-"))
{
mass = 0;
Masses[balanceNr] = mass;
msrmntState = MsrmntState.Valid;
log.InfoFormat("Balance response = \"{0}<cr><lf>\", Mass = {1}", received, mass);
}
else
{
msrmntState = MsrmntState.Failed;
log.WarnFormat("Balance response = \"{0}<cr><lf>\", Overload or and unexpected error !!!", received);
bool b = float.TryParse(fields[1], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out mass);
}
}
else if (fields[0].Equals("TB")) /// Taring
{
if (fields.Length >= 3 &&
float.TryParse(fields[1],
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
CultureInfo.InvariantCulture,
out mass))
{
if (fields[2].Equals("g")) mass /= 1000.0f;
if (fields[2].Equals("t")) mass *= 1000.0f;
msrmntState = MsrmntState.Valid;
log.InfoFormat("Balance response = \"{0}<cr><lf>\", Tara = {1}", received, mass);
}
else
{
msrmntState = MsrmntState.Failed;
log.WarnFormat("Balance response = \"{0}<cr><lf>\", Overload or and unexpected error !!!", received);
}
}
else
{
msrmntState = MsrmntState.Failed;
log.WarnFormat("Balance response = \"{0}<cr><lf>\", Unexpected error !!!", received);
}
}
}
/// <summary>Run this device</summary>
public void RunDeviceAfter()
{
}
/// <summary>Stop this device</summary>
public void StopDevice()
{
if (balanceCfg.IdNr == 1 && serialPort != null) serialPort.Close();
}
/// <summary>
/// Events: BalanceDone, Error
/// </summary>
/// <param name="result">Reference to a variable for 'tara' in kg</param>
/// <returns>TaringOp instance reference casted to IOperaton</returns>
public IOperation TaringOp(ref FloatBox tara)
{
return new TaringOp(this, ref tara);
}
/// <summary>
/// Events: BalanceDone, Error
/// </summary>
/// <param name="result">Reference to a variable for the measured mass in kg</param>
/// <returns>ReadMassOp instance reference casted to IOperaton</returns>
public IOperation ReadMassOp(ref FloatBox mass)
{
return new ReadMassOp(this, ref mass);
}
/// <summary>
/// Events: BalanceDone, Error
/// </summary>
/// <param name="result">Reference to a variable for the measured mass in kg</param>
/// <param name="readingsCount">Required mass readings count (>= 3)</param>
/// <returns>ReadMassAverageOp instance reference casted to IOperaton</returns>
public IOperation ReadStableMassOp(ref FloatBox mass, int readingsCount)
{
return new ReadStableMassOp(this, ref mass, readingsCount);
}
}
}

View File

@ -0,0 +1,38 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System.Collections.Generic;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.MettlerToledo.Multi
{
public class BalanceFactory : IComponentFactory
{
public string ClassName { get { return "MettlerToledo-Multi"; } }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 5; } }
public IComponentCfg DefaultConfig()
{
return new BalanceCfg(this);
}
public IComponentCfgCtrl CreateCfgCtrl()
{
return new BalanceCfgCtrl();
}
public IComponent ComponentFromCmpntCfg(IComponentCfg config, IList<Generic.IComponent> components)
{
return new BalanceDev((BalanceCfg)config);
}
public IComponentCfg CmpntCfgFromCmpntEntity(Entities.Component component)
{
return ComponentCfgBase.CreateFromDbEntity(typeof(BalanceCfg), component, this);
}
public void ResetStaticProperties() { BalanceDev.ResetStaticProperties(); }
}
}

View File

@ -0,0 +1,75 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using log4net;
using TBF.Boxes;
namespace TBF.BenchControl.MettlerToledo.Multi
{
public class ReadMassOp : IOperation
{
private static readonly ILog log = LogManager.GetLogger(typeof(ReadMassOp));
public override string ToString() { return string.Format("ReadMassOp(.,.)"); }
bool done;
/// Set by the constructor
BalanceDev balanceDev;
FloatBox result;
/// <summary>
/// Events: BalanceDone, Error
/// </summary>
/// <param name="balanceDev">Balance device instance</param>
/// <param name="requiredReadingsCount">Required mass readings count (>= 3)</param>
/// <param name="result">Reference to the measured mass in kg</param>
public ReadMassOp(BalanceDev balanceDev, ref FloatBox result)
{
if (balanceDev == null) throw new ArgumentNullException("balanceDev");
this.balanceDev = balanceDev;
this.result = result;
log.Debug(this.ToString());
}
/// <summary>Start this operation</summary>
public void Start()
{
done = false;
balanceDev.GetImmediateMassMeasurement();
}
/// <summary>Run this operation</summary>
/// <returns>
/// Event.None
/// Event.BalanceDone
/// Event.Error . . . . . Current.Tick == null
/// </returns>
public Event Run()
{
if (balanceDev.MsrmntState == MsrmntState.Valid)
{
result.Val = balanceDev.Mass;
done = true;
log.InfoFormat("ReadMassOp.Run() ... mass={0} ... returning Event.BalanceDone", balanceDev.Mass);
balanceDev.GetImmediateMassMeasurement(); /// Start another measurement
return Event.BalanceDone; /// Mass read OK
}
else if (done)
{
return Event.BalanceDone; /// Mass has already been read (at least once)
}
else
{
return Event.None;
}
}
/// <summary>Stop this operation</summary>
public void Stop()
{
}
}
}

View File

@ -0,0 +1,63 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using log4net;
namespace TBF.BenchControl.MettlerToledo.Multi
{
public class ReadMassesOp : IOperation
{
private static readonly ILog log = LogManager.GetLogger(typeof(ReadMassesOp));
public override string ToString() { return string.Format("ReadMassesOp()"); }
bool done;
/// <summary>
/// Events: BalanceDone, Error
/// </summary>
/// <param name="balanceDev">Balance device instance</param>
/// <param name="requiredReadingsCount">Required mass readings count (>= 3)</param>
/// <param name="result">Reference to the measured mass in kg</param>
public ReadMassesOp()
{
log.Debug(this.ToString());
}
/// <summary>Start this operation</summary>
public void Start()
{
done = false;
for (int i = 0; i < BalanceDev.BalancesCount; i++)
{
BalanceDev.Balances[i].GetImmediateMassMeasurement();
}
}
/// <summary>Run this operation</summary>
/// <returns>
/// Event.None
/// Event.BalanceDone
/// Event.Error . . . . . Current.Tick == null
/// </returns>
public Event Run()
{
if (done) return Event.BalanceDone; /// Mass has already been read
for (int i = 0; i < BalanceDev.BalancesCount; i++)
{
if (BalanceDev.Balances[i].MsrmntState == MsrmntState.Busy)
{
return Event.None;
}
}
done = true;
return Event.BalanceDone;
}
/// <summary>Stop this operation</summary>
public void Stop()
{
}
}
}

View File

@ -0,0 +1,94 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using log4net;
using TBF.Boxes;
namespace TBF.BenchControl.MettlerToledo.Multi
{
/// <summary>
/// Operation to read more mass values and average them to obtain a more accurate result.
/// </summary>
public class ReadStableMassOp : IOperation
{
private static readonly ILog log = LogManager.GetLogger(typeof(ReadStableMassOp));
public override string ToString() { return string.Format("ReadStableMassOp(.,{0},.)", totalReadingsCount); }
/// Operation specific
float[] massReadings;
int currentReadingsCount;
/// Set by the constructor
BalanceDev balanceDev;
int totalReadingsCount;
FloatBox result;
/// <summary>
/// Events: BalanceDone, Error
/// </summary>
/// <param name="balanceDev">Balance device instance</param>
/// <param name="result">Reference to the measured mass in kg</param>
/// <param name="readingsCount">Required mass readings count (>= 3)</param>
public ReadStableMassOp(BalanceDev balanceDev, ref FloatBox result, int readingsCount)
{
if (balanceDev == null) throw new ArgumentNullException("balanceDev");
this.balanceDev = balanceDev;
if (readingsCount < 3) throw new ArgumentOutOfRangeException("requiredReadingsCount");
this.totalReadingsCount = readingsCount;
this.result = result;
log.Debug(this.ToString());
}
/// <summary>Start this operation</summary>
public void Start()
{
currentReadingsCount = 0;
massReadings = new float[totalReadingsCount];
balanceDev.GetStableMassMeasurement();
}
/// <summary>Run this operation</summary>
/// <returns>
/// Event.None
/// Event.BalanceDone
/// Event.Error . . . . . Current.Tick == null
/// </returns>
public Event Run()
{
if (currentReadingsCount >= totalReadingsCount) return Event.BalanceDone; /// Mass has already been calculated
if (balanceDev.MsrmntState == MsrmntState.Busy) return Event.None;
if (balanceDev.MsrmntState == MsrmntState.Valid)
{
massReadings[currentReadingsCount++] = balanceDev.Mass;
if (currentReadingsCount == totalReadingsCount)
{
/// calculate the average
float calcMass = 0;
Array.Sort(massReadings);
for (int i = 1; i < totalReadingsCount - 1; i++) calcMass += massReadings[i];
calcMass = (calcMass / (totalReadingsCount - 2));
log.InfoFormat("ReadStableMassOp.Run() ... valid mass={0} ... returning Event.BalanceDone", calcMass);
result.Val = calcMass;
return Event.BalanceDone; /// Mass has just been calculated
}
}
balanceDev.GetStableMassMeasurement();
return Event.None;
}
/// <summary>Stop this operation</summary>
public void Stop()
{
}
}
}

View File

@ -0,0 +1,61 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
namespace TBF.BenchControl.MettlerToledo.Multi
{
public class SetUnitsOp : IOperation
{
private static readonly ILog log = LogManager.GetLogger(typeof(SetUnitsOp));
public override string ToString() { return string.Format("SetUnitsOp({0})", units); }
/// Set by the constructor
BalanceDev balanceDev;
BalanceDev.Units units;
/// <summary>
/// Events: BalanceDone, Error
/// </summary>
/// <param name="balanceDev">Balance device instance</param>
/// <param name="result">Reference to the serialNumber</param>
public SetUnitsOp(BalanceDev balanceDev, BalanceDev.Units units)
{
if (balanceDev == null) throw new ArgumentNullException("balanceDev");
this.balanceDev = balanceDev;
this.units = units;
log.Debug(this.ToString());
}
/// <summary>Start this operation</summary>
public void Start()
{
log.Debug("Start()");
balanceDev.SetUnits(units);
}
/// <summary>Run this operation</summary>
/// <returns>
/// Event.None
/// Event.BalanceDone
/// </returns>
public Event Run()
{
if (balanceDev.MsrmntState == MsrmntState.Valid) return Event.BalanceDone; /// Units set
if (balanceDev.MsrmntState == MsrmntState.Failed) return Event.Error; /// Failed
return Event.None; /// No result yet
}
/// <summary>Stop this operation</summary>
public void Stop()
{
log.Debug("Stop()");
}
}
}

View File

@ -0,0 +1,78 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using log4net;
using TBF.Boxes;
namespace TBF.BenchControl.MettlerToledo.Multi
{
public class TaringOp : IOperation
{
private static readonly ILog log = LogManager.GetLogger(typeof(TaringOp));
public override string ToString() { return string.Format("TaringOp(.,.)"); }
bool done;
/// Set by the constructor
BalanceDev balanceDev;
FloatBox tara;
/// <summary>
/// Events: BalanceDone, Error
/// </summary>
/// <param name="balanceDev">Balance device instance</param>
/// <param name="result">Reference to variable for 'tara' in kg</param>
public TaringOp(BalanceDev balanceDev, ref FloatBox tara)
{
if (balanceDev == null) throw new ArgumentNullException("balanceDev");
this.balanceDev = balanceDev;
this.tara = tara;
log.Debug(this.ToString());
}
/// <summary>Start this operation</summary>
public void Start()
{
done = false;
balanceDev.Taring();
}
/// <summary>Run this operation</summary>
/// <returns>
/// Event.None
/// Event.BalanceDone
/// Event.Error . . . . . Current.Tick == null
/// </returns>
public Event Run()
{
if (done) return Event.BalanceDone; /// Taring has been done already
if (balanceDev.MsrmntState == MsrmntState.Busy) return Event.Busy;
if (balanceDev.MsrmntState == MsrmntState.Overload)
{
tara.Val = balanceDev.Capacity;
done = true;
return Event.BalanceOverload;
}
if (balanceDev.MsrmntState == MsrmntState.Valid)
{
tara.Val = balanceDev.Mass;
done = true;
return Event.BalanceDone; /// Taring completed
}
balanceDev.Taring(); /// Failed -> repeat taring
return Event.Busy;
}
/// <summary>Stop this operation</summary>
public void Stop()
{
}
}
}

View File

@ -40,6 +40,7 @@ namespace TBF.BenchControl
Factories.Add(new TestMethods.LeakTest.TestMethodFactory());
Factories.Add(new MettlerToledo.Standard.BalanceFactory());
Factories.Add(new MettlerToledo.Standard.BalanceNewFactory());
Factories.Add(new MettlerToledo.Multi.BalanceFactory());
Factories.Add(new TestMethods.PMaxTest.TestMethodFactory());
Factories.Add(new Elde.PressureMeter.PressureMeterFactory());
Factories.Add(new Elde.Pump.PumpFactory());

View File

@ -157,6 +157,20 @@
<DependentUpon>TestStartEndForm.cs</DependentUpon>
</Compile>
<Compile Include="BenchControl\Elde\Diverter\Handlers.cs" />
<Compile Include="BenchControl\MettlerToledo\Multi\BalanceCfg.cs" />
<Compile Include="BenchControl\MettlerToledo\Multi\BalanceCfgCtrl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="BenchControl\MettlerToledo\Multi\BalanceCfgCtrl.designer.cs">
<DependentUpon>BalanceCfgCtrl.cs</DependentUpon>
</Compile>
<Compile Include="BenchControl\MettlerToledo\Multi\BalanceDev.cs" />
<Compile Include="BenchControl\MettlerToledo\Multi\BalanceFactory.cs" />
<Compile Include="BenchControl\MettlerToledo\Multi\ReadMassesOp.cs" />
<Compile Include="BenchControl\MettlerToledo\Multi\ReadMassOp.cs" />
<Compile Include="BenchControl\MettlerToledo\Multi\ReadStableMassOp.cs" />
<Compile Include="BenchControl\MettlerToledo\Multi\SetUnitsOp.cs" />
<Compile Include="BenchControl\MettlerToledo\Multi\TaringOp.cs" />
<Compile Include="BenchControl\MettlerToledo\Standard\BalanceCfg.cs" />
<Compile Include="BenchControl\MettlerToledo\Standard\BalanceCfgCtrl.cs">
<SubType>UserControl</SubType>
@ -1215,6 +1229,9 @@
<EmbeddedResource Include="BenchControl\Elde\Valve\ValveCfgCtrl.resx">
<DependentUpon>ValveCfgCtrl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="BenchControl\MettlerToledo\Multi\BalanceCfgCtrl.resx">
<DependentUpon>BalanceCfgCtrl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="BenchControl\MettlerToledo\Standard\BalanceCfgCtrl.resx">
<DependentUpon>BalanceCfgCtrl.cs</DependentUpon>
</EmbeddedResource>