MettlerToledo.Multi resolution added, Badger component updated

This commit is contained in:
Milan Hanajik 2015-05-07 21:16:59 +02:00
parent 9af74237cd
commit 5f95737d56
5 changed files with 109 additions and 65 deletions

View File

@ -20,6 +20,7 @@ namespace TBF.BenchControl.MettlerToledo.Multi
///
public int IdNr; /// Identification number 1..3
public float Capacity; /// Max. water mass in 'kg' or volume in 'l'
public float Resolution; /// Resolution of the integer value in the serial protocol in 'kg'
public float Empty; /// 'Empty' water mass in 'kg' or volume in 'l'
public string Format;
public int EmptyTimeSec; /// s
@ -39,6 +40,7 @@ namespace TBF.BenchControl.MettlerToledo.Multi
IdNr = 1;
Capacity = 200.0f;
Resolution = 0.001f;
Empty = 20.0f;
Format = "F3";
EmptyTimeSec = 180;

View File

@ -59,39 +59,42 @@ namespace TBF.BenchControl.MettlerToledo.Multi
this.formatLabel = new System.Windows.Forms.Label();
this.idNrTextBox = new System.Windows.Forms.TextBox();
this.idNrLabel = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.resolutionTextBox = new System.Windows.Forms.TextBox();
this.resolutionLabel = 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.Location = new System.Drawing.Point(236, 224);
this.handshakeComboBox.Name = "handshakeComboBox";
this.handshakeComboBox.Size = new System.Drawing.Size(43, 21);
this.handshakeComboBox.TabIndex = 27;
this.handshakeComboBox.TabIndex = 30;
//
// stopBitsComboBox
//
this.stopBitsComboBox.Enabled = false;
this.stopBitsComboBox.FormattingEnabled = true;
this.stopBitsComboBox.Location = new System.Drawing.Point(236, 193);
this.stopBitsComboBox.Location = new System.Drawing.Point(236, 203);
this.stopBitsComboBox.Name = "stopBitsComboBox";
this.stopBitsComboBox.Size = new System.Drawing.Size(43, 21);
this.stopBitsComboBox.TabIndex = 25;
this.stopBitsComboBox.TabIndex = 28;
//
// parityComboBox
//
this.parityComboBox.Enabled = false;
this.parityComboBox.FormattingEnabled = true;
this.parityComboBox.Location = new System.Drawing.Point(100, 216);
this.parityComboBox.Location = new System.Drawing.Point(100, 224);
this.parityComboBox.Name = "parityComboBox";
this.parityComboBox.Size = new System.Drawing.Size(43, 21);
this.parityComboBox.TabIndex = 21;
this.parityComboBox.TabIndex = 24;
//
// nameTextBox
//
this.nameTextBox.Enabled = false;
this.nameTextBox.Location = new System.Drawing.Point(136, 27);
this.nameTextBox.Location = new System.Drawing.Point(136, 26);
this.nameTextBox.Name = "nameTextBox";
this.nameTextBox.Size = new System.Drawing.Size(143, 20);
this.nameTextBox.TabIndex = 2;
@ -99,7 +102,7 @@ namespace TBF.BenchControl.MettlerToledo.Multi
// nameLabel
//
this.nameLabel.AutoSize = true;
this.nameLabel.Location = new System.Drawing.Point(26, 30);
this.nameLabel.Location = new System.Drawing.Point(26, 29);
this.nameLabel.Name = "nameLabel";
this.nameLabel.Size = new System.Drawing.Size(35, 13);
this.nameLabel.TabIndex = 1;
@ -117,85 +120,85 @@ namespace TBF.BenchControl.MettlerToledo.Multi
// handshakeLabel
//
this.handshakeLabel.AutoSize = true;
this.handshakeLabel.Location = new System.Drawing.Point(162, 219);
this.handshakeLabel.Location = new System.Drawing.Point(162, 227);
this.handshakeLabel.Name = "handshakeLabel";
this.handshakeLabel.Size = new System.Drawing.Size(62, 13);
this.handshakeLabel.TabIndex = 26;
this.handshakeLabel.TabIndex = 29;
this.handshakeLabel.Text = "Handshake";
//
// stopBitsLabel
//
this.stopBitsLabel.AutoSize = true;
this.stopBitsLabel.Location = new System.Drawing.Point(162, 196);
this.stopBitsLabel.Location = new System.Drawing.Point(162, 206);
this.stopBitsLabel.Name = "stopBitsLabel";
this.stopBitsLabel.Size = new System.Drawing.Size(49, 13);
this.stopBitsLabel.TabIndex = 24;
this.stopBitsLabel.TabIndex = 27;
this.stopBitsLabel.Text = "Stop Bits";
//
// dataBitsTextBox
//
this.dataBitsTextBox.Enabled = false;
this.dataBitsTextBox.Location = new System.Drawing.Point(236, 170);
this.dataBitsTextBox.Location = new System.Drawing.Point(236, 181);
this.dataBitsTextBox.Name = "dataBitsTextBox";
this.dataBitsTextBox.Size = new System.Drawing.Size(43, 20);
this.dataBitsTextBox.TabIndex = 23;
this.dataBitsTextBox.TabIndex = 26;
//
// dataBitsLabel
//
this.dataBitsLabel.AutoSize = true;
this.dataBitsLabel.Location = new System.Drawing.Point(162, 173);
this.dataBitsLabel.Location = new System.Drawing.Point(162, 184);
this.dataBitsLabel.Name = "dataBitsLabel";
this.dataBitsLabel.Size = new System.Drawing.Size(50, 13);
this.dataBitsLabel.TabIndex = 22;
this.dataBitsLabel.TabIndex = 25;
this.dataBitsLabel.Text = "Data Bits";
//
// parityLabel
//
this.parityLabel.AutoSize = true;
this.parityLabel.Location = new System.Drawing.Point(26, 221);
this.parityLabel.Location = new System.Drawing.Point(26, 229);
this.parityLabel.Name = "parityLabel";
this.parityLabel.Size = new System.Drawing.Size(33, 13);
this.parityLabel.TabIndex = 20;
this.parityLabel.TabIndex = 23;
this.parityLabel.Text = "Parity";
//
// baudRateTextBox
//
this.baudRateTextBox.Enabled = false;
this.baudRateTextBox.Location = new System.Drawing.Point(100, 193);
this.baudRateTextBox.Location = new System.Drawing.Point(100, 203);
this.baudRateTextBox.Name = "baudRateTextBox";
this.baudRateTextBox.Size = new System.Drawing.Size(43, 20);
this.baudRateTextBox.TabIndex = 19;
this.baudRateTextBox.TabIndex = 22;
//
// baudRateLabel
//
this.baudRateLabel.AutoSize = true;
this.baudRateLabel.Location = new System.Drawing.Point(26, 196);
this.baudRateLabel.Location = new System.Drawing.Point(26, 206);
this.baudRateLabel.Name = "baudRateLabel";
this.baudRateLabel.Size = new System.Drawing.Size(58, 13);
this.baudRateLabel.TabIndex = 18;
this.baudRateLabel.TabIndex = 21;
this.baudRateLabel.Text = "Baud Rate";
//
// comPortNrTextBox
//
this.comPortNrTextBox.Enabled = false;
this.comPortNrTextBox.Location = new System.Drawing.Point(100, 170);
this.comPortNrTextBox.Location = new System.Drawing.Point(100, 181);
this.comPortNrTextBox.Name = "comPortNrTextBox";
this.comPortNrTextBox.Size = new System.Drawing.Size(43, 20);
this.comPortNrTextBox.TabIndex = 17;
this.comPortNrTextBox.TabIndex = 20;
//
// comPortNrLabel
//
this.comPortNrLabel.AutoSize = true;
this.comPortNrLabel.Location = new System.Drawing.Point(26, 173);
this.comPortNrLabel.Location = new System.Drawing.Point(26, 184);
this.comPortNrLabel.Name = "comPortNrLabel";
this.comPortNrLabel.Size = new System.Drawing.Size(68, 13);
this.comPortNrLabel.TabIndex = 16;
this.comPortNrLabel.TabIndex = 19;
this.comPortNrLabel.Text = "Serial Port #:";
//
// capacityLabel
//
this.capacityLabel.AutoSize = true;
this.capacityLabel.Location = new System.Drawing.Point(26, 76);
this.capacityLabel.Location = new System.Drawing.Point(26, 71);
this.capacityLabel.Name = "capacityLabel";
this.capacityLabel.Size = new System.Drawing.Size(76, 13);
this.capacityLabel.TabIndex = 5;
@ -204,7 +207,7 @@ namespace TBF.BenchControl.MettlerToledo.Multi
// capacityTextBox
//
this.capacityTextBox.Enabled = false;
this.capacityTextBox.Location = new System.Drawing.Point(137, 73);
this.capacityTextBox.Location = new System.Drawing.Point(137, 68);
this.capacityTextBox.Name = "capacityTextBox";
this.capacityTextBox.Size = new System.Drawing.Size(43, 20);
this.capacityTextBox.TabIndex = 6;
@ -212,7 +215,7 @@ namespace TBF.BenchControl.MettlerToledo.Multi
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(186, 76);
this.label2.Location = new System.Drawing.Point(186, 71);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(19, 13);
this.label2.TabIndex = 7;
@ -221,76 +224,76 @@ namespace TBF.BenchControl.MettlerToledo.Multi
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(186, 99);
this.label3.Location = new System.Drawing.Point(186, 113);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(19, 13);
this.label3.TabIndex = 10;
this.label3.TabIndex = 13;
this.label3.Text = "kg";
//
// emptyTextBox
//
this.emptyTextBox.Enabled = false;
this.emptyTextBox.Location = new System.Drawing.Point(137, 96);
this.emptyTextBox.Location = new System.Drawing.Point(137, 110);
this.emptyTextBox.Name = "emptyTextBox";
this.emptyTextBox.Size = new System.Drawing.Size(43, 20);
this.emptyTextBox.TabIndex = 9;
this.emptyTextBox.TabIndex = 12;
//
// emptyLabel
//
this.emptyLabel.AutoSize = true;
this.emptyLabel.Location = new System.Drawing.Point(26, 99);
this.emptyLabel.Location = new System.Drawing.Point(26, 113);
this.emptyLabel.Name = "emptyLabel";
this.emptyLabel.Size = new System.Drawing.Size(64, 13);
this.emptyLabel.TabIndex = 8;
this.emptyLabel.TabIndex = 11;
this.emptyLabel.Text = "Tank Empty";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(186, 145);
this.label4.Location = new System.Drawing.Point(186, 155);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(24, 13);
this.label4.TabIndex = 15;
this.label4.TabIndex = 18;
this.label4.Text = "sec";
//
// emptyTimeTextBox
//
this.emptyTimeTextBox.Enabled = false;
this.emptyTimeTextBox.Location = new System.Drawing.Point(137, 142);
this.emptyTimeTextBox.Location = new System.Drawing.Point(137, 152);
this.emptyTimeTextBox.Name = "emptyTimeTextBox";
this.emptyTimeTextBox.Size = new System.Drawing.Size(43, 20);
this.emptyTimeTextBox.TabIndex = 14;
this.emptyTimeTextBox.TabIndex = 17;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(26, 145);
this.label5.Location = new System.Drawing.Point(26, 155);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(90, 13);
this.label5.TabIndex = 13;
this.label5.TabIndex = 16;
this.label5.Text = "Tank Empty Time";
//
// formatTextBox
//
this.formatTextBox.Enabled = false;
this.formatTextBox.Location = new System.Drawing.Point(137, 119);
this.formatTextBox.Location = new System.Drawing.Point(137, 131);
this.formatTextBox.Name = "formatTextBox";
this.formatTextBox.Size = new System.Drawing.Size(43, 20);
this.formatTextBox.TabIndex = 12;
this.formatTextBox.TabIndex = 15;
//
// formatLabel
//
this.formatLabel.AutoSize = true;
this.formatLabel.Location = new System.Drawing.Point(26, 122);
this.formatLabel.Location = new System.Drawing.Point(26, 134);
this.formatLabel.Name = "formatLabel";
this.formatLabel.Size = new System.Drawing.Size(76, 13);
this.formatLabel.TabIndex = 11;
this.formatLabel.TabIndex = 14;
this.formatLabel.Text = "Decimal points";
//
// idNrTextBox
//
this.idNrTextBox.Enabled = false;
this.idNrTextBox.Location = new System.Drawing.Point(137, 50);
this.idNrTextBox.Location = new System.Drawing.Point(137, 47);
this.idNrTextBox.Name = "idNrTextBox";
this.idNrTextBox.Size = new System.Drawing.Size(43, 20);
this.idNrTextBox.TabIndex = 4;
@ -299,16 +302,45 @@ namespace TBF.BenchControl.MettlerToledo.Multi
// idNrLabel
//
this.idNrLabel.AutoSize = true;
this.idNrLabel.Location = new System.Drawing.Point(26, 53);
this.idNrLabel.Location = new System.Drawing.Point(26, 50);
this.idNrLabel.Name = "idNrLabel";
this.idNrLabel.Size = new System.Drawing.Size(85, 13);
this.idNrLabel.TabIndex = 3;
this.idNrLabel.Text = "ID Number (1..3)";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(186, 92);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(19, 13);
this.label1.TabIndex = 10;
this.label1.Text = "kg";
//
// resolutionTextBox
//
this.resolutionTextBox.Enabled = false;
this.resolutionTextBox.Location = new System.Drawing.Point(137, 89);
this.resolutionTextBox.Name = "resolutionTextBox";
this.resolutionTextBox.Size = new System.Drawing.Size(43, 20);
this.resolutionTextBox.TabIndex = 9;
//
// resolutionLabel
//
this.resolutionLabel.AutoSize = true;
this.resolutionLabel.Location = new System.Drawing.Point(26, 92);
this.resolutionLabel.Name = "resolutionLabel";
this.resolutionLabel.Size = new System.Drawing.Size(57, 13);
this.resolutionLabel.TabIndex = 8;
this.resolutionLabel.Text = "Resolution";
//
// BalanceCfgCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.label1);
this.Controls.Add(this.resolutionTextBox);
this.Controls.Add(this.resolutionLabel);
this.Controls.Add(this.idNrTextBox);
this.Controls.Add(this.idNrLabel);
this.Controls.Add(this.formatTextBox);
@ -375,5 +407,8 @@ namespace TBF.BenchControl.MettlerToledo.Multi
private System.Windows.Forms.Label formatLabel;
private System.Windows.Forms.TextBox idNrTextBox;
private System.Windows.Forms.Label idNrLabel;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox resolutionTextBox;
private System.Windows.Forms.Label resolutionLabel;
}
}

View File

@ -110,6 +110,7 @@ namespace TBF.BenchControl.MettlerToledo.Multi
nameTextBox.Text = config.Name;
idNrTextBox.Text = config.IdNr.ToString();
capacityTextBox.Text = config.Capacity.ToString();
resolutionTextBox.Text = config.Resolution.ToString();
emptyTextBox.Text = config.Empty.ToString();
formatTextBox.Text = (config.Format.Length > 1) ? config.Format.Substring(1) : config.Format;
emptyTimeTextBox.Text = config.EmptyTimeSec.ToString();
@ -128,6 +129,7 @@ namespace TBF.BenchControl.MettlerToledo.Multi
idNrTextBox.Enabled = true;
capacityTextBox.Enabled = true;
resolutionTextBox.Enabled = true;
emptyTextBox.Enabled = true;
formatTextBox.Enabled = true;
emptyTimeTextBox.Enabled = true;
@ -157,6 +159,11 @@ namespace TBF.BenchControl.MettlerToledo.Multi
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Tank Capacity' is not valid";
}
if (!Utils.TryParseUFloat(resolutionTextBox.Text, out mass) || mass <= 0)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Resolution' is not valid";
}
if (!Utils.TryParseUFloat(emptyTextBox.Text, out mass) || mass <= 0)
{
flags |= CfgUpdateFlags.Error;
@ -207,6 +214,7 @@ namespace TBF.BenchControl.MettlerToledo.Multi
config.IdNr = int.Parse(idNrTextBox.Text);
config.Capacity = Utils.ParseUFloat(capacityTextBox.Text);
config.Resolution = Utils.ParseUFloat(resolutionTextBox.Text);
config.Empty = Utils.ParseUFloat(emptyTextBox.Text);
config.Format = "F" + formatTextBox.Text;
config.EmptyTimeSec = int.Parse(emptyTimeTextBox.Text);

View File

@ -34,7 +34,6 @@ namespace TBF.BenchControl.MettlerToledo.Multi
/// Enumeration of balances via static fields and methods
/// </summary>
static int nextBalanceIdx = 0;
static int currentBalanceIdx = 0;
public static new void ResetStaticProperties()
{
nextBalanceIdx = 0;
@ -50,6 +49,7 @@ namespace TBF.BenchControl.MettlerToledo.Multi
public int BalanceNr { get { return balanceNr; } }
public float Capacity { get { return balanceCfg.Capacity; } }
public float Resolution { get { return balanceCfg.Resolution; } }
public int EmptyTimeSec { get { return balanceCfg.EmptyTimeSec; } }
/// <summary>The state of the mass measurement</summary>
@ -154,7 +154,7 @@ namespace TBF.BenchControl.MettlerToledo.Multi
}
string currentBuffer = stringBuilder.ToString();
int eolPos = currentBuffer.IndexOf("\r\n");
int eolPos = currentBuffer.IndexOf("\r");
if (eolPos >= 0)
{
msrmntTimeStamp = StateMachine.Time;
@ -185,30 +185,29 @@ namespace TBF.BenchControl.MettlerToledo.Multi
}
else if (fields.Length == 3)
{
float tmpMass;
if (float.TryParse(fields[1],
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
CultureInfo.InvariantCulture,
out tmpMass))
int balanceIdNr = received[0];
if (balanceIdNr >= 1 && balanceIdNr <= nextBalanceIdx)
{
Masses[currentBalanceIdx] = tmpMass / 100.0f;
msrmntState = MsrmntState.Valid;
log.InfoFormat("Balance response = \"{0}<cr><lf>\", Mass = {1}", received, tmpMass);
}
float tmpMass;
if (float.TryParse(fields[1],
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign,
CultureInfo.InvariantCulture,
out tmpMass))
{
Masses[balanceIdNr - 1] = tmpMass * Balances[balanceIdNr - 1].Resolution;
msrmntState = MsrmntState.Valid;
log.InfoFormat("Balance response = \"{0}<cr><lf>\", Mass = {1}", received, tmpMass);
}
msrmntState = MsrmntState.Failed;
log.WarnFormat("Balance response = \"{0}<cr><lf>\", Unexpected error !!!", received);
msrmntState = MsrmntState.Failed;
log.WarnFormat("Balance response = \"{0}<cr><lf>\", Unexpected error !!!", received);
}
}
else
{
msrmntState = MsrmntState.Failed;
log.WarnFormat("Balance response = \"{0}<cr><lf>\", Unexpected error !!!", received);
}
if (++currentBalanceIdx >= nextBalanceIdx)
{
currentBalanceIdx = 0;
}
}
}