Work in progress: Diverter calibration
This commit is contained in:
@@ -18,7 +18,6 @@ namespace TBF.BenchControl.Elde.Diverter
|
||||
get { return (controlBoard.Route & mask) != 0; }
|
||||
}
|
||||
|
||||
|
||||
public Diverter(DiverterCfg cfg, IList<Generic.IComponent> components)
|
||||
: base(cfg)
|
||||
{
|
||||
@@ -30,7 +29,59 @@ namespace TBF.BenchControl.Elde.Diverter
|
||||
if (cfg.BitPosition < 0 || cfg.BitPosition >= 64) throw new ArgumentOutOfRangeException("position");
|
||||
this.mask = (((ulong)1) << cfg.BitPosition);
|
||||
|
||||
/// Prepare data for SendCalibData() control board component method
|
||||
controlBoard.DiverterEdge[0] = (uint)diverterCfg.StartingEdge;
|
||||
controlBoard.DiverterEdge[1] = (uint)diverterCfg.StoppingEdge;
|
||||
|
||||
log.Debug(this.ToString());
|
||||
}
|
||||
|
||||
|
||||
#region Configuration Change Handling
|
||||
|
||||
public static void OnCfgChange(object sender, CfgChangeArgs args)
|
||||
{
|
||||
if (CfgChangeHandler == null) return;
|
||||
try { CfgChangeHandler(sender, args); }
|
||||
catch (Exception e) { log.Error("CfgChangeHandler(...) failed", e); }
|
||||
}
|
||||
|
||||
public static event EventHandler<CfgChangeArgs> CfgChangeHandler;
|
||||
|
||||
public override void StartChangeHandler()
|
||||
{
|
||||
CfgChangeHandler += delegate(object sender, CfgChangeArgs args)
|
||||
{
|
||||
DiverterCfg tmpcfg = args.Cfg as DiverterCfg;
|
||||
if (tmpcfg != null && tmpcfg.Name.Equals(Name))
|
||||
{
|
||||
if (args.Command == CfgChangeCmd.CfgChange)
|
||||
{
|
||||
//diverterCfg.StableTimeMs = tmpcfg.StableTimeMs;
|
||||
//diverterCfg.FlowStableSec = tmpcfg.FlowStableSec;
|
||||
}
|
||||
//else if (args.Command == CfgChangeCmd.RVOpenStep)
|
||||
//{
|
||||
// controlBoard.ValveMove(Idx1, RegulValveMode.PulseWidth, new float[2] { 2.0f, 2.0f }, StableTime);
|
||||
// // TODO: avoid conflicts
|
||||
// // TOTEST
|
||||
//}
|
||||
//else if (args.Command == CfgChangeCmd.RVCloseStep)
|
||||
//{
|
||||
// controlBoard.ValveMove(Idx1, RegulValveMode.PulseWidth, new float[2] { -2.0f, -2.0f }, StableTime);
|
||||
// // TODO: avoid conflicts
|
||||
// // TOTEST
|
||||
//}
|
||||
//else if (args.Command == CfgChangeCmd.GetRVAdc1 || args.Command == CfgChangeCmd.GetRVAdc2)
|
||||
//{
|
||||
// int adc = (int)controlBoard.AnalogInputRaw(Idx1 - 1, 0);
|
||||
// // TOTEST
|
||||
// DiverterCfgCtrl.OnCmdResponse(this, new CmdResponseArgs(args.Command, adc));
|
||||
//}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endregion Configuration Change Handling
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,9 @@ namespace TBF.BenchControl.Elde.Diverter
|
||||
///
|
||||
/// Serialized parameters
|
||||
///
|
||||
public int BitPosition;
|
||||
public int BitPosition; /// 0..63
|
||||
public int StartingEdge; /// 0..100 in %, threshold for the ADC value to start the test
|
||||
public int StoppingEdge; /// 0..100 in %, threshold for the ADC value to start the test
|
||||
|
||||
/// Private parameterless constructor invoked by all other (public) constructors
|
||||
DiverterCfg()
|
||||
@@ -21,6 +23,8 @@ namespace TBF.BenchControl.Elde.Diverter
|
||||
Name = "Div";
|
||||
ParentName = "CB";
|
||||
BitPosition = 0;
|
||||
StartingEdge = 50;
|
||||
StoppingEdge = 50;
|
||||
}
|
||||
|
||||
public DiverterCfg(IComponentFactory factory)
|
||||
@@ -31,10 +35,12 @@ namespace TBF.BenchControl.Elde.Diverter
|
||||
|
||||
public string ToString(int i)
|
||||
{
|
||||
return string.Format("Name={0}, Parent={1}, Bit={2}",
|
||||
return string.Format("Name={0}, Parent={1}, Bit={2}, StartEdge={3}%, StopEdge={4}%",
|
||||
Name,
|
||||
(string.IsNullOrEmpty(ParentName) ? "-" : ParentName),
|
||||
BitPosition);
|
||||
BitPosition,
|
||||
StartingEdge,
|
||||
StoppingEdge);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+137
-1
@@ -35,6 +35,17 @@
|
||||
this.bitPositionLabel = new System.Windows.Forms.Label();
|
||||
this.bitPositionTextBox = new System.Windows.Forms.TextBox();
|
||||
this.parentNameComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.startingEdgeTextBox = new System.Windows.Forms.TextBox();
|
||||
this.startingEdgeLabel = new System.Windows.Forms.Label();
|
||||
this.stoppingEdgeTextBox = new System.Windows.Forms.TextBox();
|
||||
this.stoppingEdgeLabel = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.startButton = new System.Windows.Forms.Button();
|
||||
this.stopButton = new System.Windows.Forms.Button();
|
||||
this.leftButton = new System.Windows.Forms.Button();
|
||||
this.rightButton = new System.Windows.Forms.Button();
|
||||
this.updateButton = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// nameTextBox
|
||||
@@ -98,10 +109,124 @@
|
||||
this.parentNameComboBox.Size = new System.Drawing.Size(130, 21);
|
||||
this.parentNameComboBox.TabIndex = 4;
|
||||
//
|
||||
// startingEdgeTextBox
|
||||
//
|
||||
this.startingEdgeTextBox.Enabled = false;
|
||||
this.startingEdgeTextBox.Location = new System.Drawing.Point(137, 118);
|
||||
this.startingEdgeTextBox.Name = "startingEdgeTextBox";
|
||||
this.startingEdgeTextBox.Size = new System.Drawing.Size(46, 20);
|
||||
this.startingEdgeTextBox.TabIndex = 8;
|
||||
//
|
||||
// startingEdgeLabel
|
||||
//
|
||||
this.startingEdgeLabel.AutoSize = true;
|
||||
this.startingEdgeLabel.Location = new System.Drawing.Point(27, 121);
|
||||
this.startingEdgeLabel.Name = "startingEdgeLabel";
|
||||
this.startingEdgeLabel.Size = new System.Drawing.Size(71, 13);
|
||||
this.startingEdgeLabel.TabIndex = 7;
|
||||
this.startingEdgeLabel.Text = "Starting Edge";
|
||||
//
|
||||
// stoppingEdgeTextBox
|
||||
//
|
||||
this.stoppingEdgeTextBox.Enabled = false;
|
||||
this.stoppingEdgeTextBox.Location = new System.Drawing.Point(137, 143);
|
||||
this.stoppingEdgeTextBox.Name = "stoppingEdgeTextBox";
|
||||
this.stoppingEdgeTextBox.Size = new System.Drawing.Size(46, 20);
|
||||
this.stoppingEdgeTextBox.TabIndex = 10;
|
||||
//
|
||||
// stoppingEdgeLabel
|
||||
//
|
||||
this.stoppingEdgeLabel.AutoSize = true;
|
||||
this.stoppingEdgeLabel.Location = new System.Drawing.Point(27, 146);
|
||||
this.stoppingEdgeLabel.Name = "stoppingEdgeLabel";
|
||||
this.stoppingEdgeLabel.Size = new System.Drawing.Size(77, 13);
|
||||
this.stoppingEdgeLabel.TabIndex = 9;
|
||||
this.stoppingEdgeLabel.Text = "Stopping Edge";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(190, 145);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(15, 13);
|
||||
this.label2.TabIndex = 11;
|
||||
this.label2.Text = "%";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(190, 121);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(15, 13);
|
||||
this.label1.TabIndex = 12;
|
||||
this.label1.Text = "%";
|
||||
//
|
||||
// startButton
|
||||
//
|
||||
this.startButton.Location = new System.Drawing.Point(10, 457);
|
||||
this.startButton.Name = "startButton";
|
||||
this.startButton.Size = new System.Drawing.Size(55, 31);
|
||||
this.startButton.TabIndex = 13;
|
||||
this.startButton.Text = "Start";
|
||||
this.startButton.UseVisualStyleBackColor = true;
|
||||
this.startButton.Click += new System.EventHandler(this.startButton_Click);
|
||||
//
|
||||
// stopButton
|
||||
//
|
||||
this.stopButton.Location = new System.Drawing.Point(71, 457);
|
||||
this.stopButton.Name = "stopButton";
|
||||
this.stopButton.Size = new System.Drawing.Size(55, 31);
|
||||
this.stopButton.TabIndex = 14;
|
||||
this.stopButton.Text = "Stop";
|
||||
this.stopButton.UseVisualStyleBackColor = true;
|
||||
this.stopButton.Click += new System.EventHandler(this.stopButton_Click);
|
||||
//
|
||||
// leftButton
|
||||
//
|
||||
this.leftButton.Location = new System.Drawing.Point(132, 457);
|
||||
this.leftButton.Name = "leftButton";
|
||||
this.leftButton.Size = new System.Drawing.Size(31, 31);
|
||||
this.leftButton.TabIndex = 15;
|
||||
this.leftButton.Text = "<--";
|
||||
this.leftButton.UseVisualStyleBackColor = true;
|
||||
this.leftButton.Click += new System.EventHandler(this.leftButton_Click);
|
||||
//
|
||||
// rightButton
|
||||
//
|
||||
this.rightButton.Location = new System.Drawing.Point(169, 457);
|
||||
this.rightButton.Name = "rightButton";
|
||||
this.rightButton.Size = new System.Drawing.Size(31, 31);
|
||||
this.rightButton.TabIndex = 16;
|
||||
this.rightButton.Text = "-->";
|
||||
this.rightButton.UseVisualStyleBackColor = true;
|
||||
this.rightButton.Click += new System.EventHandler(this.rightButton_Click);
|
||||
//
|
||||
// updateButton
|
||||
//
|
||||
this.updateButton.Enabled = false;
|
||||
this.updateButton.Location = new System.Drawing.Point(206, 457);
|
||||
this.updateButton.Name = "updateButton";
|
||||
this.updateButton.Size = new System.Drawing.Size(85, 31);
|
||||
this.updateButton.TabIndex = 17;
|
||||
this.updateButton.Text = "Update Edge";
|
||||
this.updateButton.UseVisualStyleBackColor = true;
|
||||
this.updateButton.Click += new System.EventHandler(this.updateButton_Click);
|
||||
//
|
||||
// DiverterCfgCtrl
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.Controls.Add(this.updateButton);
|
||||
this.Controls.Add(this.rightButton);
|
||||
this.Controls.Add(this.leftButton);
|
||||
this.Controls.Add(this.stopButton);
|
||||
this.Controls.Add(this.startButton);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.stoppingEdgeTextBox);
|
||||
this.Controls.Add(this.stoppingEdgeLabel);
|
||||
this.Controls.Add(this.startingEdgeTextBox);
|
||||
this.Controls.Add(this.startingEdgeLabel);
|
||||
this.Controls.Add(this.parentNameComboBox);
|
||||
this.Controls.Add(this.bitPositionTextBox);
|
||||
this.Controls.Add(this.bitPositionLabel);
|
||||
@@ -110,7 +235,7 @@
|
||||
this.Controls.Add(this.nameLabel);
|
||||
this.Controls.Add(this.classNameLabel);
|
||||
this.Name = "DiverterCfgCtrl";
|
||||
this.Size = new System.Drawing.Size(300, 200);
|
||||
this.Size = new System.Drawing.Size(300, 500);
|
||||
this.Load += new System.EventHandler(this.DiverterCfgCtrl_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
@@ -126,5 +251,16 @@
|
||||
private System.Windows.Forms.Label bitPositionLabel;
|
||||
private System.Windows.Forms.TextBox bitPositionTextBox;
|
||||
private System.Windows.Forms.ComboBox parentNameComboBox;
|
||||
private System.Windows.Forms.TextBox startingEdgeTextBox;
|
||||
private System.Windows.Forms.Label startingEdgeLabel;
|
||||
private System.Windows.Forms.TextBox stoppingEdgeTextBox;
|
||||
private System.Windows.Forms.Label stoppingEdgeLabel;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.Button startButton;
|
||||
private System.Windows.Forms.Button stopButton;
|
||||
private System.Windows.Forms.Button leftButton;
|
||||
private System.Windows.Forms.Button rightButton;
|
||||
private System.Windows.Forms.Button updateButton;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace TBF.BenchControl.Elde.Diverter
|
||||
|
||||
ComponentParametersDlg parent;
|
||||
|
||||
public bool ShowMore { get { return false; } }
|
||||
public bool ShowMore { get { return true; } }
|
||||
|
||||
DiverterCfg config;
|
||||
public IComponentCfg Config
|
||||
@@ -45,11 +45,18 @@ namespace TBF.BenchControl.Elde.Diverter
|
||||
}
|
||||
}
|
||||
|
||||
if (config != null)
|
||||
{
|
||||
/// TODO
|
||||
}
|
||||
|
||||
Redraw();
|
||||
StartResponseHandler();
|
||||
}
|
||||
|
||||
public void Closing()
|
||||
{
|
||||
StopResponseHandler();
|
||||
}
|
||||
|
||||
void Redraw()
|
||||
@@ -60,6 +67,8 @@ namespace TBF.BenchControl.Elde.Diverter
|
||||
parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName;
|
||||
nameTextBox.Text = config.Name;
|
||||
bitPositionTextBox.Text = config.BitPosition.ToString();
|
||||
startingEdgeTextBox.Text = config.StartingEdge.ToString();
|
||||
stoppingEdgeTextBox.Text = config.StoppingEdge.ToString();
|
||||
}
|
||||
|
||||
public void Unlock()
|
||||
@@ -67,6 +76,8 @@ namespace TBF.BenchControl.Elde.Diverter
|
||||
nameTextBox.Enabled = true;
|
||||
parentNameComboBox.Enabled = true;
|
||||
bitPositionTextBox.Enabled = true;
|
||||
startingEdgeTextBox.Enabled = true;
|
||||
stoppingEdgeTextBox.Enabled = true;
|
||||
}
|
||||
|
||||
public CfgUpdateFlags VerifyCfg(ref string message)
|
||||
@@ -84,6 +95,16 @@ namespace TBF.BenchControl.Elde.Diverter
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "'Bit Position' should be between 0 and 63";
|
||||
}
|
||||
if (!int.TryParse(startingEdgeTextBox.Text, out dummy) || dummy < 0 || dummy > 100)
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "'Starting Edge' should be between 0 and 100";
|
||||
}
|
||||
if (!int.TryParse(stoppingEdgeTextBox.Text, out dummy) || dummy < 0 || dummy > 100)
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "'Stopping Edge' should be between 0 and 100";
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
@@ -96,8 +117,94 @@ namespace TBF.BenchControl.Elde.Diverter
|
||||
config.Name = nameTextBox.Text;
|
||||
config.ParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text;
|
||||
config.BitPosition = int.Parse(bitPositionTextBox.Text);
|
||||
config.StartingEdge = int.Parse(startingEdgeTextBox.Text);
|
||||
config.StoppingEdge = int.Parse(stoppingEdgeTextBox.Text);
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Do some stuff here
|
||||
///
|
||||
enum EdgeSel { NoEdge, StartEdge, StopEdge };
|
||||
EdgeSel lastTestedEdge = EdgeSel.NoEdge;
|
||||
int cursorPosition = 0;
|
||||
int currentEdgeLevel = 50; /// Edge level 0..100 in %
|
||||
|
||||
private void startButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
lastTestedEdge = EdgeSel.StartEdge;
|
||||
updateButton.Enabled = true;
|
||||
}
|
||||
|
||||
private void stopButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
lastTestedEdge = EdgeSel.StopEdge;
|
||||
updateButton.Enabled = true;
|
||||
|
||||
}
|
||||
|
||||
private void leftButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (currentEdgeLevel > 0) currentEdgeLevel--;
|
||||
}
|
||||
|
||||
private void rightButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (currentEdgeLevel < 100) currentEdgeLevel++;
|
||||
}
|
||||
|
||||
private void updateButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
switch (lastTestedEdge)
|
||||
{
|
||||
case EdgeSel.StartEdge:
|
||||
startingEdgeTextBox.Text = currentEdgeLevel.ToString();
|
||||
break;
|
||||
case EdgeSel.StopEdge:
|
||||
stoppingEdgeTextBox.Text = currentEdgeLevel.ToString();
|
||||
break;
|
||||
case EdgeSel.NoEdge:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region Configuration Change Handling
|
||||
|
||||
public static void OnCmdResponse(object sender, CmdResponseArgs args)
|
||||
{
|
||||
if (CmdResponseHandler == null) return;
|
||||
try { CmdResponseHandler(sender, args); }
|
||||
catch (Exception e) { log.Error("CmdResponseHandler(...) failed", e); }
|
||||
}
|
||||
|
||||
public static event EventHandler<CmdResponseArgs> CmdResponseHandler;
|
||||
|
||||
public void StartResponseHandler()
|
||||
{
|
||||
CmdResponseHandler += delegate(object sender, CmdResponseArgs args)
|
||||
{
|
||||
//if (args.Command == CfgChangeCmd.GetRVAdc1)
|
||||
//{
|
||||
// adc1 = args.Response;
|
||||
// adcTextBox1.Text = adc1.ToString();
|
||||
//}
|
||||
//else if (args.Command == CfgChangeCmd.GetRVAdc2)
|
||||
//{
|
||||
// adc2 = args.Response;
|
||||
// adcTextBox2.Text = adc2.ToString();
|
||||
//}
|
||||
};
|
||||
}
|
||||
|
||||
public void StopResponseHandler()
|
||||
{
|
||||
CmdResponseHandler = null;
|
||||
}
|
||||
|
||||
#endregion Configuration Change Handling
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user