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; private ushort currentOutputs;
const ushort WatchdogBitMask = 0x0010; ushort watchdogBitMask;
public QuidoRS() public QuidoRS()
{ {
@@ -33,6 +33,8 @@ namespace TBF.BenchControl.Modbus.QuidoRS
modbus = (GenericDevices.IModbus)TbfComponents.FindComponent(cfg.ParentName, components); modbus = (GenericDevices.IModbus)TbfComponents.FindComponent(cfg.ParentName, components);
if (modbus == null) throw new Exception("Cannot find " + Name + " parent"); if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
watchdogBitMask = (ushort)(quidoRSCfg.WatchdogEnabled ? (1 << quidoRSCfg.WatchdogBitNr) : 0);
log.Debug(this.ToString()); log.Debug(this.ToString());
} }
@@ -49,7 +51,7 @@ namespace TBF.BenchControl.Modbus.QuidoRS
/// <summary>Run this device</summary> /// <summary>Run this device</summary>
public void RunDeviceAfter() public void RunDeviceAfter()
{ {
currentOutputs = (UInt16)((Int32)currentOutputs ^ (Int32)WatchdogBitMask); currentOutputs = (UInt16)((Int32)currentOutputs ^ (Int32)watchdogBitMask);
SendOutputs(currentOutputs); SendOutputs(currentOutputs);
} }
@@ -64,7 +66,7 @@ namespace TBF.BenchControl.Modbus.QuidoRS
/// <param name="outputs">output value</param> /// <param name="outputs">output value</param>
public void SetOutputs(ushort outputs) public void SetOutputs(ushort outputs)
{ {
currentOutputs = (UInt16)((Int32)outputs | ((Int32)currentOutputs & (Int32)WatchdogBitMask)); currentOutputs = (UInt16)((Int32)outputs | ((Int32)currentOutputs & (Int32)watchdogBitMask));
SendOutputs(currentOutputs); SendOutputs(currentOutputs);
} }
@@ -17,6 +17,8 @@ namespace TBF.BenchControl.Modbus.QuidoRS
/// Serialized parameters /// Serialized parameters
/// ///
public byte ModbusAddress; /// 1..255 public byte ModbusAddress; /// 1..255
public bool WatchdogEnabled;
public int WatchdogBitNr; /// 0..15
/// Private parameterless constructor invoked by all other (public) constructors /// Private parameterless constructor invoked by all other (public) constructors
QuidoRSCfg() QuidoRSCfg()
@@ -24,6 +26,8 @@ namespace TBF.BenchControl.Modbus.QuidoRS
Name = "QuidoRS"; Name = "QuidoRS";
ParentName = "Modbus"; ParentName = "Modbus";
ModbusAddress = 49; ModbusAddress = 49;
WatchdogEnabled = true;
WatchdogBitNr = 4;
} }
public QuidoRSCfg(IComponentFactory factory) public QuidoRSCfg(IComponentFactory factory)
@@ -63,6 +63,8 @@ namespace TBF.BenchControl.Modbus.QuidoRS
nameTextBox.Text = config.Name; nameTextBox.Text = config.Name;
parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName; parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName;
modbusAddressTextBox.Text = config.ModbusAddress.ToString(); modbusAddressTextBox.Text = config.ModbusAddress.ToString();
watchdogCheckBox.Checked = config.WatchdogEnabled;
watchdogBitNrTextBox.Text = config.WatchdogBitNr.ToString();
} }
public void Unlock() public void Unlock()
@@ -70,6 +72,8 @@ namespace TBF.BenchControl.Modbus.QuidoRS
nameTextBox.Enabled = true; nameTextBox.Enabled = true;
parentNameComboBox.Enabled = true; parentNameComboBox.Enabled = true;
modbusAddressTextBox.Enabled = true; modbusAddressTextBox.Enabled = true;
watchdogCheckBox.Enabled = true;
watchdogBitNrTextBox.Enabled = true;
} }
public CfgUpdateFlags VerifyCfg(ref string message) public CfgUpdateFlags VerifyCfg(ref string message)
@@ -87,7 +91,12 @@ namespace TBF.BenchControl.Modbus.QuidoRS
flags |= CfgUpdateFlags.Error; flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Modbus Address' should be between 0 and 255"; message += Environment.NewLine + "'Modbus Address' should be between 0 and 255";
} }
return flags; 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;
} }
public CfgUpdateFlags UpdateCfg() public CfgUpdateFlags UpdateCfg()
@@ -99,6 +108,8 @@ namespace TBF.BenchControl.Modbus.QuidoRS
config.Name = nameTextBox.Text; config.Name = nameTextBox.Text;
config.ParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text; config.ParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text;
config.ModbusAddress = (byte)int.Parse(modbusAddressTextBox.Text); config.ModbusAddress = (byte)int.Parse(modbusAddressTextBox.Text);
config.WatchdogEnabled = watchdogCheckBox.Checked;
config.WatchdogBitNr = int.Parse(watchdogBitNrTextBox.Text);
return flags; return flags;
} }
@@ -31,92 +31,126 @@ namespace TBF.BenchControl.Modbus.QuidoRS
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.parentNameLabel = new System.Windows.Forms.Label(); this.parentNameLabel = new System.Windows.Forms.Label();
this.nameTextBox = new System.Windows.Forms.TextBox(); this.nameTextBox = new System.Windows.Forms.TextBox();
this.nameLabel = new System.Windows.Forms.Label(); this.nameLabel = new System.Windows.Forms.Label();
this.componentNameLabel = new System.Windows.Forms.Label(); this.componentNameLabel = new System.Windows.Forms.Label();
this.modbusAddressLabel = new System.Windows.Forms.Label(); this.modbusAddressLabel = new System.Windows.Forms.Label();
this.modbusAddressTextBox = new System.Windows.Forms.TextBox(); this.modbusAddressTextBox = new System.Windows.Forms.TextBox();
this.parentNameComboBox = new System.Windows.Forms.ComboBox(); this.parentNameComboBox = new System.Windows.Forms.ComboBox();
this.SuspendLayout(); this.watchdogCheckBox = new System.Windows.Forms.CheckBox();
// this.watchdogBitNrTextBox = new System.Windows.Forms.TextBox();
// parentNameLabel this.watchdogBitNrLabel = new System.Windows.Forms.Label();
// this.SuspendLayout();
this.parentNameLabel.AutoSize = true; //
this.parentNameLabel.Location = new System.Drawing.Point(28, 81); // parentNameLabel
this.parentNameLabel.Name = "parentNameLabel"; //
this.parentNameLabel.Size = new System.Drawing.Size(69, 13); this.parentNameLabel.AutoSize = true;
this.parentNameLabel.TabIndex = 3; this.parentNameLabel.Location = new System.Drawing.Point(28, 81);
this.parentNameLabel.Text = "Parent Name"; this.parentNameLabel.Name = "parentNameLabel";
// this.parentNameLabel.Size = new System.Drawing.Size(69, 13);
// nameTextBox this.parentNameLabel.TabIndex = 3;
// this.parentNameLabel.Text = "Parent Name";
this.nameTextBox.Enabled = false; //
this.nameTextBox.Location = new System.Drawing.Point(138, 52); // nameTextBox
this.nameTextBox.Name = "nameTextBox"; //
this.nameTextBox.Size = new System.Drawing.Size(130, 20); this.nameTextBox.Enabled = false;
this.nameTextBox.TabIndex = 2; this.nameTextBox.Location = new System.Drawing.Point(138, 52);
// this.nameTextBox.Name = "nameTextBox";
// nameLabel this.nameTextBox.Size = new System.Drawing.Size(130, 20);
// this.nameTextBox.TabIndex = 2;
this.nameLabel.AutoSize = true; //
this.nameLabel.Location = new System.Drawing.Point(28, 55); // nameLabel
this.nameLabel.Name = "nameLabel"; //
this.nameLabel.Size = new System.Drawing.Size(35, 13); this.nameLabel.AutoSize = true;
this.nameLabel.TabIndex = 1; this.nameLabel.Location = new System.Drawing.Point(28, 55);
this.nameLabel.Text = "Name"; this.nameLabel.Name = "nameLabel";
// this.nameLabel.Size = new System.Drawing.Size(35, 13);
// componentNameLabel this.nameLabel.TabIndex = 1;
// this.nameLabel.Text = "Name";
this.componentNameLabel.AutoSize = true; //
this.componentNameLabel.Location = new System.Drawing.Point(135, 28); // componentNameLabel
this.componentNameLabel.Name = "componentNameLabel"; //
this.componentNameLabel.Size = new System.Drawing.Size(83, 13); this.componentNameLabel.AutoSize = true;
this.componentNameLabel.TabIndex = 0; this.componentNameLabel.Location = new System.Drawing.Point(135, 28);
this.componentNameLabel.Text = "ComonentName"; this.componentNameLabel.Name = "componentNameLabel";
// this.componentNameLabel.Size = new System.Drawing.Size(83, 13);
// modbusAddressLabel this.componentNameLabel.TabIndex = 0;
// this.componentNameLabel.Text = "ComonentName";
this.modbusAddressLabel.AutoSize = true; //
this.modbusAddressLabel.Location = new System.Drawing.Point(28, 133); // modbusAddressLabel
this.modbusAddressLabel.Name = "modbusAddressLabel"; //
this.modbusAddressLabel.Size = new System.Drawing.Size(86, 13); this.modbusAddressLabel.AutoSize = true;
this.modbusAddressLabel.TabIndex = 7; this.modbusAddressLabel.Location = new System.Drawing.Point(28, 108);
this.modbusAddressLabel.Text = "Modbus Address"; this.modbusAddressLabel.Name = "modbusAddressLabel";
// this.modbusAddressLabel.Size = new System.Drawing.Size(86, 13);
// modbusAddressTextBox this.modbusAddressLabel.TabIndex = 7;
// this.modbusAddressLabel.Text = "Modbus Address";
this.modbusAddressTextBox.Enabled = false; //
this.modbusAddressTextBox.Location = new System.Drawing.Point(138, 130); // modbusAddressTextBox
this.modbusAddressTextBox.Name = "modbusAddressTextBox"; //
this.modbusAddressTextBox.Size = new System.Drawing.Size(46, 20); this.modbusAddressTextBox.Enabled = false;
this.modbusAddressTextBox.TabIndex = 8; this.modbusAddressTextBox.Location = new System.Drawing.Point(138, 105);
// this.modbusAddressTextBox.Name = "modbusAddressTextBox";
// parentNameComboBox this.modbusAddressTextBox.Size = new System.Drawing.Size(46, 20);
// this.modbusAddressTextBox.TabIndex = 8;
this.parentNameComboBox.Enabled = false; //
this.parentNameComboBox.FormattingEnabled = true; // parentNameComboBox
this.parentNameComboBox.Location = new System.Drawing.Point(138, 78); //
this.parentNameComboBox.Name = "parentNameComboBox"; this.parentNameComboBox.Enabled = false;
this.parentNameComboBox.Size = new System.Drawing.Size(130, 21); this.parentNameComboBox.FormattingEnabled = true;
this.parentNameComboBox.TabIndex = 4; this.parentNameComboBox.Location = new System.Drawing.Point(138, 78);
// this.parentNameComboBox.Name = "parentNameComboBox";
// ComponentCfgCtrl this.parentNameComboBox.Size = new System.Drawing.Size(130, 21);
// this.parentNameComboBox.TabIndex = 4;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); //
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; // watchdogCheckBox
this.Controls.Add(this.parentNameComboBox); //
this.Controls.Add(this.modbusAddressTextBox); this.watchdogCheckBox.AutoSize = true;
this.Controls.Add(this.modbusAddressLabel); this.watchdogCheckBox.Enabled = false;
this.Controls.Add(this.parentNameLabel); this.watchdogCheckBox.Location = new System.Drawing.Point(31, 131);
this.Controls.Add(this.nameTextBox); this.watchdogCheckBox.Name = "watchdogCheckBox";
this.Controls.Add(this.nameLabel); this.watchdogCheckBox.Size = new System.Drawing.Size(99, 17);
this.Controls.Add(this.componentNameLabel); this.watchdogCheckBox.TabIndex = 9;
this.Name = "ComponentCfgCtrl"; this.watchdogCheckBox.Text = "Watchdog \'ON\'";
this.Size = new System.Drawing.Size(300, 200); this.watchdogCheckBox.UseVisualStyleBackColor = true;
this.Load += new System.EventHandler(this.QuidoRSCfgCtrl_Load); //
this.ResumeLayout(false); // watchdogBitNrTextBox
this.PerformLayout(); //
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);
this.Controls.Add(this.parentNameLabel);
this.Controls.Add(this.nameTextBox);
this.Controls.Add(this.nameLabel);
this.Controls.Add(this.componentNameLabel);
this.Name = "QuidoRSCfgCtrl";
this.Size = new System.Drawing.Size(300, 200);
this.Load += new System.EventHandler(this.QuidoRSCfgCtrl_Load);
this.ResumeLayout(false);
this.PerformLayout();
} }
@@ -129,5 +163,8 @@ namespace TBF.BenchControl.Modbus.QuidoRS
private System.Windows.Forms.Label modbusAddressLabel; private System.Windows.Forms.Label modbusAddressLabel;
private System.Windows.Forms.TextBox modbusAddressTextBox; private System.Windows.Forms.TextBox modbusAddressTextBox;
private System.Windows.Forms.ComboBox parentNameComboBox; private System.Windows.Forms.ComboBox parentNameComboBox;
private System.Windows.Forms.CheckBox watchdogCheckBox;
private System.Windows.Forms.TextBox watchdogBitNrTextBox;
private System.Windows.Forms.Label watchdogBitNrLabel;
} }
} }