diff --git a/TODO.txt b/TODO.txt index 8d2707395..1401f2f5c 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,4 +1,5 @@ iPerl: +- OptoTelegram parsing, odkial prat MeterType? - STOP nefunguje pocas communikacie - na Process obrazovke posunut stupacku a rezervoar uplne doprava diff --git a/TestBenchFramework/BenchControl/TestMethods/iPerlCommunication/TestMethod.cs b/TestBenchFramework/BenchControl/TestMethods/iPerlCommunication/TestMethod.cs index fcddebb1a..52f75746f 100644 --- a/TestBenchFramework/BenchControl/TestMethods/iPerlCommunication/TestMethod.cs +++ b/TestBenchFramework/BenchControl/TestMethods/iPerlCommunication/TestMethod.cs @@ -9,10 +9,12 @@ using TBF.BenchControl; namespace TBF.BenchControl.TestMethods.iPerlCommunication { - public class TestMethod : ComponentBase, GenericDevices.ITestMethod + public class TestMethod : ComponentBase, GenericDevices.ITestMethod, Generic.IDevice { private static readonly ILog log = LogManager.GetLogger(typeof(TestMethod)); - public override string ToString() { return string.Format("TestMethods.Adjustment({0})", Cfg.ToString(1)); } + protected static readonly ILog rfidDataLogger = LogManager.GetLogger("RfidData"); + + public override string ToString() { return string.Format("TestMethods.Adjustment({0})", Cfg.ToString(1)); } readonly TestMethodCfg testMethodCfg; @@ -31,6 +33,16 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication log.Debug(this.ToString()); } + public void Initialize() + { + rfidDataLogger.Fatal("------------------------------------------------------------------------"); + rfidDataLogger.Fatal("Program restarted"); + } + + public void RunDeviceBefore() { } + public void RunDeviceAfter() { } + public void StopDevice() { } + public IList Execute(Entities.Test test) { return (new iPerlCommunicationSeq()).Execute(test, testMethodCfg.TestParams); diff --git a/TestBenchFramework/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs b/TestBenchFramework/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs index 3928af744..a2c539f5f 100644 --- a/TestBenchFramework/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs +++ b/TestBenchFramework/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs @@ -18,6 +18,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication public partial class iPerlCommunicationForm : Form, GenericDevices.IHasCompleted { private static readonly ILog log = LogManager.GetLogger(typeof(iPerlCommunicationForm)); + protected static readonly ILog rfidDataLogger = LogManager.GetLogger("RfidData"); #region DLL_Interface @@ -36,8 +37,20 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication [DllImport("libRfid.dll", EntryPoint = "writeRequestPort")] static extern unsafe int writeRequestPort(MessageID messageId, int offset, int lenght, byte* ptr, int timeout_ms); + static int currentPort; + + /// + /// Wrapper function with safe interface and unsafe body + /// + /// Value returned by openPort(...) + public static unsafe int OpenPort(int comPort) + { + currentPort = comPort; + return openPort(comPort); + } + /// - /// Wrapper function with safe interface adn unsafe body + /// Wrapper function with safe interface and unsafe body /// /// Value returned by readRequestPort(...) public static unsafe int ReadRequestPort(MessageID messageID, int offset, int lenght, out byte[] buffer, int timeout) @@ -48,6 +61,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication fixed (byte* pBuf = buf) { retv = readRequestPort(messageID, offset, lenght, pBuf, timeout); + rfidDataLogger.InfoFormat("Group={0}, Port={1}, ReadRequestPort({2}, {3}, {4}, ...) returned {5} {6}", currentGroup, currentPort, messageID, offset, lenght, retv, (retv != 0) ? "!" : ""); buffer = new byte[lenght]; for (int i = 0; i < lenght; i++) buffer[i] = buf[i]; @@ -66,7 +80,19 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication fixed (byte* pBuf = buffer) { retv = writeRequestPort(messageID, offset, lenght, pBuf, timeout); - } + if (lenght == 1) + { + rfidDataLogger.InfoFormat("Group={0}, Port={1}, WriteRequestPort({3}, {4}, {5}, {6}) returned {2} {7}", currentGroup, currentPort, retv, messageID, offset, lenght, pBuf[0].ToString("X2"), (retv != 0) ? "!" : ""); + } + else if (lenght == 2) + { + rfidDataLogger.InfoFormat("Group={0}, Port={1}, WriteRequestPort({3}, {4}, {5}, {6} {7}) returned {2} {8}", currentGroup, currentPort, retv, messageID, offset, lenght, pBuf[0].ToString("X2"), pBuf[1].ToString("X2"), (retv != 0) ? "!" : ""); + } + else + { + rfidDataLogger.InfoFormat("Group={0}, Port={1}, WriteRequestPort({3}, {4}, {5}, {6} {7} ...) returned {2} {8}", currentGroup, currentPort, retv, messageID, offset, lenght, pBuf[0].ToString("X2"), pBuf[1].ToString("X2"), (retv != 0) ? "!" : ""); + } + } return retv; } @@ -387,6 +413,10 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication { int threadId = (threadData as Boxes.IntBox).Val; + rfidDataLogger.InfoFormat(""); /// Makes the log more readable when there is a lot of data + rfidDataLogger.WarnFormat("Activity = {0}", activity); + rfidDataLogger.InfoFormat(""); /// Makes the log more readable when there is a lot of data + for (int group = 1; group <= lastGroup; group++) { while (currentGroup != group && !stopWorkerThreads[threadId]) Thread.Sleep(50); @@ -426,8 +456,9 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication else if (wm.Disabled) OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, "Watermeter is disabled")); else { - OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, "Cannot " + activity)); - wm.Disabled = true; + OnCommCompleted(null, new CommCompletedEventArgs(threadId, wmNr, activity + " failed !!!")); + rfidDataLogger.ErrorFormat("Group={0}, Port={1}, {2} failed !!!", currentGroup, currentPort, activity); + wm.Disabled = true; } } else @@ -464,7 +495,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication if (wm.Disabled) return false; - if (openPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port + if (OpenPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port bool success = false; @@ -519,7 +550,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication } /// Communication necessary - if (openPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port + if (OpenPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port bool success = true; @@ -596,7 +627,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication { if (wm.Disabled) return false; - if (openPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port + if (OpenPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port bool success = false; @@ -641,7 +672,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication { if (wm.Disabled) return false; - if (openPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port + if (OpenPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port bool success = false; @@ -675,7 +706,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication { if (wm.Disabled) return false; - if (openPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port + if (OpenPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port bool success = false; @@ -727,7 +758,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication { if (wm.Disabled) return false; - if (openPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port + if (OpenPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port bool success = false; @@ -776,7 +807,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication { if (wm.Disabled) return false; - if (openPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port + if (OpenPort(wm.RfidComPortNr) != 0) return false; /// Open RFID port bool success = false; diff --git a/TestBenchFramework/BenchControl/WaterMeters/iPerl/OptoTelegram.cs b/TestBenchFramework/BenchControl/WaterMeters/iPerl/OptoTelegram.cs new file mode 100644 index 000000000..12ba75435 --- /dev/null +++ b/TestBenchFramework/BenchControl/WaterMeters/iPerl/OptoTelegram.cs @@ -0,0 +1,150 @@ +using System; +using System.Globalization; + +namespace TBF.BenchControl.WaterMeters.iPerl +{ + public class OptoTelegram + { + public static readonly int Length = 42; + + public double EMF; + public Int16 MagneticField; + public double Flow; + public double Volume; + public Int16 Impedance; + public UInt32 Timestamp; + public byte GG; + + string sourceStr; + + + public OptoTelegram() + { + } + + public override string ToString() + { + return sourceStr; + } + + /// + /// Create a configuration structure from a complete byte array + /// + /// Telegram description: + /// + /// AAAAAA[tab]BBBB[tab]CCCC[tab]DDDDDD[tab]EEEE[tab]FFFFFFFF[tab]GG[cr][lf] (42 bytes) + /// + /// Data Comment Type Calculate to decimal + /// ---------------------------------------------------------------- + /// AAAAAA EMF Int24 Value * 0.000000333 + /// BBBB Magnetic field Int16 Value + /// CCCC Flow Int16 Value * 0.225 * Scalig factor + /// DDDDDD Volume Int24 Value / 16000 * Scaling factor + /// EEEE Impedance Int16 Value + /// FFFFFFFF Timestamp Uint32 Value / 8192 + /// GG + /// ---------------------------------------------------------------- + /// + /// Example: + /// FFFFFE 51EA 0000 65324E 0087 F6319DFF 86 + /// FFDD3A 51F9 0000 65324E 0088 F631A60B 45 + /// ... + /// + /// A complete byte array data + /// ConfigStruct or null when byte array was not complete + public static OptoTelegram FromString(string telegram, MeterType meterType) + { + if ((telegram == null) || (telegram.Length < Length) || + (telegram[6] != '\t') || (telegram[11] != '\t') || + (telegram[16] != '\t') || (telegram[23] != '\t') || + (telegram[28] != '\t') || (telegram[37] != '\t') || + (telegram[40] != '\r') || (telegram[41] != '\n')) + { + return null; + } + + OptoTelegram opto = new OptoTelegram(); + + Int32 value; + if (Int32.TryParse(telegram.Substring(0, 6), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out value)) + { + Int32 svalue = (value >= 0x00800000) ? (value - 0x01000000) : value; + opto.EMF = 0.000000333 * (double)svalue; + } + else return null; + + if (Int32.TryParse(telegram.Substring(7, 4), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out value)) + { + Int32 svalue = (value >= 0x00008000) ? (value - 0x00010000) : value; + opto.MagneticField = (Int16)svalue; + } + else return null; + + double factor = ScalingFactor(meterType); + + if (Int32.TryParse(telegram.Substring(12, 4), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out value)) + { + Int32 svalue = (value >= 0x00008000) ? (value - 0x00010000) : value; + opto.Flow = 0.225 * (double)svalue * factor; + } + else return null; + + if (Int32.TryParse(telegram.Substring(17, 6), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out value)) + { + Int32 svalue = (value >= 0x00800000) ? (value - 0x01000000) : value; + opto.Volume = (double)svalue / 16000.0 * factor; + } + else return null; + + if (Int32.TryParse(telegram.Substring(24, 4), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out value)) + { + Int32 svalue = (value >= 0x00008000) ? (value - 0x00010000) : value; + opto.Impedance = (Int16)svalue; + } + else return null; + + UInt32 uvalue; + if (UInt32.TryParse(telegram.Substring(29, 8), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out uvalue)) + { + opto.Timestamp = uvalue; + } + else return null; + + if (UInt32.TryParse(telegram.Substring(38, 2), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out uvalue)) + { + opto.GG = (byte)uvalue; + } + else return null; + + opto.sourceStr = telegram.Substring(0, Length - 2); + + return opto; + } + + + /// + /// Scaling factor: + /// 0, 1 (DN15, Coax) . . . . 1 + /// 2 (DN20) . . . . . . . . 2 + /// 3 (DN25) . . . . . . . . 4 + /// 4, 5 (DN26, DN32) . . . . 8 + /// 6 (DN40) . . . . . . . . 16 + /// + /// MeterType (0..6) + /// Scaling factor + public static double ScalingFactor(MeterType meterType) + { + switch (meterType) + { + default: + case MeterType.DN15: + case MeterType.CoaxManifold: return 1.0; + case MeterType.DN20: return 2.0; + case MeterType.DN25: return 4.0; + case MeterType.DN26: + case MeterType.DN32: return 8.0; + case MeterType.DN40: return 16.0; + } + } + } +} diff --git a/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeter.cs b/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeter.cs index 2d209ef3f..9fab4c39a 100644 --- a/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeter.cs +++ b/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeter.cs @@ -18,7 +18,8 @@ namespace TBF.BenchControl.WaterMeters.iPerl public class WaterMeter : ComponentBase, IDevice, GenericDevices.IWaterMeter, GenericDevices.IRegisterReader, IOperation { private static readonly ILog log = LogManager.GetLogger(typeof(WaterMeter)); - public override string ToString() { return string.Format("iPerl({0})", Cfg.ToString(1)); } + protected static readonly ILog optoDataLogger = LogManager.GetLogger("OptoData"); + public override string ToString() { return string.Format("iPerl({0})", Cfg.ToString(1)); } readonly WaterMeterCfg iPerlCfg; @@ -69,10 +70,30 @@ namespace TBF.BenchControl.WaterMeters.iPerl bool disabled; /// ConfigStruct of the water meter obtained or updated by iPerlCommunication - public ConfigStruct ConfigStruct; + public ConfigStruct ConfigStruct + { + get { return configStruct; } + set { configStruct = value; } + } + ConfigStruct configStruct; /// CalibrationStruct of the water meter obtained or updated by iPerlCommunication - public CalibrationStruct CalibrationStruct; + public CalibrationStruct CalibrationStruct + { + get { return calibrationStruct; } + set + { + calibrationStruct = value; + switch (calibrationStruct.VolumeUnits) + { + default: + case VolumeUnits.m3: volumeUnit = 1000.0; break; /// liter per m3 + case VolumeUnits.US_gallon: volumeUnit = 3.785; break; /// liter per US gallon + case VolumeUnits.UK_gallon: volumeUnit = 4.54609; break; /// liter per UK gallon + } + } + } + CalibrationStruct calibrationStruct; public ushort CalibrationFactor { get { return CalibrationStruct.Calibration; } } @@ -86,21 +107,37 @@ namespace TBF.BenchControl.WaterMeters.iPerl } - Boxes.IntBox pulses; - Boxes.IntBox refPulses; + /// + /// Volume of water in liter set by OptoTelegramRreceived(...) + /// + private double volumeLtr; + + /// + /// Volume of one water meter unit in liter. Set when reading the configuration. + /// + private double volumeUnit; + + private Boxes.IntBox pulses; + private Boxes.IntBox refPulses; /// /// Opto serial port and worker thread related private variables /// private SerialPort optoSerialPort; - private bool optoPortOpen; + +#if USE_SEPARATE_WORKER_THREAD private Thread workerThread; private bool stopWorkerThread; - - - public WaterMeter() +#endif + + + public WaterMeter() { + synchronized = false; + synchronized2 = false; + partOfTelegram = string.Empty; + volumeUnit = 1000.0; /// liter / m3 } public WaterMeter(WaterMeterCfg cfg) @@ -110,26 +147,38 @@ namespace TBF.BenchControl.WaterMeters.iPerl log.Debug(this.ToString()); } + static bool initOnceDone; public void Initialize() { if (DebugLevel == Entities.DebugMode.Normal) { + if (!initOnceDone) + { + initOnceDone = true; + optoDataLogger.Fatal("------------------------------------------------------------------------"); + optoDataLogger.Fatal("Program restarted"); + } + optoSerialPort = new SerialPort(string.Format("COM{0}", iPerlCfg.OptoComPortNr), 9600, Parity.None, 8, StopBits.One); optoSerialPort.Handshake = Handshake.None; optoSerialPort.Open(); - optoPortOpen = true; +#if USE_SEPARATE_WORKER_THREAD stopWorkerThread = false; workerThread = new Thread(Worker); workerThread.Start(); +#endif } } public void RunDeviceBefore() { - } +#if !USE_SEPARATE_WORKER_THREAD + ReadOptoSerialPort(); +#endif + } public void RunDeviceAfter() { @@ -139,12 +188,13 @@ namespace TBF.BenchControl.WaterMeters.iPerl { if (DebugLevel == Entities.DebugMode.Normal) { +#if USE_SEPARATE_WORKER_THREAD stopWorkerThread = true; workerThread.Join(2000); - optoSerialPort.Close(); - optoPortOpen = false; - } - } +#endif + optoSerialPort.Close(); + } + } /// /// Events: Event.ReadRegisterDone, Event.Error @@ -205,33 +255,108 @@ namespace TBF.BenchControl.WaterMeters.iPerl void ReadPulses() { - /// Do something meaningfull here - pulses.Val = 1; - refPulses.Val = 2; + pulses.Val = (int)(volumeLtr / (double)PulsesPerLtr + 0.5); + refPulses.Val = 2; /// Do something meaningfull here } +#if USE_SEPARATE_WORKER_THREAD void Worker() { while (!stopWorkerThread) { Thread.Sleep(250); if (stopWorkerThread) break; - int nrBytes = optoSerialPort.BytesToRead; - if (nrBytes > 0) - { - char[] buffer = new char[nrBytes]; - optoSerialPort.Read(buffer, 0, nrBytes); - string s = new string(buffer); - OnOptoReceived(this, new OptoReceivedEventArgs(s)); - } - else - { - //OnOptoReceived(this, new OptoReceivedEventArgs(".")); - } + ReadOptoSerialPort(); } } +#endif + bool synchronized; + bool synchronized2; + string partOfTelegram; + + /// + /// 9600 Bd, 8 data bits, 1 stop bit, no parity + /// + /// Telegram description: + /// + /// AAAAAA[tab]BBBB[tab]CCCC[tab]DDDDDD[tab]EEEE[tab]FFFFFFFF[tab]GG[cr][lf] (42 bytes) + /// + /// Example: + /// FFFFFE 51EA 0000 65324E 0087 F6319DFF 86 + /// FFDD3A 51F9 0000 65324E 0088 F631A60B 45 + /// ... + /// + void ReadOptoSerialPort() + { + if (DebugLevel == Entities.DebugMode.Normal || DebugLevel == Entities.DebugMode.Record) + { + 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; + + OptoTelegram opto; + while (true) + { + 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) + { + optoDataLogger.ErrorFormat("{0}: Opto data syncronisation error", Name); + } + synchronized = true; + } + // CR+LF found and (pos >= OptoTelegram.Length - 2) + else if ((null != (opto = OptoTelegram.FromString(allRcvd.Substring(pos - OptoTelegram.Length + 2), iPerlCfg.MeterType)))) + { + OptoTelegramRreceived(opto, synchronized2); + synchronized2 = synchronized; + allRcvd = allRcvd.Substring(pos + 2); + } + else + { + optoDataLogger.ErrorFormat("{0}: Wrong format of opto data", Name); + allRcvd = allRcvd.Substring(pos + 2); + } + } + + //OnOptoReceived(this, new OptoReceivedEventArgs(s)); + } + else + { + //OnOptoReceived(this, new OptoReceivedEventArgs(".")); + } + } + else if (DebugLevel == Entities.DebugMode.Simulate) + { + } + else if (DebugLevel == Entities.DebugMode.Reply) + { + } + } + + void OptoTelegramRreceived(OptoTelegram optoTelegram, bool async) + { + volumeLtr = optoTelegram.Volume * volumeUnit; + optoDataLogger.InfoFormat("{0}: {1}", Name, optoTelegram); + } /// /// Called from the state machine when a test is selected and UI needs to be updated. diff --git a/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeterCfg.cs b/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeterCfg.cs index 261ee1822..59014c9de 100644 --- a/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeterCfg.cs +++ b/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeterCfg.cs @@ -19,6 +19,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl /// /// Serialized parameters /// + public MeterType MeterType; public int OptoComPortNr; public int RfidComPortNr; public int Group; /// Number written to QuidoRS to connct the watermeter to RfidComPort diff --git a/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeterCfgCtrl.cs b/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeterCfgCtrl.cs index 0d52d74c5..5c75cd036 100644 --- a/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeterCfgCtrl.cs +++ b/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeterCfgCtrl.cs @@ -35,6 +35,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl private void WaterMeterCfgCtrl_Load(object sender, EventArgs e) { nameLabel.Text = Strings.Name; + for (byte i = 0; i < (byte)MeterType.Count; i++) meterTypeComboBox.Items.Add(((MeterType)i).ToString()); Redraw(); } @@ -47,6 +48,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl if (config == null) return; /// Control was not loaded, settings were not changed classNameLabel.Text = config.Factory.ClassName; nameTextBox.Text = config.Name; + meterTypeComboBox.Text = config.MeterType.ToString(); optoPortNrTextBox.Text = config.OptoComPortNr.ToString(); rfidPortNrTextBox.Text = config.RfidComPortNr.ToString(); groupTextBox.Text = config.Group.ToString(); @@ -55,6 +57,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl public void Unlock() { nameTextBox.Enabled = true; + meterTypeComboBox.Enabled = true; optoPortNrTextBox.Enabled = true; rfidPortNrTextBox.Enabled = true; groupTextBox.Enabled = true; @@ -64,6 +67,12 @@ namespace TBF.BenchControl.WaterMeters.iPerl { CfgUpdateFlags flags = CfgUpdateFlags.None; + if (!meterTypeComboBox.Items.Contains(meterTypeComboBox.Text)) + { + flags |= CfgUpdateFlags.Error; + message += Environment.NewLine + "Meter type is not valid"; + } + int dummy; if (!int.TryParse(optoPortNrTextBox.Text, out dummy) || dummy < 1 || dummy > 999) { @@ -91,6 +100,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed config.Name = nameTextBox.Text; + config.MeterType = (MeterType)meterTypeComboBox.SelectedIndex; config.OptoComPortNr = int.Parse(optoPortNrTextBox.Text); config.RfidComPortNr = int.Parse(rfidPortNrTextBox.Text); config.Group = int.Parse(groupTextBox.Text); diff --git a/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeterCfgCtrl.designer.cs b/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeterCfgCtrl.designer.cs index e6947b62a..349c29b46 100644 --- a/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeterCfgCtrl.designer.cs +++ b/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeterCfgCtrl.designer.cs @@ -32,112 +32,134 @@ namespace TBF.BenchControl.WaterMeters.iPerl /// 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.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(130, 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, 79); - 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, 82); - 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, 103); - 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, 106); - 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, 127); - 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, 130); - this.groupLabel.Name = "groupLabel"; - this.groupLabel.Size = new System.Drawing.Size(39, 13); - this.groupLabel.TabIndex = 10; - this.groupLabel.Text = "Group:"; - // - // WaterMeterCfgCtrl - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - 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.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(); } @@ -152,5 +174,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl private System.Windows.Forms.Label rfidPortNrLabel; private System.Windows.Forms.TextBox groupTextBox; private System.Windows.Forms.Label groupLabel; + private System.Windows.Forms.Label meterTypeLabel; + private System.Windows.Forms.ComboBox meterTypeComboBox; } } diff --git a/TestBenchFramework/SampleConfig/log4netConfig.xml b/TestBenchFramework/SampleConfig/log4netConfig.xml index 3180f4e9f..35a71b025 100644 --- a/TestBenchFramework/SampleConfig/log4netConfig.xml +++ b/TestBenchFramework/SampleConfig/log4netConfig.xml @@ -6,24 +6,34 @@ - - + + + + - + - - + + - + + + + + + + + + - + @@ -31,7 +41,7 @@ - + @@ -39,20 +49,40 @@ + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + @@ -60,8 +90,16 @@ - - - + + + + + + + + + + + diff --git a/TestBenchFramework/TBF.csproj b/TestBenchFramework/TBF.csproj index 02526f8b8..8c0236262 100644 --- a/TestBenchFramework/TBF.csproj +++ b/TestBenchFramework/TBF.csproj @@ -358,6 +358,7 @@ +