PreviousRoi parameter added to RoiCfg, masks prepared at the very last moment in RoiDetectionOp, Event.RoiDetectionPreviousFailed added.
This commit is contained in:
@@ -158,6 +158,7 @@ namespace TBF.BenchControl
|
||||
CameraOpFailed,
|
||||
RoiDetectionPassed,
|
||||
RoiDetectionFailed,
|
||||
RoiDetectionPreviousFailed,
|
||||
|
||||
/// Generic
|
||||
Error, /// Many ops.: Fatal error occurred
|
||||
|
||||
@@ -18,14 +18,15 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
|
||||
protected readonly RoiCfg roiCfg;
|
||||
|
||||
readonly CLP1611.Camera camera;
|
||||
readonly Telnet.TelnetClient telnet;
|
||||
public readonly CLP1611.Camera Camera;
|
||||
public readonly Telnet.TelnetClient Telnet;
|
||||
public readonly Roi PreviousRoi;
|
||||
|
||||
|
||||
Boxes.IntBox oroiX;
|
||||
Boxes.IntBox oroiY;
|
||||
Boxes.IntBox oroiWid;
|
||||
Boxes.IntBox oroiHgh;
|
||||
public bool Detected;
|
||||
public Boxes.IntBox RoiX;
|
||||
public Boxes.IntBox RoiY;
|
||||
public Boxes.IntBox RoiWid;
|
||||
public Boxes.IntBox RoiHgh;
|
||||
|
||||
|
||||
public Roi()
|
||||
@@ -36,23 +37,25 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
: base(cfg)
|
||||
{
|
||||
roiCfg = cfg as RoiCfg;
|
||||
camera = TbfComponents.FindComponent(cfg.ParentName, components) as CLP1611.Camera;
|
||||
if (camera != null) telnet = camera.Telnet;
|
||||
Camera = TbfComponents.FindComponent(cfg.ParentName, components) as CLP1611.Camera;
|
||||
if (Camera != null) Telnet = Camera.Telnet;
|
||||
|
||||
oroiX = new Boxes.IntBox();
|
||||
oroiY = new Boxes.IntBox();
|
||||
oroiWid = new Boxes.IntBox();
|
||||
oroiHgh = new Boxes.IntBox();
|
||||
PreviousRoi = TbfComponents.FindComponent(roiCfg.PreviousRoi, components) as Roi;
|
||||
|
||||
Detected = false;
|
||||
RoiX = new Boxes.IntBox();
|
||||
RoiY = new Boxes.IntBox();
|
||||
RoiWid = new Boxes.IntBox();
|
||||
RoiHgh = new Boxes.IntBox();
|
||||
|
||||
log.Debug(this.ToString());
|
||||
}
|
||||
|
||||
public IOperation RoiDetectionOp()
|
||||
{
|
||||
if (camera != null && telnet != null)
|
||||
if (Camera != null && Telnet != null)
|
||||
{
|
||||
return new RoiDetectionOp(this, camera, telnet, string.Format("clp/RoiDetection {0}", roiCfg.Args),
|
||||
oroiX, oroiY, oroiWid, oroiHgh);
|
||||
return new RoiDetectionOp(this, roiCfg.Args, RoiX, RoiY, RoiWid, RoiHgh);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
///
|
||||
/// Serialized parameters
|
||||
///
|
||||
public string PreviousRoi;
|
||||
public string Args;
|
||||
|
||||
/// Private parameterless constructor invoked by all other (public) constructors
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
parent = ParentForm as ComponentParametersDlg;
|
||||
if (parent == null) return;
|
||||
|
||||
previousRoiComboBox.Items.Add("---");
|
||||
if (parent.TbfComponents != null)
|
||||
{
|
||||
foreach (var cmpnt in parent.TbfComponents)
|
||||
@@ -45,6 +46,10 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
{
|
||||
parentNameComboBox.Items.Add(cmpnt.Name);
|
||||
}
|
||||
if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is TBF.BenchControl.Network.Camera.Roi.Factory)
|
||||
{
|
||||
previousRoiComboBox.Items.Add(cmpnt.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +67,7 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
classNameLabel.Text = config.Factory.ClassName;
|
||||
nameTextBox.Text = config.Name;
|
||||
parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName;
|
||||
previousRoiComboBox.Text = string.IsNullOrEmpty(config.PreviousRoi) ? "---" : config.PreviousRoi;
|
||||
argsTextBox.Text = config.Args;
|
||||
}
|
||||
|
||||
@@ -69,6 +75,7 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
{
|
||||
nameTextBox.Enabled = true;
|
||||
parentNameComboBox.Enabled = true;
|
||||
previousRoiComboBox.Enabled = true;
|
||||
argsTextBox.Enabled = true;
|
||||
}
|
||||
|
||||
@@ -80,6 +87,7 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
|
||||
config.Name = nameTextBox.Text;
|
||||
config.ParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text;
|
||||
config.PreviousRoi = previousRoiComboBox.Text.Equals("---") ? string.Empty : previousRoiComboBox.Text;
|
||||
config.Args = argsTextBox.Text;
|
||||
|
||||
return flags;
|
||||
@@ -95,6 +103,12 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
message += Environment.NewLine + "Invalid 'Parent Name'";
|
||||
}
|
||||
|
||||
if (!previousRoiComboBox.Items.Contains(previousRoiComboBox.Text))
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "Invalid 'Previous RoI'";
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
}
|
||||
|
||||
+59
-12
@@ -38,23 +38,27 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
this.nameLabel = new System.Windows.Forms.Label();
|
||||
this.classNameLabel = new System.Windows.Forms.Label();
|
||||
this.parentNameComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.textBox1 = new System.Windows.Forms.TextBox();
|
||||
this.previousRoiComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.previousRoiLabel = new System.Windows.Forms.Label();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// argsTextBox
|
||||
//
|
||||
this.argsTextBox.Enabled = false;
|
||||
this.argsTextBox.Location = new System.Drawing.Point(104, 99);
|
||||
this.argsTextBox.Location = new System.Drawing.Point(104, 127);
|
||||
this.argsTextBox.Name = "argsTextBox";
|
||||
this.argsTextBox.Size = new System.Drawing.Size(372, 20);
|
||||
this.argsTextBox.TabIndex = 6;
|
||||
this.argsTextBox.TabIndex = 7;
|
||||
//
|
||||
// argsLabel
|
||||
//
|
||||
this.argsLabel.AutoSize = true;
|
||||
this.argsLabel.Location = new System.Drawing.Point(18, 102);
|
||||
this.argsLabel.Location = new System.Drawing.Point(18, 130);
|
||||
this.argsLabel.Name = "argsLabel";
|
||||
this.argsLabel.Size = new System.Drawing.Size(57, 13);
|
||||
this.argsLabel.TabIndex = 5;
|
||||
this.argsLabel.TabIndex = 6;
|
||||
this.argsLabel.Text = "Arguments";
|
||||
//
|
||||
// parentNameLabel
|
||||
@@ -63,7 +67,7 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
this.parentNameLabel.Location = new System.Drawing.Point(18, 76);
|
||||
this.parentNameLabel.Name = "parentNameLabel";
|
||||
this.parentNameLabel.Size = new System.Drawing.Size(69, 13);
|
||||
this.parentNameLabel.TabIndex = 3;
|
||||
this.parentNameLabel.TabIndex = 2;
|
||||
this.parentNameLabel.Text = "Parent Name";
|
||||
//
|
||||
// nameTextBox
|
||||
@@ -71,8 +75,8 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
this.nameTextBox.Enabled = false;
|
||||
this.nameTextBox.Location = new System.Drawing.Point(104, 47);
|
||||
this.nameTextBox.Name = "nameTextBox";
|
||||
this.nameTextBox.Size = new System.Drawing.Size(130, 20);
|
||||
this.nameTextBox.TabIndex = 2;
|
||||
this.nameTextBox.Size = new System.Drawing.Size(174, 20);
|
||||
this.nameTextBox.TabIndex = 1;
|
||||
//
|
||||
// nameLabel
|
||||
//
|
||||
@@ -80,7 +84,7 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
this.nameLabel.Location = new System.Drawing.Point(18, 50);
|
||||
this.nameLabel.Name = "nameLabel";
|
||||
this.nameLabel.Size = new System.Drawing.Size(35, 13);
|
||||
this.nameLabel.TabIndex = 1;
|
||||
this.nameLabel.TabIndex = 0;
|
||||
this.nameLabel.Text = "Name";
|
||||
//
|
||||
// classNameLabel
|
||||
@@ -98,21 +102,60 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
this.parentNameComboBox.FormattingEnabled = true;
|
||||
this.parentNameComboBox.Location = new System.Drawing.Point(104, 73);
|
||||
this.parentNameComboBox.Name = "parentNameComboBox";
|
||||
this.parentNameComboBox.Size = new System.Drawing.Size(130, 21);
|
||||
this.parentNameComboBox.TabIndex = 4;
|
||||
this.parentNameComboBox.Size = new System.Drawing.Size(174, 21);
|
||||
this.parentNameComboBox.TabIndex = 3;
|
||||
//
|
||||
// RoICfgCtrl
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(-211, -147);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(57, 13);
|
||||
this.label1.TabIndex = 5;
|
||||
this.label1.Text = "Arguments";
|
||||
//
|
||||
// textBox1
|
||||
//
|
||||
this.textBox1.Enabled = false;
|
||||
this.textBox1.Location = new System.Drawing.Point(-125, -150);
|
||||
this.textBox1.Name = "textBox1";
|
||||
this.textBox1.Size = new System.Drawing.Size(372, 20);
|
||||
this.textBox1.TabIndex = 6;
|
||||
//
|
||||
// previousRoiComboBox
|
||||
//
|
||||
this.previousRoiComboBox.Enabled = false;
|
||||
this.previousRoiComboBox.FormattingEnabled = true;
|
||||
this.previousRoiComboBox.Location = new System.Drawing.Point(104, 100);
|
||||
this.previousRoiComboBox.Name = "previousRoiComboBox";
|
||||
this.previousRoiComboBox.Size = new System.Drawing.Size(174, 21);
|
||||
this.previousRoiComboBox.TabIndex = 5;
|
||||
//
|
||||
// previousRoiLabel
|
||||
//
|
||||
this.previousRoiLabel.AutoSize = true;
|
||||
this.previousRoiLabel.Location = new System.Drawing.Point(18, 103);
|
||||
this.previousRoiLabel.Name = "previousRoiLabel";
|
||||
this.previousRoiLabel.Size = new System.Drawing.Size(68, 13);
|
||||
this.previousRoiLabel.TabIndex = 4;
|
||||
this.previousRoiLabel.Text = "Previous RoI";
|
||||
//
|
||||
// RoiCfgCtrl
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.Controls.Add(this.previousRoiComboBox);
|
||||
this.Controls.Add(this.previousRoiLabel);
|
||||
this.Controls.Add(this.parentNameComboBox);
|
||||
this.Controls.Add(this.textBox1);
|
||||
this.Controls.Add(this.argsTextBox);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.argsLabel);
|
||||
this.Controls.Add(this.parentNameLabel);
|
||||
this.Controls.Add(this.nameTextBox);
|
||||
this.Controls.Add(this.nameLabel);
|
||||
this.Controls.Add(this.classNameLabel);
|
||||
this.Name = "RoICfgCtrl";
|
||||
this.Name = "RoiCfgCtrl";
|
||||
this.Size = new System.Drawing.Size(500, 300);
|
||||
this.Load += new System.EventHandler(this.PumpCfgCtrl_Load);
|
||||
this.ResumeLayout(false);
|
||||
@@ -129,5 +172,9 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
private System.Windows.Forms.Label nameLabel;
|
||||
private System.Windows.Forms.Label classNameLabel;
|
||||
private System.Windows.Forms.ComboBox parentNameComboBox;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.TextBox textBox1;
|
||||
private System.Windows.Forms.ComboBox previousRoiComboBox;
|
||||
private System.Windows.Forms.Label previousRoiLabel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,18 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
{
|
||||
public class RoiDetectionOp : IOperation
|
||||
{
|
||||
readonly Roi roi;
|
||||
readonly CLP1611.Camera camera;
|
||||
readonly Telnet.TelnetClient telnet;
|
||||
readonly string command;
|
||||
readonly string args;
|
||||
|
||||
string command;
|
||||
bool roiDetectionCommandSent;
|
||||
|
||||
string response;
|
||||
bool passed;
|
||||
bool failed;
|
||||
bool previousFailed;
|
||||
|
||||
Boxes.IntBox oroiX;
|
||||
Boxes.IntBox oroiY;
|
||||
@@ -25,34 +28,29 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
/// Events: Event.None or Event.Error
|
||||
/// </summary>
|
||||
/// <param name="camera">CLP1611.Camera reference</param>
|
||||
public RoiDetectionOp(Roi roi, CLP1611.Camera camera, Telnet.TelnetClient telnet, string command,
|
||||
Boxes.IntBox oroiX,
|
||||
Boxes.IntBox oroiY,
|
||||
Boxes.IntBox oroiWid,
|
||||
Boxes.IntBox oroiHgh)
|
||||
public RoiDetectionOp(Roi roi, string args, Boxes.IntBox oroiX, Boxes.IntBox oroiY,
|
||||
Boxes.IntBox oroiWid, Boxes.IntBox oroiHgh)
|
||||
{
|
||||
this.camera = camera;
|
||||
this.telnet = telnet;
|
||||
this.command = command;
|
||||
this.roi = roi;
|
||||
this.camera = roi.Camera;
|
||||
this.telnet = roi.Telnet;
|
||||
this.args = args;
|
||||
this.oroiX = oroiX;
|
||||
this.oroiY = oroiY;
|
||||
this.oroiWid = oroiWid;
|
||||
this.oroiHgh = oroiHgh;
|
||||
|
||||
roiDetectionCommandSent = false;
|
||||
response = null;
|
||||
passed = false;
|
||||
failed = false;
|
||||
|
||||
telnet.promptReceivedHandler += delegate(object sndr, PromptReceivedEventArgs args)
|
||||
telnet.promptReceivedHandler += delegate(object sndr, PromptReceivedEventArgs a)
|
||||
{
|
||||
OnPromptReceived(sndr, args);
|
||||
OnPromptReceived(sndr, a);
|
||||
};
|
||||
}
|
||||
|
||||
void OnPromptReceived(object sndr, PromptReceivedEventArgs args)
|
||||
void OnPromptReceived(object sndr, PromptReceivedEventArgs a)
|
||||
{
|
||||
response = args.Response;
|
||||
response = a.Response;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
@@ -66,23 +64,46 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
{
|
||||
if (telnet.State == TelnetClient.TelnetState.Inactive)
|
||||
{
|
||||
return Event.Busy;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// State variables
|
||||
//
|
||||
response = null;
|
||||
passed = false;
|
||||
failed = false;
|
||||
previousFailed = false;
|
||||
|
||||
//
|
||||
// Prepare command
|
||||
//
|
||||
string masks = string.Empty;
|
||||
Roi previous = roi.PreviousRoi;
|
||||
int maskLevel = 0;
|
||||
while (previous != null && maskLevel++ < 3)
|
||||
{
|
||||
if (!previous.Detected)
|
||||
{
|
||||
previousFailed = true;
|
||||
return Event.RoiDetectionPreviousFailed;
|
||||
}
|
||||
|
||||
masks += string.Format(" -m {0} {1} {2} {3}", previous.RoiX.Val, previous.RoiY.Val,
|
||||
previous.RoiWid.Val, previous.RoiHgh.Val);
|
||||
previous = previous.PreviousRoi;
|
||||
}
|
||||
command = string.Format("clp/RoiDetection{0} {1}", masks, args);
|
||||
|
||||
//
|
||||
// Send (or enqueue) command
|
||||
//
|
||||
telnet.Enqueue(new Telnet.Command(Telnet.CmdAction.CLEAR_RESPONSE));
|
||||
telnet.Enqueue(new Telnet.Command(Telnet.CmdAction.SEND_COMMAND, command));
|
||||
roiDetectionCommandSent = true;
|
||||
return Event.Busy;
|
||||
}
|
||||
|
||||
return Event.Busy;
|
||||
}
|
||||
else if (passed)
|
||||
{
|
||||
return Event.RoiDetectionPassed;
|
||||
}
|
||||
else if (failed)
|
||||
{
|
||||
return Event.RoiDetectionFailed;
|
||||
}
|
||||
else if (response != null)
|
||||
{
|
||||
@@ -116,6 +137,18 @@ namespace TBF.BenchControl.Network.Camera.Roi
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (passed)
|
||||
{
|
||||
return Event.RoiDetectionPassed;
|
||||
}
|
||||
else if (failed)
|
||||
{
|
||||
return Event.RoiDetectionFailed;
|
||||
}
|
||||
else if (previousFailed)
|
||||
{
|
||||
return Event.RoiDetectionPreviousFailed;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Event.Busy;
|
||||
|
||||
Reference in New Issue
Block a user