QuidoRS : Watchdog is optional, configurable, ver. 2 12.455

This commit is contained in:
Milan Hanajik
2017-02-09 20:59:00 +01:00
parent 46cc618300
commit 93513100eb
4 changed files with 144 additions and 90 deletions
@@ -19,7 +19,7 @@ namespace TBF.BenchControl.Modbus.QuidoRS
private ushort currentOutputs;
const ushort WatchdogBitMask = 0x0010;
ushort watchdogBitMask;
public QuidoRS()
{
@@ -33,6 +33,8 @@ namespace TBF.BenchControl.Modbus.QuidoRS
modbus = (GenericDevices.IModbus)TbfComponents.FindComponent(cfg.ParentName, components);
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
watchdogBitMask = (ushort)(quidoRSCfg.WatchdogEnabled ? (1 << quidoRSCfg.WatchdogBitNr) : 0);
log.Debug(this.ToString());
}
@@ -49,7 +51,7 @@ namespace TBF.BenchControl.Modbus.QuidoRS
/// <summary>Run this device</summary>
public void RunDeviceAfter()
{
currentOutputs = (UInt16)((Int32)currentOutputs ^ (Int32)WatchdogBitMask);
currentOutputs = (UInt16)((Int32)currentOutputs ^ (Int32)watchdogBitMask);
SendOutputs(currentOutputs);
}
@@ -64,7 +66,7 @@ namespace TBF.BenchControl.Modbus.QuidoRS
/// <param name="outputs">output value</param>
public void SetOutputs(ushort outputs)
{
currentOutputs = (UInt16)((Int32)outputs | ((Int32)currentOutputs & (Int32)WatchdogBitMask));
currentOutputs = (UInt16)((Int32)outputs | ((Int32)currentOutputs & (Int32)watchdogBitMask));
SendOutputs(currentOutputs);
}
@@ -17,6 +17,8 @@ namespace TBF.BenchControl.Modbus.QuidoRS
/// Serialized parameters
///
public byte ModbusAddress; /// 1..255
public bool WatchdogEnabled;
public int WatchdogBitNr; /// 0..15
/// Private parameterless constructor invoked by all other (public) constructors
QuidoRSCfg()
@@ -24,6 +26,8 @@ namespace TBF.BenchControl.Modbus.QuidoRS
Name = "QuidoRS";
ParentName = "Modbus";
ModbusAddress = 49;
WatchdogEnabled = true;
WatchdogBitNr = 4;
}
public QuidoRSCfg(IComponentFactory factory)
@@ -63,6 +63,8 @@ namespace TBF.BenchControl.Modbus.QuidoRS
nameTextBox.Text = config.Name;
parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName;
modbusAddressTextBox.Text = config.ModbusAddress.ToString();
watchdogCheckBox.Checked = config.WatchdogEnabled;
watchdogBitNrTextBox.Text = config.WatchdogBitNr.ToString();
}
public void Unlock()
@@ -70,6 +72,8 @@ namespace TBF.BenchControl.Modbus.QuidoRS
nameTextBox.Enabled = true;
parentNameComboBox.Enabled = true;
modbusAddressTextBox.Enabled = true;
watchdogCheckBox.Enabled = true;
watchdogBitNrTextBox.Enabled = true;
}
public CfgUpdateFlags VerifyCfg(ref string message)
@@ -87,6 +91,11 @@ namespace TBF.BenchControl.Modbus.QuidoRS
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Modbus Address' should be between 0 and 255";
}
if (!int.TryParse(watchdogBitNrTextBox.Text, out dummy) || dummy < 0 || dummy > 15)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Watchdog Bit Nr.' should be between 0 and 15";
}
return flags;
}
@@ -99,6 +108,8 @@ 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);
config.WatchdogEnabled = watchdogCheckBox.Checked;
config.WatchdogBitNr = int.Parse(watchdogBitNrTextBox.Text);
return flags;
}
@@ -38,6 +38,9 @@ namespace TBF.BenchControl.Modbus.QuidoRS
this.modbusAddressLabel = new System.Windows.Forms.Label();
this.modbusAddressTextBox = new System.Windows.Forms.TextBox();
this.parentNameComboBox = new System.Windows.Forms.ComboBox();
this.watchdogCheckBox = new System.Windows.Forms.CheckBox();
this.watchdogBitNrTextBox = new System.Windows.Forms.TextBox();
this.watchdogBitNrLabel = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// parentNameLabel
@@ -78,7 +81,7 @@ namespace TBF.BenchControl.Modbus.QuidoRS
// modbusAddressLabel
//
this.modbusAddressLabel.AutoSize = true;
this.modbusAddressLabel.Location = new System.Drawing.Point(28, 133);
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;
@@ -87,7 +90,7 @@ namespace TBF.BenchControl.Modbus.QuidoRS
// modbusAddressTextBox
//
this.modbusAddressTextBox.Enabled = false;
this.modbusAddressTextBox.Location = new System.Drawing.Point(138, 130);
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;
@@ -101,10 +104,41 @@ namespace TBF.BenchControl.Modbus.QuidoRS
this.parentNameComboBox.Size = new System.Drawing.Size(130, 21);
this.parentNameComboBox.TabIndex = 4;
//
// ComponentCfgCtrl
// watchdogCheckBox
//
this.watchdogCheckBox.AutoSize = true;
this.watchdogCheckBox.Enabled = false;
this.watchdogCheckBox.Location = new System.Drawing.Point(31, 131);
this.watchdogCheckBox.Name = "watchdogCheckBox";
this.watchdogCheckBox.Size = new System.Drawing.Size(99, 17);
this.watchdogCheckBox.TabIndex = 9;
this.watchdogCheckBox.Text = "Watchdog \'ON\'";
this.watchdogCheckBox.UseVisualStyleBackColor = true;
//
// watchdogBitNrTextBox
//
this.watchdogBitNrTextBox.Enabled = false;
this.watchdogBitNrTextBox.Location = new System.Drawing.Point(138, 153);
this.watchdogBitNrTextBox.Name = "watchdogBitNrTextBox";
this.watchdogBitNrTextBox.Size = new System.Drawing.Size(46, 20);
this.watchdogBitNrTextBox.TabIndex = 11;
//
// watchdogBitNrLabel
//
this.watchdogBitNrLabel.AutoSize = true;
this.watchdogBitNrLabel.Location = new System.Drawing.Point(28, 156);
this.watchdogBitNrLabel.Name = "watchdogBitNrLabel";
this.watchdogBitNrLabel.Size = new System.Drawing.Size(81, 13);
this.watchdogBitNrLabel.TabIndex = 10;
this.watchdogBitNrLabel.Text = "Watchdog bit #";
//
// QuidoRSCfgCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.watchdogBitNrTextBox);
this.Controls.Add(this.watchdogBitNrLabel);
this.Controls.Add(this.watchdogCheckBox);
this.Controls.Add(this.parentNameComboBox);
this.Controls.Add(this.modbusAddressTextBox);
this.Controls.Add(this.modbusAddressLabel);
@@ -112,7 +146,7 @@ namespace TBF.BenchControl.Modbus.QuidoRS
this.Controls.Add(this.nameTextBox);
this.Controls.Add(this.nameLabel);
this.Controls.Add(this.componentNameLabel);
this.Name = "ComponentCfgCtrl";
this.Name = "QuidoRSCfgCtrl";
this.Size = new System.Drawing.Size(300, 200);
this.Load += new System.EventHandler(this.QuidoRSCfgCtrl_Load);
this.ResumeLayout(false);
@@ -129,5 +163,8 @@ namespace TBF.BenchControl.Modbus.QuidoRS
private System.Windows.Forms.Label modbusAddressLabel;
private System.Windows.Forms.TextBox modbusAddressTextBox;
private System.Windows.Forms.ComboBox parentNameComboBox;
private System.Windows.Forms.CheckBox watchdogCheckBox;
private System.Windows.Forms.TextBox watchdogBitNrTextBox;
private System.Windows.Forms.Label watchdogBitNrLabel;
}
}