From 4dcd018642918bda943a7693365ddf5cf6b2cfe1 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Thu, 23 Jun 2016 16:39:56 +0200 Subject: [PATCH] Keithley.RS232 and Keithley.TempMeter components added, ver. 2.8.313 --- .../BenchControl/Keithley/RS232/Factory.cs | 23 ++ .../BenchControl/Keithley/RS232/Multimeter.cs | 134 ++++++++++ .../Keithley/RS232/MultimeterCfg.cs | 52 ++++ .../Keithley/RS232/MultimeterCfgCtrl.cs | 173 +++++++++++++ .../RS232/MultimeterCfgCtrl.designer.cs | 229 ++++++++++++++++++ .../Keithley/RS232/MultimeterCfgCtrl.resx | 120 +++++++++ .../Keithley/TempMeter/Factory.cs | 23 ++ .../Keithley/TempMeter/ReadTempOp.cs | 63 +++++ .../Keithley/TempMeter/TempMeter.cs | 59 +++++ .../Keithley/TempMeter/TempMeterCfg.cs | 44 ++++ .../TempMeter/TempMeterCfgCtrl.Designer.cs | 133 ++++++++++ .../Keithley/TempMeter/TempMeterCfgCtrl.cs | 108 +++++++++ .../Keithley/TempMeter/TempMeterCfgCtrl.resx | 120 +++++++++ .../BenchControl/TbfComponents.cs | 6 +- TestBenchFramework/Properties/AssemblyInfo.cs | 4 +- TestBenchFramework/TBF.csproj | 25 ++ 16 files changed, 1312 insertions(+), 4 deletions(-) create mode 100644 TestBenchFramework/BenchControl/Keithley/RS232/Factory.cs create mode 100644 TestBenchFramework/BenchControl/Keithley/RS232/Multimeter.cs create mode 100644 TestBenchFramework/BenchControl/Keithley/RS232/MultimeterCfg.cs create mode 100644 TestBenchFramework/BenchControl/Keithley/RS232/MultimeterCfgCtrl.cs create mode 100644 TestBenchFramework/BenchControl/Keithley/RS232/MultimeterCfgCtrl.designer.cs create mode 100644 TestBenchFramework/BenchControl/Keithley/RS232/MultimeterCfgCtrl.resx create mode 100644 TestBenchFramework/BenchControl/Keithley/TempMeter/Factory.cs create mode 100644 TestBenchFramework/BenchControl/Keithley/TempMeter/ReadTempOp.cs create mode 100644 TestBenchFramework/BenchControl/Keithley/TempMeter/TempMeter.cs create mode 100644 TestBenchFramework/BenchControl/Keithley/TempMeter/TempMeterCfg.cs create mode 100644 TestBenchFramework/BenchControl/Keithley/TempMeter/TempMeterCfgCtrl.Designer.cs create mode 100644 TestBenchFramework/BenchControl/Keithley/TempMeter/TempMeterCfgCtrl.cs create mode 100644 TestBenchFramework/BenchControl/Keithley/TempMeter/TempMeterCfgCtrl.resx diff --git a/TestBenchFramework/BenchControl/Keithley/RS232/Factory.cs b/TestBenchFramework/BenchControl/Keithley/RS232/Factory.cs new file mode 100644 index 000000000..47f13adfb --- /dev/null +++ b/TestBenchFramework/BenchControl/Keithley/RS232/Factory.cs @@ -0,0 +1,23 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +using TBF.BenchControl.Generic; + +namespace TBF.BenchControl.Keithley.RS232 +{ + public class Factory : IComponentFactory + { + public string ClassName { get { return this.GetType().Namespace.Substring(17) + ".Multimeter"; } } + + public void ResetStaticProperties() { Multimeter.ResetStaticProperties(); } + + public IComponent DummyComponent() { return new Multimeter(); } + + public IComponentCfg DefaultConfig() { return new MultimeterCfg(this); } + + public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component) + { + return ComponentCfgBase.CreateFromDbEntity(typeof(MultimeterCfg), component, this); + } + } +} diff --git a/TestBenchFramework/BenchControl/Keithley/RS232/Multimeter.cs b/TestBenchFramework/BenchControl/Keithley/RS232/Multimeter.cs new file mode 100644 index 000000000..2c9d6c9b4 --- /dev/null +++ b/TestBenchFramework/BenchControl/Keithley/RS232/Multimeter.cs @@ -0,0 +1,134 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO.Ports; +using System.Text; +using System.Threading; +using log4net; +using Config.Entities; +using TBF.BenchControl.Generic; +using TBF.Boxes; + +namespace TBF.BenchControl.Keithley.RS232 +{ + /// + /// Root component for Modbus communication via serial port (RS485) + /// + public class Multimeter : ComponentBase, IDevice, GenericDevices.IModbus + { + private static readonly ILog log = LogManager.GetLogger(typeof(Multimeter)); + public override string ToString() { return string.Format("Keithley.RS232.Multimeter({0})", Cfg.ToString(1)); } + + private readonly MultimeterCfg modbusCommonCfg; + + /// Private fields + SerialPort serialPort; + Thread workerThread; + bool stopWorkerThread; + + public Multimeter() + { + } + + /// + /// Ambient temperature / humidity / pressure meter 'Greco' connected via serial interface (RS232) + /// Connection settings: 19200 Bd 8-bits No-parity 1-stop-bit Flow control: none or hardware. + /// + public Multimeter(MultimeterCfg cfg, IList components) + : base(cfg) + { + serialPort = null; + modbusCommonCfg = cfg; + log.Debug(this.ToString()); + } + + ~Multimeter() + { + } + + public float GetTemperature(int channelNr) + { + return 25.0f; + } + + + public void Initialize() + { + if (modbusCommonCfg.DebugLevel == DebugMode.Simulate) + { + log.FatalFormat("Simulated device {0}", ToString()); + return; + } + + string comPortName = "COM" + modbusCommonCfg.ComPortNr.ToString(); + serialPort = new SerialPort(comPortName, modbusCommonCfg.BaudRate, modbusCommonCfg.Parity, modbusCommonCfg.DataBits, modbusCommonCfg.StopBits); + serialPort.Handshake = modbusCommonCfg.Handshake; + serialPort.Open(); + + stopWorkerThread = false; + workerThread = new Thread(Worker); + workerThread.Start(); + + log.FatalFormat("Successfully initialized device {0}", ToString()); + } + + + /// + /// Send a modbus message. + /// This function calculates and overwrites the last 2 bytes + /// of the message - CRC as specified in Modbus specification. + /// + /// Message incl CRC, CRC bytes dont have to be set + public void SendMessage(byte[] message) + { + if (modbusCommonCfg.DebugLevel == DebugMode.Simulate) return; + + Telegram.UpdateTelegramCRC(message); + log.Debug(Telegram.LogTelegram("Sending message ", message)); + serialPort.Write(message, 0, message.Length); + } + + void Worker() + { + while (!stopWorkerThread) + { + Thread.Sleep(250); + if (stopWorkerThread) break; + int nrBytes = serialPort.BytesToRead; + if (nrBytes > 0) + { + char[] buffer = new char[nrBytes]; + serialPort.Read(buffer, 0, nrBytes); + string s = Telegram.LogTelegram("Received: ", new string(buffer)); + /// ODO: Add handler + //OnQuidoReceived(this, new QuidoReceivedEventArgs(s)); + } + } + } + + + /// Run this device + public void RunDeviceBefore() + { + } + + /// Run this device + public void RunDeviceAfter() + { + } + + /// Stop this device + public void StopDevice() + { + if (serialPort != null) + { + stopWorkerThread = true; + workerThread.Join(2000); + serialPort.Close(); + } + } + } +} diff --git a/TestBenchFramework/BenchControl/Keithley/RS232/MultimeterCfg.cs b/TestBenchFramework/BenchControl/Keithley/RS232/MultimeterCfg.cs new file mode 100644 index 000000000..854cdb72e --- /dev/null +++ b/TestBenchFramework/BenchControl/Keithley/RS232/MultimeterCfg.cs @@ -0,0 +1,52 @@ +/// +/// Copyright (c) 2016 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.Keithley.RS232 +{ + public class MultimeterCfg : ComponentCfgBase, Generic.IComponentCfg + { + public IComponent GetComponent(IList components) { return new Multimeter(this, components); } + public IComponentCfgCtrl GetControl() { return new MultimeterCfgCtrl(); } + + /// + /// Serialized parameters + /// + 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 + MultimeterCfg() + { + Name = "Keithley"; + ParentName = string.Empty; + ComPortNr = 5; + BaudRate = 9600; + Parity = System.IO.Ports.Parity.None; + DataBits = 8; + StopBits = System.IO.Ports.StopBits.One; + Handshake = System.IO.Ports.Handshake.None; + } + + public MultimeterCfg(IComponentFactory factory) + : this() + { + this.Factory = factory; + } + + public string ToString(int i) + { + return string.Format("Name={0}, Com{1}, {2}Bd, {3}-bits, parity={4}, stopBits={5}, {6}", + Name, ComPortNr, BaudRate, DataBits, Parity, StopBits, Handshake); + } + } +} diff --git a/TestBenchFramework/BenchControl/Keithley/RS232/MultimeterCfgCtrl.cs b/TestBenchFramework/BenchControl/Keithley/RS232/MultimeterCfgCtrl.cs new file mode 100644 index 000000000..116b8fd2f --- /dev/null +++ b/TestBenchFramework/BenchControl/Keithley/RS232/MultimeterCfgCtrl.cs @@ -0,0 +1,173 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +using System; +using System.Windows.Forms; +using System.IO.Ports; +using log4net; +using TBF.BenchControl.Generic; +using TBF.Resources; + +namespace TBF.BenchControl.Keithley.RS232 +{ + public partial class MultimeterCfgCtrl : UserControl, IComponentCfgCtrl + { + static readonly ILog log = LogManager.GetLogger(typeof(MultimeterCfgCtrl)); + + public bool ShowMore { get { return false; } } + + MultimeterCfg config; + public IComponentCfg Config + { + get { return config as IComponentCfg; } + set + { + config = value as MultimeterCfg; + Redraw(); + } + } + + public MultimeterCfgCtrl() + { + 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 ModbusCfgCtrl_Load(object sender, EventArgs e) + { + nameLabel.Text = Strings.Name; + Redraw(); + } + + public void Closing() + { + } + + void Redraw() + { + if (config == null) return; /// Control was not loaded, settings were not changed + + classNameLabel.Text = config.Factory.ClassName; + nameTextBox.Text = config.Name; + 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; + comPortNrTextBox.Enabled = true; + baudRateTextBox.Enabled = true; + parityComboBox.Enabled = true; + dataBitsTextBox.Enabled = true; + stopBitsComboBox.Enabled = true; + handshakeComboBox.Enabled = true; + } + + 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.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; + } + + public CfgUpdateFlags VerifyCfg(ref string message) + { + CfgUpdateFlags flags = CfgUpdateFlags.None; + + int dummy; + 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; + } + } +} diff --git a/TestBenchFramework/BenchControl/Keithley/RS232/MultimeterCfgCtrl.designer.cs b/TestBenchFramework/BenchControl/Keithley/RS232/MultimeterCfgCtrl.designer.cs new file mode 100644 index 000000000..9f47819ab --- /dev/null +++ b/TestBenchFramework/BenchControl/Keithley/RS232/MultimeterCfgCtrl.designer.cs @@ -0,0 +1,229 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +namespace TBF.BenchControl.Keithley.RS232 +{ + partial class MultimeterCfgCtrl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.comPortNrTextBox = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.baudRateLabel = new System.Windows.Forms.Label(); + this.baudRateTextBox = new System.Windows.Forms.TextBox(); + this.partityLabel = new System.Windows.Forms.Label(); + this.dataBitsLabel = new System.Windows.Forms.Label(); + this.dataBitsTextBox = new System.Windows.Forms.TextBox(); + this.stopBitsLabel = new System.Windows.Forms.Label(); + this.handshakeLabel = new System.Windows.Forms.Label(); + this.nameTextBox = new System.Windows.Forms.TextBox(); + this.nameLabel = new System.Windows.Forms.Label(); + this.classNameLabel = new System.Windows.Forms.Label(); + this.parityComboBox = new System.Windows.Forms.ComboBox(); + this.stopBitsComboBox = new System.Windows.Forms.ComboBox(); + this.handshakeComboBox = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // comPortNrTextBox + // + this.comPortNrTextBox.Enabled = false; + this.comPortNrTextBox.Location = new System.Drawing.Point(140, 52); + this.comPortNrTextBox.Name = "comPortNrTextBox"; + this.comPortNrTextBox.Size = new System.Drawing.Size(34, 20); + this.comPortNrTextBox.TabIndex = 4; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(29, 55); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(98, 13); + this.label1.TabIndex = 3; + this.label1.Text = "Serial Port Number:"; + // + // baudRateLabel + // + this.baudRateLabel.AutoSize = true; + this.baudRateLabel.Location = new System.Drawing.Point(29, 79); + this.baudRateLabel.Name = "baudRateLabel"; + this.baudRateLabel.Size = new System.Drawing.Size(58, 13); + this.baudRateLabel.TabIndex = 5; + this.baudRateLabel.Text = "Baud Rate"; + // + // baudRateTextBox + // + this.baudRateTextBox.Enabled = false; + this.baudRateTextBox.Location = new System.Drawing.Point(140, 76); + this.baudRateTextBox.Name = "baudRateTextBox"; + this.baudRateTextBox.Size = new System.Drawing.Size(130, 20); + this.baudRateTextBox.TabIndex = 6; + // + // partityLabel + // + this.partityLabel.AutoSize = true; + this.partityLabel.Location = new System.Drawing.Point(29, 103); + this.partityLabel.Name = "partityLabel"; + this.partityLabel.Size = new System.Drawing.Size(33, 13); + this.partityLabel.TabIndex = 7; + this.partityLabel.Text = "Parity"; + // + // dataBitsLabel + // + this.dataBitsLabel.AutoSize = true; + this.dataBitsLabel.Location = new System.Drawing.Point(29, 127); + this.dataBitsLabel.Name = "dataBitsLabel"; + this.dataBitsLabel.Size = new System.Drawing.Size(50, 13); + this.dataBitsLabel.TabIndex = 9; + this.dataBitsLabel.Text = "Data Bits"; + // + // dataBitsTextBox + // + this.dataBitsTextBox.Enabled = false; + this.dataBitsTextBox.Location = new System.Drawing.Point(140, 124); + this.dataBitsTextBox.Name = "dataBitsTextBox"; + this.dataBitsTextBox.Size = new System.Drawing.Size(34, 20); + this.dataBitsTextBox.TabIndex = 10; + // + // stopBitsLabel + // + this.stopBitsLabel.AutoSize = true; + this.stopBitsLabel.Location = new System.Drawing.Point(29, 151); + this.stopBitsLabel.Name = "stopBitsLabel"; + this.stopBitsLabel.Size = new System.Drawing.Size(49, 13); + this.stopBitsLabel.TabIndex = 11; + this.stopBitsLabel.Text = "Stop Bits"; + // + // handshakeLabel + // + this.handshakeLabel.AutoSize = true; + this.handshakeLabel.Location = new System.Drawing.Point(29, 175); + this.handshakeLabel.Name = "handshakeLabel"; + this.handshakeLabel.Size = new System.Drawing.Size(62, 13); + this.handshakeLabel.TabIndex = 13; + this.handshakeLabel.Text = "Handshake"; + // + // nameTextBox + // + this.nameTextBox.Enabled = false; + this.nameTextBox.Location = new System.Drawing.Point(140, 28); + 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(30, 31); + 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(137, 7); + this.classNameLabel.Name = "classNameLabel"; + this.classNameLabel.Size = new System.Drawing.Size(83, 13); + this.classNameLabel.TabIndex = 0; + this.classNameLabel.Text = "ComonentName"; + // + // parityComboBox + // + this.parityComboBox.Enabled = false; + this.parityComboBox.FormattingEnabled = true; + this.parityComboBox.Location = new System.Drawing.Point(140, 100); + this.parityComboBox.Name = "parityComboBox"; + this.parityComboBox.Size = new System.Drawing.Size(130, 21); + this.parityComboBox.TabIndex = 8; + // + // stopBitsComboBox + // + this.stopBitsComboBox.Enabled = false; + this.stopBitsComboBox.FormattingEnabled = true; + this.stopBitsComboBox.Location = new System.Drawing.Point(140, 148); + this.stopBitsComboBox.Name = "stopBitsComboBox"; + this.stopBitsComboBox.Size = new System.Drawing.Size(130, 21); + this.stopBitsComboBox.TabIndex = 12; + // + // handshakeComboBox + // + this.handshakeComboBox.Enabled = false; + this.handshakeComboBox.FormattingEnabled = true; + this.handshakeComboBox.Location = new System.Drawing.Point(140, 172); + this.handshakeComboBox.Name = "handshakeComboBox"; + this.handshakeComboBox.Size = new System.Drawing.Size(130, 21); + this.handshakeComboBox.TabIndex = 14; + // + // AmbientCfgCtrl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.SystemColors.Control; + 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 = "AmbientCfgCtrl"; + this.Size = new System.Drawing.Size(300, 240); + this.Load += new System.EventHandler(this.ModbusCfgCtrl_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox comPortNrTextBox; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label baudRateLabel; + private System.Windows.Forms.TextBox baudRateTextBox; + private System.Windows.Forms.Label partityLabel; + private System.Windows.Forms.Label dataBitsLabel; + private System.Windows.Forms.TextBox dataBitsTextBox; + private System.Windows.Forms.Label stopBitsLabel; + private System.Windows.Forms.Label handshakeLabel; + private System.Windows.Forms.TextBox nameTextBox; + private System.Windows.Forms.Label nameLabel; + private System.Windows.Forms.Label classNameLabel; + private System.Windows.Forms.ComboBox parityComboBox; + private System.Windows.Forms.ComboBox stopBitsComboBox; + private System.Windows.Forms.ComboBox handshakeComboBox; + + } +} diff --git a/TestBenchFramework/BenchControl/Keithley/RS232/MultimeterCfgCtrl.resx b/TestBenchFramework/BenchControl/Keithley/RS232/MultimeterCfgCtrl.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/TestBenchFramework/BenchControl/Keithley/RS232/MultimeterCfgCtrl.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TestBenchFramework/BenchControl/Keithley/TempMeter/Factory.cs b/TestBenchFramework/BenchControl/Keithley/TempMeter/Factory.cs new file mode 100644 index 000000000..82bcbe066 --- /dev/null +++ b/TestBenchFramework/BenchControl/Keithley/TempMeter/Factory.cs @@ -0,0 +1,23 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +using TBF.BenchControl.Generic; + +namespace TBF.BenchControl.Keithley.TempMeter +{ + public class Factory : IComponentFactory + { + public string ClassName { get { return this.GetType().Namespace.Substring(17); } } + + public void ResetStaticProperties() { TempMeter.ResetStaticProperties(); } + + public IComponent DummyComponent() { return new TempMeter(); } + + public IComponentCfg DefaultConfig() { return new TempMeterCfg(this); } + + public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component) + { + return ComponentCfgBase.CreateFromDbEntity(typeof(TempMeterCfg), component, this); + } + } +} diff --git a/TestBenchFramework/BenchControl/Keithley/TempMeter/ReadTempOp.cs b/TestBenchFramework/BenchControl/Keithley/TempMeter/ReadTempOp.cs new file mode 100644 index 000000000..177cb1969 --- /dev/null +++ b/TestBenchFramework/BenchControl/Keithley/TempMeter/ReadTempOp.cs @@ -0,0 +1,63 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +using System; +using log4net; +using TBF.Boxes; +using TBF.BenchControl.Keithley.RS232; + +namespace TBF.BenchControl.Keithley.TempMeter +{ + public class ReadTempOp : IOperation + { + private static readonly ILog log = LogManager.GetLogger(typeof(ReadTempOp)); + public override string ToString() { return string.Format("ReadTempOp(.,{0},{1},.)", eventDone, tempMeterNr); } + + /// Set by the constructor + Multimeter multimeter; + Event eventDone; + int tempMeterNr; + FloatBox temp; + + /// + /// Events: TempInDone, TempOutDone, TempDivDone or Error + /// + /// TempMeter reference + /// Reference to the variable, value is in degree Celsius + /// Event to be returned by Run() when completed OK + public ReadTempOp(TempMeter tempMeter, ref FloatBox temp, Event eventDone) + { + if (tempMeter == null) throw new ArgumentNullException("tempMeter"); + this.multimeter = tempMeter.Multimeter; + this.tempMeterNr = tempMeter.Idx0; + this.temp = temp; + this.eventDone = eventDone; + log.Debug(this.ToString()); + } + public ReadTempOp(TempMeter tempMeter, ref FloatBox temp) + : this(tempMeter, ref temp, Event.TempDone) + { + } + + /// Start this operation + public void Start() + { + temp.Val = multimeter.GetTemperature(tempMeterNr); + } + + /// Run this operation + /// + /// Event.TempInDone, Event.TempOutDone or Event.TempDivDone + /// + public Event Run() + { + temp.Val = multimeter.GetTemperature(tempMeterNr); + return eventDone; + } + + /// Stop this operation + public void Stop() + { + } + } +} diff --git a/TestBenchFramework/BenchControl/Keithley/TempMeter/TempMeter.cs b/TestBenchFramework/BenchControl/Keithley/TempMeter/TempMeter.cs new file mode 100644 index 000000000..ca29a21db --- /dev/null +++ b/TestBenchFramework/BenchControl/Keithley/TempMeter/TempMeter.cs @@ -0,0 +1,59 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +using System; +using System.Collections.Generic; +using log4net; +using TBF.Boxes; +using TBF.BenchControl.Keithley.RS232; + +namespace TBF.BenchControl.Keithley.TempMeter +{ + public class TempMeter : ComponentBase, GenericDevices.ITempMeter + { + private static readonly ILog log = LogManager.GetLogger(typeof(TempMeter)); + public override string ToString() { return string.Format("Keithley.TempMeter({0})", Cfg.ToString(1)); } + + readonly TempMeterCfg tempMtrCfg; /// configuration + + public readonly Multimeter Multimeter; /// parent component + + public int Idx0 { get { return tempMtrCfg.Idx0; } } /// 0..3 + + public TempMeter() + { + } + + public TempMeter(TempMeterCfg cfg, IList components) + : base(cfg) + { + tempMtrCfg = cfg; + + Multimeter = (Multimeter)TbfComponents.FindComponent(cfg.ParentName, components); + if (Multimeter == null) throw new Exception("Cannot find " + Name + " parent"); + + log.Debug(this.ToString()); + } + + /// + /// Events: TempDone, Error + /// + /// Reference to a variable for the temperature in Celsius + /// ReadTempOp instance reference casted to IOperaton + public IOperation ReadTempOp(ref FloatBox temp) + { + return new ReadTempOp(this, ref temp); + } + + /// + /// Events: tempDone, Error + /// + /// Reference to a variable for the temperature in Celsius + /// Event returned when measurement done + /// ReadTempOp instance reference casted to IOperaton + public IOperation ReadTempOp(ref FloatBox temp, Event tempDone) + { + return new ReadTempOp(this, ref temp, tempDone); + } + } +} diff --git a/TestBenchFramework/BenchControl/Keithley/TempMeter/TempMeterCfg.cs b/TestBenchFramework/BenchControl/Keithley/TempMeter/TempMeterCfg.cs new file mode 100644 index 000000000..553761d60 --- /dev/null +++ b/TestBenchFramework/BenchControl/Keithley/TempMeter/TempMeterCfg.cs @@ -0,0 +1,44 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +using System; +using System.Collections.Generic; +using System.IO; +using System.Xml.Serialization; +using TBF.BenchControl.Generic; + +namespace TBF.BenchControl.Keithley.TempMeter +{ + public class TempMeterCfg : ComponentCfgBase, IChildComponentCfg + { + public IComponent GetComponent(IList components) { return new TempMeter(this, components); } + public IComponentCfgCtrl GetControl() { return new TempMeterCfgCtrl(); } + + /// + /// Serialized parameters + /// + public int Idx0; /// 0..3 + + /// Private parameterless constructor invoked by all other (public) constructors + TempMeterCfg() + { + Name = "T"; + ParentName = "Keithley"; + Idx0 = 0; + } + + public TempMeterCfg(IComponentFactory factory) + : this() + { + this.Factory = factory; + } + + public string ToString(int i) + { + return string.Format("Name={0}, Parent={1}, Idx0={2}", + Name, + (string.IsNullOrEmpty(ParentName) ? "-" : ParentName), + Idx0); + } + } +} diff --git a/TestBenchFramework/BenchControl/Keithley/TempMeter/TempMeterCfgCtrl.Designer.cs b/TestBenchFramework/BenchControl/Keithley/TempMeter/TempMeterCfgCtrl.Designer.cs new file mode 100644 index 000000000..c4573c9ad --- /dev/null +++ b/TestBenchFramework/BenchControl/Keithley/TempMeter/TempMeterCfgCtrl.Designer.cs @@ -0,0 +1,133 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +namespace TBF.BenchControl.Keithley.TempMeter +{ + partial class TempMeterCfgCtrl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.positionTextBox = new System.Windows.Forms.TextBox(); + this.positionLabel = new System.Windows.Forms.Label(); + this.parentNameLabel = new System.Windows.Forms.Label(); + this.nameTextBox = new System.Windows.Forms.TextBox(); + this.nameLabel = new System.Windows.Forms.Label(); + this.classNameLabel = new System.Windows.Forms.Label(); + this.parentNameComboBox = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // positionTextBox + // + this.positionTextBox.Enabled = false; + this.positionTextBox.Location = new System.Drawing.Point(130, 82); + this.positionTextBox.Name = "positionTextBox"; + this.positionTextBox.Size = new System.Drawing.Size(46, 20); + this.positionTextBox.TabIndex = 6; + // + // positionLabel + // + this.positionLabel.AutoSize = true; + this.positionLabel.Location = new System.Drawing.Point(20, 85); + this.positionLabel.Name = "positionLabel"; + this.positionLabel.Size = new System.Drawing.Size(44, 13); + this.positionLabel.TabIndex = 5; + this.positionLabel.Text = "Position"; + // + // parentNameLabel + // + this.parentNameLabel.AutoSize = true; + this.parentNameLabel.Location = new System.Drawing.Point(20, 61); + this.parentNameLabel.Name = "parentNameLabel"; + this.parentNameLabel.Size = new System.Drawing.Size(69, 13); + this.parentNameLabel.TabIndex = 3; + this.parentNameLabel.Text = "Parent Name"; + // + // nameTextBox + // + this.nameTextBox.Enabled = false; + this.nameTextBox.Location = new System.Drawing.Point(130, 34); + this.nameTextBox.Name = "nameTextBox"; + this.nameTextBox.Size = new System.Drawing.Size(130, 20); + this.nameTextBox.TabIndex = 2; + // + // nameLabel + // + this.nameLabel.AutoSize = true; + this.nameLabel.Location = new System.Drawing.Point(20, 37); + this.nameLabel.Name = "nameLabel"; + this.nameLabel.Size = new System.Drawing.Size(35, 13); + this.nameLabel.TabIndex = 1; + this.nameLabel.Text = "Name"; + // + // classNameLabel + // + this.classNameLabel.AutoSize = true; + this.classNameLabel.Location = new System.Drawing.Point(127, 10); + this.classNameLabel.Name = "classNameLabel"; + this.classNameLabel.Size = new System.Drawing.Size(83, 13); + this.classNameLabel.TabIndex = 0; + this.classNameLabel.Text = "ComonentName"; + // + // parentNameComboBox + // + this.parentNameComboBox.Enabled = false; + this.parentNameComboBox.FormattingEnabled = true; + this.parentNameComboBox.Location = new System.Drawing.Point(130, 58); + this.parentNameComboBox.Name = "parentNameComboBox"; + this.parentNameComboBox.Size = new System.Drawing.Size(130, 21); + this.parentNameComboBox.TabIndex = 4; + // + // TempMeterCfgCtrl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.parentNameComboBox); + this.Controls.Add(this.positionTextBox); + this.Controls.Add(this.positionLabel); + this.Controls.Add(this.parentNameLabel); + this.Controls.Add(this.nameTextBox); + this.Controls.Add(this.nameLabel); + this.Controls.Add(this.classNameLabel); + this.Name = "TempMeterCfgCtrl"; + this.Size = new System.Drawing.Size(300, 240); + this.Load += new System.EventHandler(this.TempMeterCfgCtrl_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox positionTextBox; + private System.Windows.Forms.Label positionLabel; + private System.Windows.Forms.Label parentNameLabel; + private System.Windows.Forms.TextBox nameTextBox; + private System.Windows.Forms.Label nameLabel; + private System.Windows.Forms.Label classNameLabel; + private System.Windows.Forms.ComboBox parentNameComboBox; + } +} diff --git a/TestBenchFramework/BenchControl/Keithley/TempMeter/TempMeterCfgCtrl.cs b/TestBenchFramework/BenchControl/Keithley/TempMeter/TempMeterCfgCtrl.cs new file mode 100644 index 000000000..6d94aeb54 --- /dev/null +++ b/TestBenchFramework/BenchControl/Keithley/TempMeter/TempMeterCfgCtrl.cs @@ -0,0 +1,108 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +using System; +using System.Globalization; +using System.Windows.Forms; +using log4net; +using TBF.BenchControl.Generic; + +namespace TBF.BenchControl.Keithley.TempMeter +{ + public partial class TempMeterCfgCtrl : UserControl, IComponentCfgCtrl + { + static readonly ILog log = LogManager.GetLogger(typeof(TempMeterCfgCtrl)); + + ComponentParametersDlg parent; + + public bool ShowMore { get { return false; } } + + TempMeterCfg config; + public IComponentCfg Config + { + get { return config as IComponentCfg; } + set + { + config = value as TempMeterCfg; + Redraw(); + } + } + + public TempMeterCfgCtrl() + { + InitializeComponent(); + } + + private void TempMeterCfgCtrl_Load(object sender, EventArgs e) + { + parent = ParentForm as ComponentParametersDlg; + if (parent == null) return; + + if (parent.TbfComponents != null) + { + foreach (var cmpnt in parent.TbfComponents) + { + if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is Keithley.RS232.Factory) + { + parentNameComboBox.Items.Add(cmpnt.Name); + } + } + } + + Redraw(); + } + + public void Closing() + { + } + + void Redraw() + { + if (config == null) return; /// Control was not loaded, settings were not changed + + classNameLabel.Text = config.Factory.ClassName; + nameTextBox.Text = config.Name; + parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName; + positionTextBox.Text = config.Idx0.ToString(); + } + + public void Unlock() + { + nameTextBox.Enabled = true; + parentNameComboBox.Enabled = true; + positionTextBox.Enabled = true; + } + + public CfgUpdateFlags VerifyCfg(ref string message) + { + CfgUpdateFlags flags = CfgUpdateFlags.None; + + int dummy; + if (!parentNameComboBox.Items.Contains(parentNameComboBox.Text)) + { + flags |= CfgUpdateFlags.Error; + message += Environment.NewLine + "Invalid 'Parent Name'"; + } + if (!int.TryParse(positionTextBox.Text, out dummy) || dummy < 0 || dummy > 7) + { + flags |= CfgUpdateFlags.Error; + message += Environment.NewLine + "'Position' should be between 0 and 7"; + } + + return flags; + } + + public CfgUpdateFlags UpdateCfg() + { + CfgUpdateFlags flags = CfgUpdateFlags.RestartRqrd; + + if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed + + config.Name = nameTextBox.Text; + config.ParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text; + config.Idx0 = int.Parse(positionTextBox.Text); + + return flags; + } + } +} diff --git a/TestBenchFramework/BenchControl/Keithley/TempMeter/TempMeterCfgCtrl.resx b/TestBenchFramework/BenchControl/Keithley/TempMeter/TempMeterCfgCtrl.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/TestBenchFramework/BenchControl/Keithley/TempMeter/TempMeterCfgCtrl.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TestBenchFramework/BenchControl/TbfComponents.cs b/TestBenchFramework/BenchControl/TbfComponents.cs index 3073ead06..322f44190 100644 --- a/TestBenchFramework/BenchControl/TbfComponents.cs +++ b/TestBenchFramework/BenchControl/TbfComponents.cs @@ -46,7 +46,9 @@ namespace TBF.BenchControl Factories.Add(new Cameras.IdcCamera.IdcCameraFactory()); Factories.Add(new WaterMeters.iPerl.WaterMeterFactory()); /// iPerl Factories.Add(new TestMethods.iPerlCommunication.TestMethodFactory()); /// iPerlCommunication - Factories.Add(new ResultsPrinters.LabelPrinter.PrinterFactory()); /// LabelPrinter + Factories.Add(new Keithley.RS232.Factory()); /// Keithley.RS232.Multimeter + Factories.Add(new Keithley.TempMeter.Factory()); /// Keithley.TempMeter + Factories.Add(new ResultsPrinters.LabelPrinter.PrinterFactory()); /// LabelPrinter Factories.Add(new TestMethods.LeakTest.TestMethodFactory()); Factories.Add(new MettlerToledo.Standard.BalanceFactory()); /// MettlerToledo Balance Factories.Add(new MettlerToledo.Standard.BalanceOldFactory()); /// MettlerToledoBalanceOld @@ -56,7 +58,7 @@ namespace TBF.BenchControl Factories.Add(new Output.FileWriters.Basic.FactorySingle()); /// Output.FileWriters.Basic.Single Factories.Add(new Output.FileWriters.Basic.FactoryCompound()); /// Output.FileWriters.Basic.Compound Factories.Add(new Output.FileWriters.Enhanced.FactorySingle()); /// Output.FileWriters.Basic.Single - Factories.Add(new Output.FileWriters.Enhanced.FactoryCompound()); /// Output.FileWriters.Basic.Compound + Factories.Add(new Output.FileWriters.Enhanced.FactoryCompound()); /// Output.FileWriters.Basic.Compound Factories.Add(new TestMethods.PMaxTest.TestMethodFactory()); Factories.Add(new Elde.PressureMeter.PressureMeterFactory()); Factories.Add(new Elde.PressureMeterInternal.PressureMeterFactory()); diff --git a/TestBenchFramework/Properties/AssemblyInfo.cs b/TestBenchFramework/Properties/AssemblyInfo.cs index 01cb31a05..57ba4f1a8 100644 --- a/TestBenchFramework/Properties/AssemblyInfo.cs +++ b/TestBenchFramework/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("2.8.312.1")] -[assembly: AssemblyFileVersion("2.8.312.1")] +[assembly: AssemblyVersion("2.8.313.1")] +[assembly: AssemblyFileVersion("2.8.313.1")] diff --git a/TestBenchFramework/TBF.csproj b/TestBenchFramework/TBF.csproj index dff5a0e61..1d777cee1 100644 --- a/TestBenchFramework/TBF.csproj +++ b/TestBenchFramework/TBF.csproj @@ -341,6 +341,25 @@ + + + + + UserControl + + + MultimeterCfgCtrl.cs + + + + + + UserControl + + + TempMeterCfgCtrl.cs + + @@ -1610,6 +1629,12 @@ ValveCfgCtrl.cs + + MultimeterCfgCtrl.cs + + + TempMeterCfgCtrl.cs + BalanceCfgCtrl.cs