diff --git a/DeviceTest/DeviceTestDlg.cs b/DeviceTest/DeviceTestDlg.cs index bfabc37c0..ce815774e 100644 --- a/DeviceTest/DeviceTestDlg.cs +++ b/DeviceTest/DeviceTestDlg.cs @@ -276,7 +276,14 @@ namespace DeviceTest radioButton3.Text = "SelectTank 3"; radioButton4.Text = "SelectTank -"; } - else radioButton1.Text = "spare"; + else if (className == "Modbus.QuidoRS") + { + radioButton1.Text = "Close relay 1"; + radioButton2.Text = "Close relay 2"; + radioButton3.Text = "Close relay 3"; + radioButton4.Text = "Open all relays"; + } + else radioButton1.Text = "spare"; } /// void UpdateOperations2(string className) @@ -296,7 +303,14 @@ namespace DeviceTest radioButton23.Text = "SelectTank 3"; radioButton24.Text = "SelectTank -"; } - else radioButton21.Text = "spare"; + else if (className == "Modbus.QuidoRS") + { + radioButton21.Text = "Close relay 1"; + radioButton22.Text = "Close relay 2"; + radioButton23.Text = "Close relay 3"; + radioButton24.Text = "Open all relays"; + } + else radioButton21.Text = "spare"; } /// void UpdateOperations3(string className) @@ -316,7 +330,14 @@ namespace DeviceTest radioButton33.Text = "SelectTank 3"; radioButton34.Text = "SelectTank -"; } - else radioButton31.Text = "spare"; + else if (className == "Modbus.QuidoRS") + { + radioButton31.Text = "Close relay 1"; + radioButton32.Text = "Close relay 2"; + radioButton33.Text = "Close relay 3"; + radioButton34.Text = "Open all relays"; + } + else radioButton31.Text = "spare"; } @@ -672,6 +693,13 @@ namespace DeviceTest //operation3 = (tbfComponent1forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(3); //operation4 = (tbfComponent1forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(0); } + else if (tbfComponent3forOp is TBF.BenchControl.Modbus.TankSelector.TankSelector) + { + operation1 = (tbfComponent3forOp as TBF.BenchControl.Modbus.QuidoRS.QuidoRS).SetOutputsOp(1); + operation2 = (tbfComponent3forOp as TBF.BenchControl.Modbus.QuidoRS.QuidoRS).SetOutputsOp(2); + operation3 = (tbfComponent3forOp as TBF.BenchControl.Modbus.QuidoRS.QuidoRS).SetOutputsOp(4); + operation4 = (tbfComponent3forOp as TBF.BenchControl.Modbus.QuidoRS.QuidoRS).SetOutputsOp(0); + } if (tbfComponent2forOp is TBF.BenchControl.Modbus.PressureMeter.Meret.PressureMeter) @@ -704,6 +732,13 @@ namespace DeviceTest //operation23 = (tbfComponent2forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(3); //operation24 = (tbfComponent2forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(0); } + else if (tbfComponent3forOp is TBF.BenchControl.Modbus.TankSelector.TankSelector) + { + operation21 = (tbfComponent3forOp as TBF.BenchControl.Modbus.QuidoRS.QuidoRS).SetOutputsOp(1); + operation22 = (tbfComponent3forOp as TBF.BenchControl.Modbus.QuidoRS.QuidoRS).SetOutputsOp(2); + operation23 = (tbfComponent3forOp as TBF.BenchControl.Modbus.QuidoRS.QuidoRS).SetOutputsOp(4); + operation24 = (tbfComponent3forOp as TBF.BenchControl.Modbus.QuidoRS.QuidoRS).SetOutputsOp(0); + } if (tbfComponent3forOp is TBF.BenchControl.Modbus.PressureMeter.Meret.PressureMeter) @@ -736,6 +771,13 @@ namespace DeviceTest //operation33 = (tbfComponent3forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(3); //operation34 = (tbfComponent3forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(0); } + else if (tbfComponent3forOp is TBF.BenchControl.Modbus.TankSelector.TankSelector) + { + operation31 = (tbfComponent3forOp as TBF.BenchControl.Modbus.QuidoRS.QuidoRS).SetOutputsOp(1); + operation32 = (tbfComponent3forOp as TBF.BenchControl.Modbus.QuidoRS.QuidoRS).SetOutputsOp(2); + operation33 = (tbfComponent3forOp as TBF.BenchControl.Modbus.QuidoRS.QuidoRS).SetOutputsOp(4); + operation34 = (tbfComponent3forOp as TBF.BenchControl.Modbus.QuidoRS.QuidoRS).SetOutputsOp(0); + } int time = 0; diff --git a/TBF/BenchControl/GenericDevices/IParallelOutput.cs b/TBF/BenchControl/GenericDevices/IParallelOutput.cs new file mode 100644 index 000000000..1ab398ebe --- /dev/null +++ b/TBF/BenchControl/GenericDevices/IParallelOutput.cs @@ -0,0 +1,15 @@ +/// +/// Copyright (c) 2019 Sensus Slovensko a.s. +/// +using System; +using TBF.BenchControl.Generic; + +namespace TBF.BenchControl.GenericDevices +{ + public interface IParallelOutput : IComponent + { + IOperation SetOutputsOp(ushort outValue); + IOperation ShowBenchWaitingOp(); + IOperation ShowBenchErrorOp(); + } +} diff --git a/TBF/BenchControl/Modbus/Common/Modbus.cs b/TBF/BenchControl/Modbus/Common/Modbus.cs index ff119a141..0c80feba5 100644 --- a/TBF/BenchControl/Modbus/Common/Modbus.cs +++ b/TBF/BenchControl/Modbus/Common/Modbus.cs @@ -28,6 +28,7 @@ namespace TBF.BenchControl.Modbus.Common /// Private fields SerialPort serialPort; DateTime lastSerialPortWrite; + bool initialRunDeviceCommComplete; public Queue[] ReceivedTelegrams { @@ -82,6 +83,8 @@ namespace TBF.BenchControl.Modbus.Common //workerThread = new Thread(Worker); //workerThread.Start(); + initialRunDeviceCommComplete = false; /// Causes search for Quido RS modules in the first RunDeviceAfter() call + log.FatalFormat("{0} - Device successfully initialized", Name); } @@ -99,7 +102,7 @@ namespace TBF.BenchControl.Modbus.Common Telegram.UpdateTelegramCRC(message); - if ((DateTime.Now - lastSerialPortWrite) > new TimeSpan(0, 0, 0, 0, 100)) + if ((DateTime.Now - lastSerialPortWrite) > new TimeSpan(0, 0, 0, 0, 100) && initialRunDeviceCommComplete) { /// More then 100 ms since last 'send' --> do not enqueue the message SendMessageNow(message); @@ -174,12 +177,12 @@ namespace TBF.BenchControl.Modbus.Common Debug.WriteLine(s); log.Debug(s); } - else - { - string s = Telegram.LogTelegram(string.Format("{0} - Invalid data received ", Name), buffer); - Debug.WriteLine(s); - log.Debug(s); - } + else + { + string s = Telegram.LogTelegram(string.Format("{0} - Invalid data received ", Name), buffer); + Debug.WriteLine(s); + log.Debug(s); + } } } @@ -188,6 +191,16 @@ namespace TBF.BenchControl.Modbus.Common { if (serialPort == null) return; + if (!initialRunDeviceCommComplete) + { + initialRunDeviceCommComplete = true; /// Prevent 2nd invocation of the subsequent code + + /// Search Quido RS modules + byte[] searchTelegram = new byte[] { 0xF8, 0x11, 0, 0 }; + Telegram.UpdateTelegramCRC(searchTelegram); + SendMessageNow(searchTelegram); + } + if (telegramsToSend.Count > 0 && (DateTime.Now - lastSerialPortWrite) > new TimeSpan(0, 0, 0, 0, 500)) { SendMessageNow(telegramsToSend.Dequeue()); @@ -197,15 +210,27 @@ namespace TBF.BenchControl.Modbus.Common /// Stop this device public void StopDevice() { - if (serialPort != null) - { - //stopWorkerThread = true; - //workerThread.Join(2000); - serialPort.Close(); - serialPort = null; - } } - public void StopDevice2() { } + public void StopDevice2() + { + if (serialPort != null) + { + /// Send telegrams currently in the queue + while (telegramsToSend.Count > 0) + { + while ((DateTime.Now - lastSerialPortWrite) <= new TimeSpan(0, 0, 0, 0, 200)) + { + Thread.Sleep(100); + } + SendMessageNow(telegramsToSend.Dequeue()); + } + + //stopWorkerThread = true; + //workerThread.Join(2000); + serialPort.Close(); + serialPort = null; + } + } } } diff --git a/TBF/BenchControl/Modbus/QuidoRS/Factory.cs b/TBF/BenchControl/Modbus/QuidoRS/Factory.cs index 59d8e7523..00537b450 100644 --- a/TBF/BenchControl/Modbus/QuidoRS/Factory.cs +++ b/TBF/BenchControl/Modbus/QuidoRS/Factory.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2015-2016 Sensus Metering Systems +/// Copyright (c) 2015-2016 Sensus Slovensko a.s. /// using System.Collections.Generic; using TBF.BenchControl.Generic; diff --git a/TBF/BenchControl/Modbus/QuidoRS/QuidoRS.cs b/TBF/BenchControl/Modbus/QuidoRS/QuidoRS.cs index 20a3141de..08c665aa9 100644 --- a/TBF/BenchControl/Modbus/QuidoRS/QuidoRS.cs +++ b/TBF/BenchControl/Modbus/QuidoRS/QuidoRS.cs @@ -1,15 +1,17 @@ /// -/// Copyright (c) 2015 Sensus Metering Systems +/// Copyright (c) 2015-2019 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; using log4net; using TBF.BenchControl.Generic; using TBF.Boxes; +using System.Text; +using System.Diagnostics; namespace TBF.BenchControl.Modbus.QuidoRS { - public class QuidoRS : ComponentBase, IDevice + public class QuidoRS : ComponentBase, IDevice, GenericDevices.IParallelOutput { private static readonly ILog log = LogManager.GetLogger(typeof(QuidoRS)); public override string ToString() { return string.Format("QuidoRS({0})", Cfg.ToString(1)); } @@ -60,12 +62,22 @@ namespace TBF.BenchControl.Modbus.QuidoRS if (modbus.ReceivedTelegrams[quidoRSCfg.ModbusAddress].Count > 0) { - modbus.ReceivedTelegrams[quidoRSCfg.ModbusAddress].Dequeue(); + byte[] telegram = modbus.ReceivedTelegrams[quidoRSCfg.ModbusAddress].Dequeue(); + + if ((telegram.Length >= 8) && (telegram[1] == 0x11) && (telegram[2] == telegram.Length - 5)) + { + int msgLen = telegram.Length - 7; + byte modbusAddress = telegram[3]; + string msg = Encoding.ASCII.GetString(telegram, 5, msgLen); + string s = string.Format("QuidoRS detected: Address={0}, Message={1}", modbusAddress, msg); + Debug.WriteLine(s); + log.Warn(s); + } } } public void RunDeviceAfter() { } - public void StopDevice() { } + public void StopDevice() { SendOutputs(0); } public void StopDevice2() { } @@ -124,19 +136,19 @@ namespace TBF.BenchControl.Modbus.QuidoRS private void SendOutputs(ushort outputs) { - byte[] msg = new byte[11]; + byte addr = quidoRSCfg.ModbusAddress; + byte cmd = (byte)Function.ForceMultipleCoils; + byte dataLo = (byte)(outputs & 0xFF); + byte dataHi = (byte)(outputs >> 8); - msg[0] = quidoRSCfg.ModbusAddress; - msg[1] = (byte)Function.ForceMultipleCoils; - msg[2] = 0; /// Data Hi - msg[3] = 0; /// Data Lo - msg[4] = 0; /// Nr. of coils Hi - msg[5] = 16; /// Nr. of coils Lo - msg[6] = 2; /// Byte count - msg[7] = (byte)(outputs & 0xFF); /// Output data Lo - msg[8] = (byte)(outputs >> 8); /// Output data Hi - - modbus.SendMessage(msg); + if (quidoRSCfg.Variant == QuidoVariant.QuidoRS_2_16) + { + modbus.SendMessage(new byte[] { addr, cmd, 0, 0, 0, 16, 2, dataLo, dataHi, 0, 0 }); + } + else if (quidoRSCfg.Variant == QuidoVariant.QuidoRS_8_8) + { + modbus.SendMessage(new byte[] { addr, cmd, 0, 0, 0, 8, 1, dataLo, 0, 0 }); + } lastOutputsChange = DateTime.Now; } @@ -145,22 +157,29 @@ namespace TBF.BenchControl.Modbus.QuidoRS /// /// Events: SetOpututsDone, Error /// - /// Reference to a variable for the pressure in Bar - /// SetOutputsOp instance reference casted to IOperaton + /// Parallel output data + /// SetOutputsOp operation casted to IOperaton public IOperation SetOutputsOp(ushort outValue) { return new SetOutputsOp(this, outValue); } /// - /// Events: pressureDone, Error + /// Events: Event.None /// - /// Reference to a variable for the pressure in Bar - /// Event returned when SetOutput is done - /// SetOutputsOp instance reference casted to IOperaton - public IOperation ReadPressureOp(ushort outValue, Event setOutputsDone) + /// ShowBenchWaitingOp operation casted to generic IOperaton + public IOperation ShowBenchWaitingOp() { - return new SetOutputsOp(this, outValue, setOutputsDone); + return new ShowBenchWaitingOp(this); } - } + + /// + /// Events: Event.None + /// + /// ShowBenchErrorOp operation casted to generic IOperaton + public IOperation ShowBenchErrorOp() + { + return new ShowBenchErrorOp(this); + } + } } diff --git a/TBF/BenchControl/Modbus/QuidoRS/QuidoRSCfg.cs b/TBF/BenchControl/Modbus/QuidoRS/QuidoRSCfg.cs index c9377220e..1f932276e 100644 --- a/TBF/BenchControl/Modbus/QuidoRS/QuidoRSCfg.cs +++ b/TBF/BenchControl/Modbus/QuidoRS/QuidoRSCfg.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2015-2016 Sensus Metering Systems +/// Copyright (c) 2015-2019 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -9,6 +9,13 @@ using TBF.BenchControl.Generic; namespace TBF.BenchControl.Modbus.QuidoRS { + public enum QuidoVariant + { + QuidoRS_2_16, + QuidoRS_8_8, + Count + } + public class QuidoRSCfg : ComponentCfgBase, Generic.IChildComponentCfg { public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(QuidoRSCfg) })[0]; @@ -19,7 +26,8 @@ namespace TBF.BenchControl.Modbus.QuidoRS /// /// Serialized parameters /// - public byte ModbusAddress; /// 1..255 + public byte ModbusAddress; /// 1..247 + public QuidoVariant Variant; /// 'QuidoRS_2_16' or 'QuidoRS_8_8' public bool WatchdogEnabled; public int WatchdogBitNr; /// 0..15 @@ -29,7 +37,8 @@ namespace TBF.BenchControl.Modbus.QuidoRS Name = "QuidoRS"; ParentName = "Modbus"; ModbusAddress = 49; - WatchdogEnabled = true; + Variant = QuidoVariant.QuidoRS_2_16; + WatchdogEnabled = false; WatchdogBitNr = 4; } @@ -41,9 +50,10 @@ namespace TBF.BenchControl.Modbus.QuidoRS public string ToString(int i) { - return string.Format("Name={0}, ModbusAddr={1}, Parent={2}", + return string.Format("Name={0}, ModbusAddress={1}, Variant={2}, Parent={2}", Name, ModbusAddress, + Variant, (string.IsNullOrEmpty(ParentName) ? "-" : ParentName)); } } diff --git a/TBF/BenchControl/Modbus/QuidoRS/QuidoRSCfgCtrl.cs b/TBF/BenchControl/Modbus/QuidoRS/QuidoRSCfgCtrl.cs index 5a45598fc..20026329b 100644 --- a/TBF/BenchControl/Modbus/QuidoRS/QuidoRSCfgCtrl.cs +++ b/TBF/BenchControl/Modbus/QuidoRS/QuidoRSCfgCtrl.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2015 Sensus Metering Systems +/// Copyright (c) 2015-2019 Sensus Slovensko a.s. /// using System; using System.Windows.Forms; @@ -46,6 +46,8 @@ namespace TBF.BenchControl.Modbus.QuidoRS } } + for (QuidoVariant v = 0; v < QuidoVariant.Count; v++) variantComboBox.Items.Add(v.ToString()); + Redraw(); } @@ -61,6 +63,7 @@ namespace TBF.BenchControl.Modbus.QuidoRS nameTextBox.Text = config.Name; parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName; modbusAddressTextBox.Text = config.ModbusAddress.ToString(); + variantComboBox.Text = config.Variant.ToString(); watchdogCheckBox.Checked = config.WatchdogEnabled; watchdogBitNrTextBox.Text = config.WatchdogBitNr.ToString(); } @@ -70,6 +73,7 @@ namespace TBF.BenchControl.Modbus.QuidoRS nameTextBox.Enabled = true; parentNameComboBox.Enabled = true; modbusAddressTextBox.Enabled = true; + variantComboBox.Enabled = true; watchdogCheckBox.Enabled = true; watchdogBitNrTextBox.Enabled = true; } @@ -84,11 +88,16 @@ namespace TBF.BenchControl.Modbus.QuidoRS flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "Invalid 'Parent Name'"; } - if (!int.TryParse(modbusAddressTextBox.Text, out dummy) || dummy < 0 || dummy > 255) + if (!int.TryParse(modbusAddressTextBox.Text, out dummy) || dummy < 1 || dummy > 247) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "'Modbus Address' should be between 0 and 255"; } + if (!variantComboBox.Items.Contains(variantComboBox.Text)) + { + flags |= CfgUpdateFlags.Error; + message += Environment.NewLine + "Invalid 'Variant'"; + } if (!int.TryParse(watchdogBitNrTextBox.Text, out dummy) || dummy < 0 || dummy > 15) { flags |= CfgUpdateFlags.Error; @@ -106,6 +115,10 @@ namespace TBF.BenchControl.Modbus.QuidoRS config.Name = nameTextBox.Text; config.ParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text; config.ModbusAddress = (byte)int.Parse(modbusAddressTextBox.Text); + for (QuidoVariant v = 0; v < QuidoVariant.Count; v++) + { + if (variantComboBox.Text == v.ToString()) { config.Variant = v; break; } + } config.WatchdogEnabled = watchdogCheckBox.Checked; config.WatchdogBitNr = int.Parse(watchdogBitNrTextBox.Text); diff --git a/TBF/BenchControl/Modbus/QuidoRS/QuidoRSCfgCtrl.designer.cs b/TBF/BenchControl/Modbus/QuidoRS/QuidoRSCfgCtrl.designer.cs index fb8606fb1..dafa19dfd 100644 --- a/TBF/BenchControl/Modbus/QuidoRS/QuidoRSCfgCtrl.designer.cs +++ b/TBF/BenchControl/Modbus/QuidoRS/QuidoRSCfgCtrl.designer.cs @@ -41,6 +41,8 @@ namespace TBF.BenchControl.Modbus.QuidoRS this.watchdogCheckBox = new System.Windows.Forms.CheckBox(); this.watchdogBitNrTextBox = new System.Windows.Forms.TextBox(); this.watchdogBitNrLabel = new System.Windows.Forms.Label(); + this.variantComboBox = new System.Windows.Forms.ComboBox(); + this.variantLabel = new System.Windows.Forms.Label(); this.SuspendLayout(); // // parentNameLabel @@ -84,7 +86,7 @@ namespace TBF.BenchControl.Modbus.QuidoRS this.modbusAddressLabel.Location = new System.Drawing.Point(28, 108); this.modbusAddressLabel.Name = "modbusAddressLabel"; this.modbusAddressLabel.Size = new System.Drawing.Size(86, 13); - this.modbusAddressLabel.TabIndex = 7; + this.modbusAddressLabel.TabIndex = 5; this.modbusAddressLabel.Text = "Modbus Address"; // // modbusAddressTextBox @@ -93,7 +95,7 @@ namespace TBF.BenchControl.Modbus.QuidoRS this.modbusAddressTextBox.Location = new System.Drawing.Point(138, 105); this.modbusAddressTextBox.Name = "modbusAddressTextBox"; this.modbusAddressTextBox.Size = new System.Drawing.Size(46, 20); - this.modbusAddressTextBox.TabIndex = 8; + this.modbusAddressTextBox.TabIndex = 6; // // parentNameComboBox // @@ -108,7 +110,7 @@ namespace TBF.BenchControl.Modbus.QuidoRS // this.watchdogCheckBox.AutoSize = true; this.watchdogCheckBox.Enabled = false; - this.watchdogCheckBox.Location = new System.Drawing.Point(31, 131); + this.watchdogCheckBox.Location = new System.Drawing.Point(31, 164); this.watchdogCheckBox.Name = "watchdogCheckBox"; this.watchdogCheckBox.Size = new System.Drawing.Size(99, 17); this.watchdogCheckBox.TabIndex = 9; @@ -118,7 +120,7 @@ namespace TBF.BenchControl.Modbus.QuidoRS // watchdogBitNrTextBox // this.watchdogBitNrTextBox.Enabled = false; - this.watchdogBitNrTextBox.Location = new System.Drawing.Point(138, 153); + this.watchdogBitNrTextBox.Location = new System.Drawing.Point(138, 186); this.watchdogBitNrTextBox.Name = "watchdogBitNrTextBox"; this.watchdogBitNrTextBox.Size = new System.Drawing.Size(46, 20); this.watchdogBitNrTextBox.TabIndex = 11; @@ -126,16 +128,36 @@ namespace TBF.BenchControl.Modbus.QuidoRS // watchdogBitNrLabel // this.watchdogBitNrLabel.AutoSize = true; - this.watchdogBitNrLabel.Location = new System.Drawing.Point(28, 156); + this.watchdogBitNrLabel.Location = new System.Drawing.Point(28, 189); this.watchdogBitNrLabel.Name = "watchdogBitNrLabel"; this.watchdogBitNrLabel.Size = new System.Drawing.Size(81, 13); this.watchdogBitNrLabel.TabIndex = 10; this.watchdogBitNrLabel.Text = "Watchdog bit #"; // + // variantComboBox + // + this.variantComboBox.Enabled = false; + this.variantComboBox.FormattingEnabled = true; + this.variantComboBox.Location = new System.Drawing.Point(138, 131); + this.variantComboBox.Name = "variantComboBox"; + this.variantComboBox.Size = new System.Drawing.Size(130, 21); + this.variantComboBox.TabIndex = 8; + // + // variantLabel + // + this.variantLabel.AutoSize = true; + this.variantLabel.Location = new System.Drawing.Point(28, 134); + this.variantLabel.Name = "variantLabel"; + this.variantLabel.Size = new System.Drawing.Size(40, 13); + this.variantLabel.TabIndex = 7; + this.variantLabel.Text = "Variant"; + // // QuidoRSCfgCtrl // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.variantComboBox); + this.Controls.Add(this.variantLabel); this.Controls.Add(this.watchdogBitNrTextBox); this.Controls.Add(this.watchdogBitNrLabel); this.Controls.Add(this.watchdogCheckBox); @@ -147,7 +169,7 @@ namespace TBF.BenchControl.Modbus.QuidoRS this.Controls.Add(this.nameLabel); this.Controls.Add(this.componentNameLabel); this.Name = "QuidoRSCfgCtrl"; - this.Size = new System.Drawing.Size(300, 200); + this.Size = new System.Drawing.Size(374, 268); this.Load += new System.EventHandler(this.QuidoRSCfgCtrl_Load); this.ResumeLayout(false); this.PerformLayout(); @@ -166,5 +188,7 @@ namespace TBF.BenchControl.Modbus.QuidoRS private System.Windows.Forms.CheckBox watchdogCheckBox; private System.Windows.Forms.TextBox watchdogBitNrTextBox; private System.Windows.Forms.Label watchdogBitNrLabel; + private System.Windows.Forms.ComboBox variantComboBox; + private System.Windows.Forms.Label variantLabel; } } diff --git a/TBF/BenchControl/Modbus/QuidoRS/SetOutputsOp.cs b/TBF/BenchControl/Modbus/QuidoRS/SetOutputsOp.cs index 6546db0be..35c8b7d4a 100644 --- a/TBF/BenchControl/Modbus/QuidoRS/SetOutputsOp.cs +++ b/TBF/BenchControl/Modbus/QuidoRS/SetOutputsOp.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2015 Sensus Metering Systems +/// Copyright (c) 2015 Sensus Slovensko a.s. /// using System; using log4net; diff --git a/TBF/BenchControl/Modbus/QuidoRS/ShowBenchErrorOp.cs b/TBF/BenchControl/Modbus/QuidoRS/ShowBenchErrorOp.cs new file mode 100644 index 000000000..9767b44d1 --- /dev/null +++ b/TBF/BenchControl/Modbus/QuidoRS/ShowBenchErrorOp.cs @@ -0,0 +1,51 @@ +/// +/// Copyright (c) 2019 Sensus Slovensko a.s. +/// +using System; +using log4net; +using TBF.Boxes; + +namespace TBF.BenchControl.Modbus.QuidoRS +{ + public class ShowBenchErrorOp : IOperation + { + private static readonly ILog log = LogManager.GetLogger(typeof(ShowBenchErrorOp)); + public override string ToString() { return string.Format("ShowBenchErrorOp(.)"); } + + const ushort BenchReadyValue = 0x01; + const ushort BenchErrorValue = 0x06; + + /// Set by the constructor + readonly QuidoRS quidoRS; + + /// + /// Events: Event.None + /// + /// Pressure meter reference + public ShowBenchErrorOp(QuidoRS quidoRS) + { + if (quidoRS == null) throw new ArgumentNullException("quidoRS"); + this.quidoRS = quidoRS; + + log.Debug(this.ToString()); + } + + /// Start this operation + public void Start() + { + quidoRS.SetOutputs(BenchErrorValue); + } + + /// Run this operation + public Event Run() + { + return Event.None; + } + + /// Stop this operation + public void Stop() + { + quidoRS.SetOutputs(BenchReadyValue); + } + } +} diff --git a/TBF/BenchControl/Modbus/QuidoRS/ShowBenchWaitingOp.cs b/TBF/BenchControl/Modbus/QuidoRS/ShowBenchWaitingOp.cs new file mode 100644 index 000000000..6000b6793 --- /dev/null +++ b/TBF/BenchControl/Modbus/QuidoRS/ShowBenchWaitingOp.cs @@ -0,0 +1,51 @@ +/// +/// Copyright (c) 2019 Sensus Slovensko a.s. +/// +using System; +using log4net; +using TBF.Boxes; + +namespace TBF.BenchControl.Modbus.QuidoRS +{ + public class ShowBenchWaitingOp : IOperation + { + private static readonly ILog log = LogManager.GetLogger(typeof(ShowBenchWaitingOp)); + public override string ToString() { return string.Format("ShowBenchWaitingOp(.)"); } + + const ushort BenchReadyValue = 0x01; + const ushort BenchWaitingValue = 0x06; + + /// Set by the constructor + readonly QuidoRS quidoRS; + + /// + /// Events: Event.None + /// + /// Pressure meter reference + public ShowBenchWaitingOp(QuidoRS quidoRS) + { + if (quidoRS == null) throw new ArgumentNullException("quidoRS"); + this.quidoRS = quidoRS; + + log.Debug(this.ToString()); + } + + /// Start this operation + public void Start() + { + quidoRS.SetOutputs(BenchWaitingValue); + } + + /// Run this operation + public Event Run() + { + return Event.None; + } + + /// Stop this operation + public void Stop() + { + quidoRS.SetOutputs(BenchReadyValue); + } + } +} diff --git a/TBF/BenchControl/Sequences/MainSeq.cs b/TBF/BenchControl/Sequences/MainSeq.cs index 082d57b48..e5a7f95df 100644 --- a/TBF/BenchControl/Sequences/MainSeq.cs +++ b/TBF/BenchControl/Sequences/MainSeq.cs @@ -1245,6 +1245,7 @@ namespace TBF.BenchControl.Sequences //-------------------------------- State.Create("MainSeq : Procedure configuration error") .AddOperation(checkUiOp) + .AddOperation(StateMachine.BenchErrorOp) .AddOperation(new Operations.MessageBoxOp("Test configration error")) .EnterState(); do @@ -1259,6 +1260,7 @@ namespace TBF.BenchControl.Sequences //-------------------------------- State.Create("MainSeq : ERROR -> Closing the valves") .AddOperation(checkUiOp) + .AddOperation(StateMachine.BenchErrorOp) .AddOperation(StateMachine.ControlBoard.SetValvesOp(StateMachine.DefaultValvesOpen, StateMachine.DefaultValvesClose)) .EnterState(); @@ -1270,6 +1272,7 @@ namespace TBF.BenchControl.Sequences //-------------------------------- State.Create("MainSeq : ERROR state") + .AddOperation(StateMachine.BenchErrorOp) .EnterState(); while (true) StateMachine.WaitRunDevsRunOps(); } @@ -1359,6 +1362,7 @@ namespace TBF.BenchControl.Sequences State.Create("MainSeq : Select an activity") .AddOperation(checkUiOp) + .AddOperation(StateMachine.BenchWaitingOp) .AddOperation((StateMachine.Tank1 is IScale) ? (StateMachine.Tank1 as IScale).ReadMassOp(ref mass1) : null) .AddOperation((StateMachine.Tank2 is IScale) ? (StateMachine.Tank2 as IScale).ReadMassOp(ref mass2) : null) .AddOperation((StateMachine.Tank3 is IScale) ? (StateMachine.Tank3 as IScale).ReadMassOp(ref mass3) : null) @@ -1400,6 +1404,7 @@ namespace TBF.BenchControl.Sequences Bridge.OnActivity(this, Strings.Error); ///------------------------------------ State.Create("MainSeq : ERROR state") + .AddOperation(StateMachine.BenchErrorOp) .EnterState(); while (true) StateMachine.WaitRunDevsRunOps(); /// Endless loop } diff --git a/TBF/BenchControl/State.cs b/TBF/BenchControl/State.cs index af98c15db..779419dff 100644 --- a/TBF/BenchControl/State.cs +++ b/TBF/BenchControl/State.cs @@ -171,8 +171,6 @@ namespace TBF.BenchControl /// public State EnterState() { - log.Debug(this.ToString()); - StopAndStartOperations(State.currentState, this); State.currentState = this; UiBridge.Bridge.OnStateChanged(this, State.currentState.ToString()); @@ -236,7 +234,7 @@ namespace TBF.BenchControl } } - log.WarnFormat("---------------( {0} )---------------", newState.ToString()); + log.WarnFormat("---------------( {0} )---------------", newState); /// Start() the operations that are in the current (new) state, but aren't in the previous state. foreach (IOperation operation in newState.Operations) diff --git a/TBF/BenchControl/StateMachine.cs b/TBF/BenchControl/StateMachine.cs index 6bc53607a..f52e98ab2 100644 --- a/TBF/BenchControl/StateMachine.cs +++ b/TBF/BenchControl/StateMachine.cs @@ -45,7 +45,9 @@ namespace TBF.BenchControl /// Public components public static Elde.ControlBoardDev ControlBoard; public static GenericDevices.IAmbient Ambient; - public static GenericDevices.IScaleOrTank Tank1; + public static IOperation BenchWaitingOp; + public static IOperation BenchErrorOp; + public static GenericDevices.IScaleOrTank Tank1; public static GenericDevices.IScaleOrTank Tank2; public static GenericDevices.IScaleOrTank Tank3; public static GenericDevices.IValve DrainValve1; @@ -241,6 +243,13 @@ namespace TBF.BenchControl if (cmpnt is IWaterMeter) SequenceBase.WaterMeters.Add(cmpnt as IWaterMeter); if (cmpnt is ICamera) SequenceBase.Cameras.Add(cmpnt as ICamera); if (cmpnt is GenericDevices.IAmbient) Ambient = cmpnt as GenericDevices.IAmbient; + + if (cmpnt is GenericDevices.IParallelOutput && cmpnt.Name.ToLower().Contains("tower")) + { + BenchWaitingOp = (cmpnt as GenericDevices.IParallelOutput).ShowBenchWaitingOp(); + BenchErrorOp = (cmpnt as GenericDevices.IParallelOutput).ShowBenchErrorOp(); + } + if (cmpnt is IScaleOrTank) { IScaleOrTank tank = cmpnt as IScaleOrTank; diff --git a/TBF/BenchControl/TestMethods/ChangeFlowDirection/ChangeFlowDirectionSeq.cs b/TBF/BenchControl/TestMethods/ChangeFlowDirection/ChangeFlowDirectionSeq.cs index bc9b68ffc..0c60c86d2 100644 --- a/TBF/BenchControl/TestMethods/ChangeFlowDirection/ChangeFlowDirectionSeq.cs +++ b/TBF/BenchControl/TestMethods/ChangeFlowDirection/ChangeFlowDirectionSeq.cs @@ -67,6 +67,7 @@ namespace TBF.BenchControl.TestMethods.ChangeFlowDirection Bridge.OnActivity(this, test.Method); State.Create(string.Format("{0}({1}) : Turn the direction of watermeters", test.Method, test.Name)) .AddOperation(checkUiOp) + .AddOperation(StateMachine.BenchWaitingOp) .AddOperation(new Operations.MessageBoxOp("Otočte iPerly prosím.")) .EnterState(); do diff --git a/TBF/Properties/AssemblyInfo.cs b/TBF/Properties/AssemblyInfo.cs index 9c78f5755..f410eabd6 100644 --- a/TBF/Properties/AssemblyInfo.cs +++ b/TBF/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("2.18.1144.0")] -[assembly: AssemblyFileVersion("2.18.1144.0")] +[assembly: AssemblyVersion("2.18.1147.0")] +[assembly: AssemblyFileVersion("2.18.1147.0")] diff --git a/TBF/TBF.csproj b/TBF/TBF.csproj index 494af4591..ab7f2df0c 100644 --- a/TBF/TBF.csproj +++ b/TBF/TBF.csproj @@ -549,6 +549,7 @@ + @@ -687,6 +688,8 @@ + +