Many changes, iPerl-s have Board# param., iPerlCommunication has RFIT port nr. params, bugfixes, etc.

This commit is contained in:
Milan Hanajik
2015-08-21 20:52:10 +02:00
parent 5d00bcf456
commit 46b17fddc8
14 changed files with 409 additions and 264 deletions
@@ -24,7 +24,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
readonly WaterMeterCfg iPerlCfg;
public int RfidComPortNr { get { return iPerlCfg.RfidComPortNr; } }
public int MuxBoardNr { get { return iPerlCfg.MuxBoardNr; } }
public int Group { get { return iPerlCfg.Group; } }
public float PulsesPerLtr { get { return iPerlCfg.ProcParams.PulsesPerLtr; } }
@@ -164,6 +164,8 @@ namespace TBF.BenchControl.WaterMeters.iPerl
synchronized = false;
synchronized2 = false;
partOfTelegram = string.Empty;
flushBuffer = new char[8192];
}
public WaterMeter(WaterMeterCfg cfg)
@@ -194,7 +196,9 @@ namespace TBF.BenchControl.WaterMeters.iPerl
//optoDataLogger.Fatal("------------------------------------------------------------------------");
//optoDataLogger.Fatal("Program restarted");
/// Allocate memory for opto-data from iPerl
optoData = new OptoTelegramRaw[MaxOptoDataCount];
for (int i = 0; i < MaxOptoDataCount; i++) optoData[i] = new OptoTelegramRaw();
/// Prepare serial port
optoSerialPort = new SerialPort(string.Format("COM{0}", iPerlCfg.OptoComPortNr),
@@ -207,7 +211,14 @@ namespace TBF.BenchControl.WaterMeters.iPerl
public void RunDeviceBefore()
{
ReadOptoSerialPort();
if (optoSerialPortParsingEnabled)
{
ReadOptoSerialPort();
}
else
{
FlushOptoSerialPort();
}
}
public void RunDeviceAfter()
@@ -294,7 +305,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
/// Reset opto data
optoDataCount = 0;
optoDataLogFileName = (ConfigStruct != null) ? ConfigStruct.PCBNumber2String() : "Unknown PCBNumber";
optoDataLogFileName += "_" + Name + "_" + DateTime.Now.ToShortTimeString();
optoDataLogFileName += "_" + Name + "_" + Utils.ToMyString(DateTime.Now);
sampleNr = 0;
@@ -394,6 +405,16 @@ namespace TBF.BenchControl.WaterMeters.iPerl
optoSerialPortParsingEnabled = false;
}
char[] flushBuffer;
void FlushOptoSerialPort()
{
int nrBytes = optoSerialPort.BytesToRead;
if (nrBytes > 0) optoSerialPort.Read(flushBuffer, 0, nrBytes);
}
/// <summary>
/// 9600 Bd, 8 data bits, 1 stop bit, no parity
///
@@ -408,66 +429,55 @@ namespace TBF.BenchControl.WaterMeters.iPerl
/// </summary>
void ReadOptoSerialPort()
{
if (!optoSerialPortParsingEnabled) return;
if (DebugLevel == Entities.DebugMode.Normal || DebugLevel == Entities.DebugMode.Record)
int nrBytes = optoSerialPort.BytesToRead;
if (nrBytes > 0)
{
int nrBytes = optoSerialPort.BytesToRead;
if (nrBytes > 0)
char[] buffer = new char[nrBytes];
optoSerialPort.Read(buffer, 0, nrBytes);
string received = new string(buffer);
string allRcvd = partOfTelegram + received;
while (true)
{
char[] buffer = new char[nrBytes];
optoSerialPort.Read(buffer, 0, nrBytes);
string received = new string(buffer);
int pos = allRcvd.IndexOf("\r\n");
string allRcvd = partOfTelegram + received;
while (true)
if (pos < 0)
{
int pos = allRcvd.IndexOf("\r\n");
if (pos < 0)
{
/// No CR+LF found, wait for more characters in the next invocation
partOfTelegram = allRcvd;
return;
}
// CR+LF found
else if (pos < OptoTelegram.Length - 2)
{
/// CR+LF found too early, truncate the beginning incl CR+LF and keep scanning in this loop
allRcvd = allRcvd.Substring(pos + 2);
if (synchronized)
{
optoData[optoDataCount++].SetFlags(OptoTelegramFlags.SyncError);
}
synchronized = true;
}
// CR+LF found and (pos >= OptoTelegram.Length - 2)
else if (optoData[optoDataCount].UpdateFromString(allRcvd.Substring(pos - OptoTelegramRaw.Length + 2)))
{
OptoTelegramRreceived(optoData[optoDataCount++], synchronized2);
synchronized2 = synchronized;
allRcvd = allRcvd.Substring(pos + 2);
}
else
{
optoData[optoDataCount++].SetFlags(OptoTelegramFlags.InvalidTelegram);
allRcvd = allRcvd.Substring(pos + 2);
}
/// No CR+LF found, wait for more characters in the next invocation
partOfTelegram = allRcvd;
return;
}
// CR+LF found
else if (pos < OptoTelegram.Length - 2)
{
/// CR+LF found too early, truncate the beginning incl CR+LF and keep scanning in this loop
allRcvd = allRcvd.Substring(pos + 2);
if (synchronized)
{
optoData[optoDataCount++].SetFlags(OptoTelegramFlags.SyncError);
}
synchronized = true;
}
// CR+LF found and (pos >= OptoTelegram.Length - 2)
else if (optoData[optoDataCount].UpdateFromString(allRcvd.Substring(pos - OptoTelegramRaw.Length + 2)))
{
OptoTelegramRreceived(optoData[optoDataCount++], synchronized2);
synchronized2 = synchronized;
allRcvd = allRcvd.Substring(pos + 2);
}
else
{
optoData[optoDataCount++].SetFlags(OptoTelegramFlags.InvalidTelegram);
allRcvd = allRcvd.Substring(pos + 2);
}
}
//OnOptoReceived(this, new OptoReceivedEventArgs(s));
}
else
{
//OnOptoReceived(this, new OptoReceivedEventArgs("."));
}
//OnOptoReceived(this, new OptoReceivedEventArgs(s));
}
else if (DebugLevel == Entities.DebugMode.Simulate)
{
}
else if (DebugLevel == Entities.DebugMode.Reply)
else
{
//OnOptoReceived(this, new OptoReceivedEventArgs("."));
}
}
@@ -21,8 +21,8 @@ namespace TBF.BenchControl.WaterMeters.iPerl
///
public MeterType MeterType;
public int OptoComPortNr;
public int RfidComPortNr;
public int Group; /// Number written to QuidoRS to connct the watermeter to RfidComPort
public int MuxBoardNr; /// Multiplexer board number 1 .. 4
public int Group; /// Number written to QuidoRS to connct the watermeter to RfidComPort
/// <summary> Procedure parameters </summary>
[XmlIgnore]
@@ -56,7 +56,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
Name,
MeterType,
OptoComPortNr,
RfidComPortNr,
MuxBoardNr,
Group);
}
}
@@ -50,7 +50,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
nameTextBox.Text = config.Name;
meterTypeComboBox.Text = config.MeterType.ToString();
optoPortNrTextBox.Text = config.OptoComPortNr.ToString();
rfidPortNrTextBox.Text = config.RfidComPortNr.ToString();
muxBoardNrTextBox.Text = config.MuxBoardNr.ToString();
groupTextBox.Text = config.Group.ToString();
}
@@ -59,7 +59,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
nameTextBox.Enabled = true;
meterTypeComboBox.Enabled = true;
optoPortNrTextBox.Enabled = true;
rfidPortNrTextBox.Enabled = true;
muxBoardNrTextBox.Enabled = true;
groupTextBox.Enabled = true;
}
@@ -79,7 +79,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Opto Serial Port Nr.' is not valid";
}
if (!int.TryParse(rfidPortNrTextBox.Text, out dummy) || dummy < 1 || dummy > 999)
if (!int.TryParse(muxBoardNrTextBox.Text, out dummy) || dummy < 1 || dummy > 999)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'RFID Serial Port Nr.' is not valid";
@@ -102,7 +102,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
config.Name = nameTextBox.Text;
config.MeterType = (MeterType)meterTypeComboBox.SelectedIndex;
config.OptoComPortNr = int.Parse(optoPortNrTextBox.Text);
config.RfidComPortNr = int.Parse(rfidPortNrTextBox.Text);
config.MuxBoardNr = int.Parse(muxBoardNrTextBox.Text);
config.Group = int.Parse(groupTextBox.Text);
return flags;
@@ -32,134 +32,134 @@ namespace TBF.BenchControl.WaterMeters.iPerl
/// </summary>
private void InitializeComponent()
{
this.nameTextBox = new System.Windows.Forms.TextBox();
this.nameLabel = new System.Windows.Forms.Label();
this.classNameLabel = new System.Windows.Forms.Label();
this.optoPortNrTextBox = new System.Windows.Forms.TextBox();
this.optoPortNrLabel = new System.Windows.Forms.Label();
this.rfidPortNrTextBox = new System.Windows.Forms.TextBox();
this.rfidPortNrLabel = new System.Windows.Forms.Label();
this.groupTextBox = new System.Windows.Forms.TextBox();
this.groupLabel = new System.Windows.Forms.Label();
this.meterTypeLabel = new System.Windows.Forms.Label();
this.meterTypeComboBox = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// nameTextBox
//
this.nameTextBox.Enabled = false;
this.nameTextBox.Location = new System.Drawing.Point(135, 55);
this.nameTextBox.Name = "nameTextBox";
this.nameTextBox.Size = new System.Drawing.Size(121, 20);
this.nameTextBox.TabIndex = 5;
//
// nameLabel
//
this.nameLabel.AutoSize = true;
this.nameLabel.Location = new System.Drawing.Point(25, 58);
this.nameLabel.Name = "nameLabel";
this.nameLabel.Size = new System.Drawing.Size(35, 13);
this.nameLabel.TabIndex = 4;
this.nameLabel.Text = "Name";
//
// classNameLabel
//
this.classNameLabel.AutoSize = true;
this.classNameLabel.Location = new System.Drawing.Point(132, 31);
this.classNameLabel.Name = "classNameLabel";
this.classNameLabel.Size = new System.Drawing.Size(60, 13);
this.classNameLabel.TabIndex = 3;
this.classNameLabel.Text = "ClassName";
//
// optoPortNrTextBox
//
this.optoPortNrTextBox.Enabled = false;
this.optoPortNrTextBox.Location = new System.Drawing.Point(135, 104);
this.optoPortNrTextBox.Name = "optoPortNrTextBox";
this.optoPortNrTextBox.Size = new System.Drawing.Size(34, 20);
this.optoPortNrTextBox.TabIndex = 7;
//
// optoPortNrLabel
//
this.optoPortNrLabel.AutoSize = true;
this.optoPortNrLabel.Location = new System.Drawing.Point(25, 107);
this.optoPortNrLabel.Name = "optoPortNrLabel";
this.optoPortNrLabel.Size = new System.Drawing.Size(101, 13);
this.optoPortNrLabel.TabIndex = 6;
this.optoPortNrLabel.Text = "Opto Serial Port Nr.:";
//
// rfidPortNrTextBox
//
this.rfidPortNrTextBox.Enabled = false;
this.rfidPortNrTextBox.Location = new System.Drawing.Point(135, 128);
this.rfidPortNrTextBox.Name = "rfidPortNrTextBox";
this.rfidPortNrTextBox.Size = new System.Drawing.Size(34, 20);
this.rfidPortNrTextBox.TabIndex = 9;
//
// rfidPortNrLabel
//
this.rfidPortNrLabel.AutoSize = true;
this.rfidPortNrLabel.Location = new System.Drawing.Point(25, 131);
this.rfidPortNrLabel.Name = "rfidPortNrLabel";
this.rfidPortNrLabel.Size = new System.Drawing.Size(103, 13);
this.rfidPortNrLabel.TabIndex = 8;
this.rfidPortNrLabel.Text = "RFID Serial Port Nr.:";
//
// groupTextBox
//
this.groupTextBox.Enabled = false;
this.groupTextBox.Location = new System.Drawing.Point(135, 152);
this.groupTextBox.Name = "groupTextBox";
this.groupTextBox.Size = new System.Drawing.Size(34, 20);
this.groupTextBox.TabIndex = 11;
//
// groupLabel
//
this.groupLabel.AutoSize = true;
this.groupLabel.Location = new System.Drawing.Point(25, 155);
this.groupLabel.Name = "groupLabel";
this.groupLabel.Size = new System.Drawing.Size(39, 13);
this.groupLabel.TabIndex = 10;
this.groupLabel.Text = "Group:";
//
// meterTypeLabel
//
this.meterTypeLabel.AutoSize = true;
this.meterTypeLabel.Location = new System.Drawing.Point(25, 82);
this.meterTypeLabel.Name = "meterTypeLabel";
this.meterTypeLabel.Size = new System.Drawing.Size(57, 13);
this.meterTypeLabel.TabIndex = 12;
this.meterTypeLabel.Text = "Meter type";
//
// meterTypeComboBox
//
this.meterTypeComboBox.Enabled = false;
this.meterTypeComboBox.FormattingEnabled = true;
this.meterTypeComboBox.Location = new System.Drawing.Point(135, 79);
this.meterTypeComboBox.Name = "meterTypeComboBox";
this.meterTypeComboBox.Size = new System.Drawing.Size(121, 21);
this.meterTypeComboBox.TabIndex = 13;
//
// WaterMeterCfgCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.meterTypeComboBox);
this.Controls.Add(this.meterTypeLabel);
this.Controls.Add(this.groupTextBox);
this.Controls.Add(this.groupLabel);
this.Controls.Add(this.rfidPortNrTextBox);
this.Controls.Add(this.rfidPortNrLabel);
this.Controls.Add(this.optoPortNrTextBox);
this.Controls.Add(this.optoPortNrLabel);
this.Controls.Add(this.nameTextBox);
this.Controls.Add(this.nameLabel);
this.Controls.Add(this.classNameLabel);
this.Name = "WaterMeterCfgCtrl";
this.Size = new System.Drawing.Size(300, 200);
this.Load += new System.EventHandler(this.WaterMeterCfgCtrl_Load);
this.ResumeLayout(false);
this.PerformLayout();
this.nameTextBox = new System.Windows.Forms.TextBox();
this.nameLabel = new System.Windows.Forms.Label();
this.classNameLabel = new System.Windows.Forms.Label();
this.optoPortNrTextBox = new System.Windows.Forms.TextBox();
this.optoPortNrLabel = new System.Windows.Forms.Label();
this.muxBoardNrTextBox = new System.Windows.Forms.TextBox();
this.muxBoardNrLabel = new System.Windows.Forms.Label();
this.groupTextBox = new System.Windows.Forms.TextBox();
this.groupLabel = new System.Windows.Forms.Label();
this.meterTypeLabel = new System.Windows.Forms.Label();
this.meterTypeComboBox = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// nameTextBox
//
this.nameTextBox.Enabled = false;
this.nameTextBox.Location = new System.Drawing.Point(135, 55);
this.nameTextBox.Name = "nameTextBox";
this.nameTextBox.Size = new System.Drawing.Size(121, 20);
this.nameTextBox.TabIndex = 5;
//
// nameLabel
//
this.nameLabel.AutoSize = true;
this.nameLabel.Location = new System.Drawing.Point(25, 58);
this.nameLabel.Name = "nameLabel";
this.nameLabel.Size = new System.Drawing.Size(35, 13);
this.nameLabel.TabIndex = 4;
this.nameLabel.Text = "Name";
//
// classNameLabel
//
this.classNameLabel.AutoSize = true;
this.classNameLabel.Location = new System.Drawing.Point(132, 31);
this.classNameLabel.Name = "classNameLabel";
this.classNameLabel.Size = new System.Drawing.Size(60, 13);
this.classNameLabel.TabIndex = 3;
this.classNameLabel.Text = "ClassName";
//
// optoPortNrTextBox
//
this.optoPortNrTextBox.Enabled = false;
this.optoPortNrTextBox.Location = new System.Drawing.Point(135, 104);
this.optoPortNrTextBox.Name = "optoPortNrTextBox";
this.optoPortNrTextBox.Size = new System.Drawing.Size(34, 20);
this.optoPortNrTextBox.TabIndex = 7;
//
// optoPortNrLabel
//
this.optoPortNrLabel.AutoSize = true;
this.optoPortNrLabel.Location = new System.Drawing.Point(25, 107);
this.optoPortNrLabel.Name = "optoPortNrLabel";
this.optoPortNrLabel.Size = new System.Drawing.Size(96, 13);
this.optoPortNrLabel.TabIndex = 6;
this.optoPortNrLabel.Text = "Opto serial port nr.:";
//
// muxBoardNrTextBox
//
this.muxBoardNrTextBox.Enabled = false;
this.muxBoardNrTextBox.Location = new System.Drawing.Point(135, 128);
this.muxBoardNrTextBox.Name = "muxBoardNrTextBox";
this.muxBoardNrTextBox.Size = new System.Drawing.Size(34, 20);
this.muxBoardNrTextBox.TabIndex = 9;
//
// muxBoardNrLabel
//
this.muxBoardNrLabel.AutoSize = true;
this.muxBoardNrLabel.Location = new System.Drawing.Point(25, 131);
this.muxBoardNrLabel.Name = "muxBoardNrLabel";
this.muxBoardNrLabel.Size = new System.Drawing.Size(78, 13);
this.muxBoardNrLabel.TabIndex = 8;
this.muxBoardNrLabel.Text = "Mux. board nr.:";
//
// groupTextBox
//
this.groupTextBox.Enabled = false;
this.groupTextBox.Location = new System.Drawing.Point(135, 152);
this.groupTextBox.Name = "groupTextBox";
this.groupTextBox.Size = new System.Drawing.Size(34, 20);
this.groupTextBox.TabIndex = 11;
//
// groupLabel
//
this.groupLabel.AutoSize = true;
this.groupLabel.Location = new System.Drawing.Point(25, 155);
this.groupLabel.Name = "groupLabel";
this.groupLabel.Size = new System.Drawing.Size(39, 13);
this.groupLabel.TabIndex = 10;
this.groupLabel.Text = "Group:";
//
// meterTypeLabel
//
this.meterTypeLabel.AutoSize = true;
this.meterTypeLabel.Location = new System.Drawing.Point(25, 82);
this.meterTypeLabel.Name = "meterTypeLabel";
this.meterTypeLabel.Size = new System.Drawing.Size(57, 13);
this.meterTypeLabel.TabIndex = 12;
this.meterTypeLabel.Text = "Meter type";
//
// meterTypeComboBox
//
this.meterTypeComboBox.Enabled = false;
this.meterTypeComboBox.FormattingEnabled = true;
this.meterTypeComboBox.Location = new System.Drawing.Point(135, 79);
this.meterTypeComboBox.Name = "meterTypeComboBox";
this.meterTypeComboBox.Size = new System.Drawing.Size(121, 21);
this.meterTypeComboBox.TabIndex = 13;
//
// WaterMeterCfgCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.meterTypeComboBox);
this.Controls.Add(this.meterTypeLabel);
this.Controls.Add(this.groupTextBox);
this.Controls.Add(this.groupLabel);
this.Controls.Add(this.muxBoardNrTextBox);
this.Controls.Add(this.muxBoardNrLabel);
this.Controls.Add(this.optoPortNrTextBox);
this.Controls.Add(this.optoPortNrLabel);
this.Controls.Add(this.nameTextBox);
this.Controls.Add(this.nameLabel);
this.Controls.Add(this.classNameLabel);
this.Name = "WaterMeterCfgCtrl";
this.Size = new System.Drawing.Size(300, 200);
this.Load += new System.EventHandler(this.WaterMeterCfgCtrl_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
@@ -170,8 +170,8 @@ namespace TBF.BenchControl.WaterMeters.iPerl
private System.Windows.Forms.Label classNameLabel;
private System.Windows.Forms.TextBox optoPortNrTextBox;
private System.Windows.Forms.Label optoPortNrLabel;
private System.Windows.Forms.TextBox rfidPortNrTextBox;
private System.Windows.Forms.Label rfidPortNrLabel;
private System.Windows.Forms.TextBox muxBoardNrTextBox;
private System.Windows.Forms.Label muxBoardNrLabel;
private System.Windows.Forms.TextBox groupTextBox;
private System.Windows.Forms.Label groupLabel;
private System.Windows.Forms.Label meterTypeLabel;