Cleanup : IdcCamera and RoI archaic code removed.

This commit is contained in:
Milan Hanajik
2017-01-14 21:09:57 +01:00
parent 6e9bfb61cc
commit e34fc6a1f2
46 changed files with 25 additions and 4568 deletions
@@ -1,115 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Threading;
using log4net;
using Config.Entities;
using TBF.BenchControl;
using TBF.BenchControl.Generic;
using TBF.Boxes;
namespace TBF.BenchControl.Cameras.CameraRoi
{
/// <summary>
/// IdcCamera object represents all IDC cameras.
/// Camera ID is an argument of most methods.
/// </summary>
public class CameraRoi : ComponentBase, GenericDevices.ICameraRoi, GenericDevices.IRegisterReader
{
private static readonly ILog log = LogManager.GetLogger(typeof(CameraRoi));
public override string ToString() { return string.Format("CameraRoi({0})", Cfg.ToString(1)); }
readonly CameraRoiCfg cameraRoiCfg;
readonly GenericDevices.ICamera camera;
public GenericDevices.ICamera Camera { get { return camera; } }
public double PulsesPerLtr { get { return (double)cameraRoiCfg.ProcParams.GradPerLtr; } }
public double LtrsPerPulse { get { return ltrsPerPulse; } }
readonly double ltrsPerPulse;
public int WMPulses { get { return wmPulses; } }
public int WMRefPulses { get { return wmRefPulses; } }
public double WMVolume { get { return ltrsPerPulse * (double)wmPulses; } }
public int wmPulses;
public int wmRefPulses;
public CameraRoi()
{
}
public CameraRoi(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
: base(cfg)
{
cameraRoiCfg = cfg as CameraRoiCfg;
ltrsPerPulse = (PulsesPerLtr <= float.Epsilon) ? 0 : (1 / PulsesPerLtr);
if (cfg.DebugLevel != DebugMode.Off)
{
camera = TbfComponents.FindComponent(cfg.ParentName, components) as GenericDevices.ICamera;
if ((camera == null) && (cfg.DebugLevel != DebugMode.Inherit))
{
throw new Exception("Cannot find " + Name + " parent");
}
}
log.Debug(this.ToString());
}
public void Clear()
{
wmPulses = 0;
wmRefPulses = 0;
}
public void TestCompleted()
{
/// TODO: Implement
}
/// <summary>
/// Events: Event.ReadRegisterDone, Event.Error
/// </summary>
/// <param name="pulses">Reference to a variable for the water meter pulses</param>
/// <returns>ReadWaterMeter instance reference casted to IOperaton</returns>
public IOperation ReadRegisterOp()
{
return new ReadRegisterOp(this);
}
/// <summary>
/// Watermeter wheel/arrow detection process.
/// </summary>
/// <param name="roiId">Region of interest (1..4)</param>
/// <returns>Reference to operation object instance</returns>
public IOperation DetectOp()
{
RoiProcedureParams pp = cameraRoiCfg.ProcParams;
return camera.DetectOp(cameraRoiCfg.RoiNr,
new Cameras.IdcCamera.Command.Detect(cameraRoiCfg.RoiNr, 0, pp.IRoiX, pp.IRoiY, pp.IRoiW, pp.IRoiH,
pp.CX, pp.CY, pp.ORoiW, pp.ORoiH, pp.R1, pp.R2, pp.R3,
pp.Ang1, pp.Ang2, pp.AngStep, pp.CCW, (pp.CCW ? -30 : 30),
pp.SequenceLen, pp.SequenceTiming, pp.BackgroundCorr,
pp.BrightnessRoi * camera.Brightness));
}
/// <summary>
/// Watermeter wheel/arrow angle measurement process.
/// </summary>
/// <param name="roiId">Region of interest (1..4)</param>
/// <returns>Reference to operation object instance</returns>
public IOperation MeasureOp()
{
RoiProcedureParams pp = cameraRoiCfg.ProcParams;
return camera.MeasureOp(cameraRoiCfg.RoiNr,
new Cameras.IdcCamera.Command.Measure(cameraRoiCfg.RoiNr, true, 0, pp.IRoiX, pp.IRoiY, pp.IRoiW, pp.IRoiH,
pp.CX, pp.CY, pp.ORoiW, pp.ORoiH, pp.MinMvmt, pp.MaxMvmt,
pp.BrightnessRoi * camera.Brightness));
}
}
}
@@ -1,60 +0,0 @@
///
/// Copyright (c) 2013-2016 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Ports;
using System.Xml.Serialization;
using Config.Entities;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Cameras.CameraRoi
{
public class CameraRoiCfg : ComponentCfgBase, IChildComponentCfg
{
public IComponentCfgCtrl GetControl() { return new CameraRoiCfgCtrl(); }
///
/// Serialized parameters
///
public int RoiNr; /// ROI number 1..4
///
/// Procedure parameters
///
[XmlIgnore]
public RoiProcedureParams ProcParams;
public override IParamsProvider GetProcedureParams() { return ProcParams; }
public override IParamsProvider CreateProcedureParams(Procedure procedure)
{
RoiProcedureParams procParams = new RoiProcedureParams();
procParams.UpdateProcedureParams(Name, procedure);
return procParams;
}
/// Private parameterless constructor invoked by all other (public) constructors
CameraRoiCfg()
{
Name = "ROI";
ParentName = "Idc";
ProcParams = new RoiProcedureParams();
RoiNr = 1;
}
public CameraRoiCfg(IComponentFactory factory)
: this()
{
this.Factory = factory;
}
public string ToString(int i)
{
return string.Format("Name={0}, Parent={1}, Roi={2}",
Name,
(string.IsNullOrEmpty(ParentName) ? "-" : ParentName),
RoiNr);
}
}
}
@@ -1,110 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using System.Windows.Forms;
using System.IO.Ports;
using log4net;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Cameras.CameraRoi
{
public partial class CameraRoiCfgCtrl : UserControl, IComponentCfgCtrl
{
static readonly ILog log = LogManager.GetLogger(typeof(CameraRoiCfgCtrl));
ComponentParametersDlg parent;
public bool ShowMore { get { return false; } }
CameraRoiCfg config;
public IComponentCfg Config
{
get { return config as IComponentCfg; }
set
{
config = value as CameraRoiCfg;
Redraw();
}
}
public CameraRoiCfgCtrl()
{
InitializeComponent();
}
private void IdcCameraCfgCtrl_Load(object sender, EventArgs e)
{
parent = ParentForm as ComponentParametersDlg;
if (parent == null) return;
if (parent.TbfComponents != null)
{
parentNameComboBox.Items.Add("---");
foreach (var cmpnt in parent.TbfComponents)
{
if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is BenchControl.Cameras.IdcCamera.IdcCameraFactory)
{
parentNameComboBox.Items.Add(cmpnt.Name);
}
}
}
Redraw();
}
public void Closing()
{
}
void Redraw()
{
if (config == null) return; /// Control was not loaded, settings were not changed
classNameLabel.Text = config.Factory.ClassName;
nameTextBox.Text = config.Name;
parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName;
roiTextBox.Text = config.RoiNr.ToString();
}
public void Unlock()
{
nameTextBox.Enabled = true;
parentNameComboBox.Enabled = true;
roiTextBox.Enabled = true;
}
public CfgUpdateFlags VerifyCfg(ref string message)
{
CfgUpdateFlags flags = CfgUpdateFlags.None;
if (!parentNameComboBox.Items.Contains(parentNameComboBox.Text))
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "Invalid 'Parent Name'";
}
int dummy;
if (!int.TryParse(roiTextBox.Text, out dummy) || dummy < 1 || dummy > 4)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Region of Interest' is not valid";
}
return flags;
}
public CfgUpdateFlags UpdateCfg()
{
CfgUpdateFlags flags = CfgUpdateFlags.RestartRqrd;
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
config.Name = nameTextBox.Text;
config.ParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text;
config.RoiNr = int.Parse(roiTextBox.Text);
return flags;
}
}
}
@@ -1,133 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
namespace TBF.BenchControl.Cameras.CameraRoi
{
partial class CameraRoiCfgCtrl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.nameTextBox = new System.Windows.Forms.TextBox();
this.nameLabel = new System.Windows.Forms.Label();
this.classNameLabel = new System.Windows.Forms.Label();
this.roiTextBox = new System.Windows.Forms.TextBox();
this.roiLabel = new System.Windows.Forms.Label();
this.parentNameComboBox = new System.Windows.Forms.ComboBox();
this.parentNameLabel = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// nameTextBox
//
this.nameTextBox.Enabled = false;
this.nameTextBox.Location = new System.Drawing.Point(138, 72);
this.nameTextBox.Name = "nameTextBox";
this.nameTextBox.Size = new System.Drawing.Size(130, 20);
this.nameTextBox.TabIndex = 2;
//
// nameLabel
//
this.nameLabel.AutoSize = true;
this.nameLabel.Location = new System.Drawing.Point(28, 75);
this.nameLabel.Name = "nameLabel";
this.nameLabel.Size = new System.Drawing.Size(35, 13);
this.nameLabel.TabIndex = 1;
this.nameLabel.Text = "Name";
//
// classNameLabel
//
this.classNameLabel.AutoSize = true;
this.classNameLabel.Location = new System.Drawing.Point(135, 46);
this.classNameLabel.Name = "classNameLabel";
this.classNameLabel.Size = new System.Drawing.Size(89, 13);
this.classNameLabel.TabIndex = 0;
this.classNameLabel.Text = "ComponentName";
//
// roiTextBox
//
this.roiTextBox.Enabled = false;
this.roiTextBox.Location = new System.Drawing.Point(138, 121);
this.roiTextBox.Name = "roiTextBox";
this.roiTextBox.Size = new System.Drawing.Size(80, 20);
this.roiTextBox.TabIndex = 4;
//
// roiLabel
//
this.roiLabel.AutoSize = true;
this.roiLabel.Location = new System.Drawing.Point(28, 124);
this.roiLabel.Name = "roiLabel";
this.roiLabel.Size = new System.Drawing.Size(94, 13);
this.roiLabel.TabIndex = 3;
this.roiLabel.Text = "Region of Interest:";
//
// parentNameComboBox
//
this.parentNameComboBox.Enabled = false;
this.parentNameComboBox.FormattingEnabled = true;
this.parentNameComboBox.Location = new System.Drawing.Point(138, 96);
this.parentNameComboBox.Name = "parentNameComboBox";
this.parentNameComboBox.Size = new System.Drawing.Size(130, 21);
this.parentNameComboBox.TabIndex = 6;
//
// parentNameLabel
//
this.parentNameLabel.AutoSize = true;
this.parentNameLabel.Location = new System.Drawing.Point(28, 99);
this.parentNameLabel.Name = "parentNameLabel";
this.parentNameLabel.Size = new System.Drawing.Size(69, 13);
this.parentNameLabel.TabIndex = 5;
this.parentNameLabel.Text = "Parent Name";
//
// CameraRoiCfgCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.parentNameComboBox);
this.Controls.Add(this.parentNameLabel);
this.Controls.Add(this.nameTextBox);
this.Controls.Add(this.nameLabel);
this.Controls.Add(this.classNameLabel);
this.Controls.Add(this.roiTextBox);
this.Controls.Add(this.roiLabel);
this.Name = "CameraRoiCfgCtrl";
this.Size = new System.Drawing.Size(300, 240);
this.Load += new System.EventHandler(this.IdcCameraCfgCtrl_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox nameTextBox;
private System.Windows.Forms.Label nameLabel;
private System.Windows.Forms.Label classNameLabel;
private System.Windows.Forms.TextBox roiTextBox;
private System.Windows.Forms.Label roiLabel;
private System.Windows.Forms.ComboBox parentNameComboBox;
private System.Windows.Forms.Label parentNameLabel;
}
}
@@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
@@ -1,26 +0,0 @@
///
/// Copyright (c) 2013-2016 Sensus Metering Systems
///
using System.Collections.Generic;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Cameras.CameraRoi
{
public class CameraRoiFactory : IComponentFactory
{
public string ClassName { get { return "CameraROI"; } }
public void ResetStaticProperties() { CameraRoi.ResetStaticProperties(); }
public IComponent DummyComponent() { return new CameraRoi(); }
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new CameraRoi(cfg, components); }
public IComponentCfg DefaultConfig() { return new CameraRoiCfg(this); }
public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component)
{
return ComponentCfgBase.CreateFromDbEntity(typeof(CameraRoiCfg), component, this);
}
}
}
@@ -1,59 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using log4net;
using TBF.Boxes;
namespace TBF.BenchControl.Cameras.CameraRoi
{
public class ReadRegisterOp : IOperation
{
private static readonly ILog log = LogManager.GetLogger(typeof(ReadRegisterOp));
public override string ToString() { return string.Format("ReadRegisterOp({0})", cameraRoi.Cfg.Name); }
/// Set by the constructor
readonly CameraRoi cameraRoi;
readonly BenchControl.Cameras.IdcCamera.IdcCamera camera;
/// <summary>
/// Events: Event.ReadRegisterDone or Event.Error
/// </summary>
/// <param name="reader">Register reader reference</param>
/// <param name="pulses">Reference to a field with the water meter pulses</param>
public ReadRegisterOp(CameraRoi cameraRoi)
{
this.cameraRoi = cameraRoi;
if (cameraRoi == null) throw new ArgumentNullException("reader is null or it is not IdcCamera");
camera = cameraRoi.Camera as BenchControl.Cameras.IdcCamera.IdcCamera;
log.Debug(this.ToString());
}
private void ReadPulses()
{
cameraRoi.wmPulses = camera.Idc100.Pulses;
cameraRoi.wmRefPulses = StateMachine.ControlBoard.EtPulses(0);
}
/// <summary>Start this operation</summary>
public void Start()
{
ReadPulses();
}
/// <summary>Run this operation</summary>
/// <returns>eventDone</returns>
public Event Run()
{
ReadPulses();
return Event.ReadRegisterDone;
}
/// <summary>Stop this operation</summary>
public void Stop()
{
}
}
}
@@ -1,295 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using System.IO;
using System.Text;
using System.Xml.Serialization;
using Config.Entities;
using TBF.BenchControl.Generic;
using TBF.Resources;
namespace TBF.BenchControl.Cameras.CameraRoi
{
public class RoiProcedureParams : ProcedureParamsBase, IParamsProvider, IProcedureParams
{
public int IRoiX;
public int IRoiY;
public int IRoiW;
public int IRoiH;
public float GradPerLtr;
public bool CCW; /// Clockwise = false, Counter clockwise = true
public float ORoiW;
public float ORoiH;
public float CX;
public float CY;
public float R1;
public float R2;
public float R3;
public float Ang1;
public float Ang2;
public float AngStep;
public int MinMvmt;
public int MaxMvmt;
public int SequenceLen;
public int SequenceTiming;
public int BackgroundCorr;
public float BrightnessRoi;
public override void InitializeAll()
{
IRoiX = 60;
IRoiY = 1;
IRoiW = 520;
IRoiH = 478;
GradPerLtr = 40;
CCW = true;
ORoiW = 64.0f;
ORoiH = 64.0f;
CX = 31.0f;
CY = 31.0f;
R1 = 21.0f;
R2 = 31.0f;
R3 = 0;
Ang1 = 0;
Ang2 = 400.0f;
AngStep = 40.0f;
MinMvmt = 0;
MaxMvmt = 0;
SequenceLen = 8;
SequenceTiming = 1;
BackgroundCorr = 0;
BrightnessRoi = 1.0f;
}
string[] paramNames = new string[]
{
"IRoiX",
"IRoiY",
"IRoiW",
"IRoiH",
"Grad per liter",
"CW/CCW",
"ORoiW",
"ORoiH",
"CX",
"CY",
"R1",
"R2",
"R3",
"Ang1",
"Ang2",
"AngStep",
"Min.Mvmt.",
"Max.Mvmt.",
"Det.Seq.Len",
"Det.Seq.Timing",
"Background",
"Brightness",
};
public override string ParamName(int i) { return paramNames[i]; }
public override int ParamsCount() { return paramNames.Length; }
public override string ToString(int i)
{
switch (i)
{
case 0: return IRoiX.ToString();
case 1: return IRoiY.ToString();
case 2: return IRoiW.ToString();
case 3: return IRoiH.ToString();
case 4: return GradPerLtr.ToString();
case 5: return (CCW ? "ccw" : "cw");
case 6: return ORoiW.ToString();
case 7: return ORoiH.ToString();
case 8: return CX.ToString();
case 9: return CY.ToString();
case 10: return R1.ToString();
case 11: return R2.ToString();
case 12: return R3.ToString();
case 13: return Ang1.ToString();
case 14: return Ang2.ToString();
case 15: return AngStep.ToString();
case 16: return MinMvmt.ToString();
case 17: return MaxMvmt.ToString();
case 18: return SequenceLen.ToString();
case 19: return SequenceTiming.ToString();
case 20: return BackgroundCorr.ToString();
case 21: return ((int)(100.0f * BrightnessRoi)).ToString();
default: return string.Empty;
}
}
public void UpdateParam(int i, string strValue)
{
switch (i)
{
case 0: IRoiX = int.Parse(strValue); return;
case 1: IRoiY = int.Parse(strValue); return;
case 2: IRoiW = int.Parse(strValue); return;
case 3: IRoiH = int.Parse(strValue); return;
case 4: GradPerLtr = Utils.ParseUFloat(strValue); return;
case 5: CCW = strValue.ToLower().Equals("ccw"); return;
case 6: ORoiW = Utils.ParseUFloat(strValue); return;
case 7: ORoiH = Utils.ParseUFloat(strValue); return;
case 8: CX = Utils.ParseUFloat(strValue); return;
case 9: CY = Utils.ParseUFloat(strValue); return;
case 10: R1 = Utils.ParseUFloat(strValue); return;
case 11: R2 = Utils.ParseUFloat(strValue); return;
case 12: R3 = Utils.ParseSFloat(strValue); return;
case 13: Ang1 = Utils.ParseSFloat(strValue); return;
case 14: Ang2 = Utils.ParseSFloat(strValue); return;
case 15: AngStep = Utils.ParseUFloat(strValue); return;
case 16: MinMvmt = int.Parse(strValue); return;
case 17: MaxMvmt = int.Parse(strValue); return;
case 18: SequenceLen = int.Parse(strValue); return;
case 19: SequenceTiming = int.Parse(strValue); return;
case 20: BackgroundCorr = int.Parse(strValue); return;
case 21: BrightnessRoi = ((float)int.Parse(strValue) / 100.0f); return;
default: return;
}
}
/// <summary>
/// Parses the text in the control to verify whether it represents a valid parameter.
/// </summary>
/// <param name="i">Parameter nr.</param>
/// <param name="strValue">String to be verified</param>
/// <param name="message">Message to be shown when verification fails</param>
/// <returns>'true' if parameter string is valid, 'false' otherwise</returns>
public bool ValidateParam(int i, string strValue, out string message)
{
message = string.Empty;
int iDummy;
float dummy;
switch (i)
{
case 0:
case 1:
case 2:
case 3:
case 16:
case 17:
case 18:
case 19:
case 20:
if (int.TryParse(strValue, out iDummy)) return true;
break;
case 4:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 15:
case 21:
if (Utils.TryParseUFloat(strValue, out dummy)) return true;
break;
case 12:
case 13:
case 14:
if (Utils.TryParseSFloat(strValue, out dummy)) return true;
break;
case 5:
if (strValue.ToLower().Equals("cw") || strValue.ToLower().Equals("ccw")) return true;
break;
default:
message = "Invalid index";
return false;
}
message = ParamName(i) + " is invalid";
return false;
}
void CopyContentTo(RoiProcedureParams prms)
{
prms.IRoiX = this.IRoiX;
prms.IRoiY = this.IRoiY;
prms.IRoiW = this.IRoiW;
prms.IRoiH = this.IRoiH;
prms.GradPerLtr = this.GradPerLtr;
prms.CCW = this.CCW;
prms.ORoiW = this.ORoiW;
prms.ORoiH = this.ORoiH;
prms.CX = this.CX;
prms.CY = this.CY;
prms.R1 = this.R1;
prms.R2 = this.R2;
prms.R3 = this.R3;
prms.Ang1 = this.Ang1;
prms.Ang2 = this.Ang2;
prms.AngStep = this.AngStep;
prms.MinMvmt = this.MinMvmt;
prms.MaxMvmt = this.MaxMvmt;
prms.SequenceLen = this.SequenceLen;
prms.SequenceTiming = this.SequenceTiming;
prms.BackgroundCorr = this.BackgroundCorr;
prms.BrightnessRoi = this.BrightnessRoi;
}
public IParamsProvider Clone()
{
RoiProcedureParams pars = new RoiProcedureParams();
CopyContentTo(pars);
return pars;
}
public override void UpdateProcedureParams(ComponentProcedure dbEntity)
{
if (dbEntity == null) return;
try
{
RoiProcedureParams tmp = (RoiProcedureParams)(new XmlSerializer(typeof(RoiProcedureParams)))
.Deserialize(new StringReader(dbEntity.Parameters));
procedureParamsEntity = dbEntity;
componentName = dbEntity.CmpntName;
procedure = dbEntity.Procedure;
tmp.CopyContentTo(this);
}
catch
{
}
}
public RoiProcedureParams()
{
}
public RoiProcedureParams(ComponentProcedure procedureParamsEntity, string componentName, Procedure procedure)
{
this.procedureParamsEntity = procedureParamsEntity;
this.componentName = componentName;
this.procedure = procedure;
}
}
}
@@ -1,18 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
namespace TBF.BenchControl.Cameras.IdcCamera.Command
{
public class Connect : IWorkerCmd
{
public string CmdName { get { return "Connect"; } }
public int TimeoutMs;
public Connect(int timeoutMs)
{
this.TimeoutMs = timeoutMs;
}
}
}
@@ -1,63 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
namespace TBF.BenchControl.Cameras.IdcCamera.Command
{
public class Detect : IWorkerCmd
{
public string CmdName { get { return "Detect"; } }
public int RoiNr;
public int WMeterType;
public int IRoiX;
public int IRoiY;
public int IRoiW;
public int IRoiH;
public float CX;
public float CY;
public float ORoiW;
public float ORoiH;
public float R1;
public float R2;
public float R3;
public float Ang1;
public float Ang2;
public float AngStep;
public bool CCW; /// Clockwise = false, Counter clockwise = true
public float NomSpeed;
public int SequenceLen;
public int SequenceTiming;
public int BackgroundCorr;
public float Brightness; /// Overal brightness 0.0 .. 1.0 obtained as a product of the camera and the ROI brightness
public Detect(int roiNr, int wMeterType, int iRoiX, int iRoiY, int iRoiW, int iRoiH,
float cx, float cy, float oRoiW, float oRoiH,
float r1, float r2, float r3, float ang1, float ang2, float angStep, bool ccw,
float nomSpeed, int sequenceLen, int sequenceTiming, int backgroundCorr, float brightness)
{
this.RoiNr = roiNr;
this.WMeterType = wMeterType;
this.IRoiX = iRoiX;
this.IRoiY = iRoiY;
this.IRoiW = iRoiW;
this.IRoiH = iRoiH;
this.CX = cx;
this.CY = cy;
this.ORoiW = oRoiW;
this.ORoiH = oRoiH;
this.R1 = r1;
this.R2 = r2;
this.R3 = r3;
this.Ang1 = ang1;
this.Ang2 = ang2;
this.AngStep = angStep;
this.CCW = ccw;
this.NomSpeed = nomSpeed;
this.SequenceLen = sequenceLen;
this.SequenceTiming = sequenceTiming;
this.BackgroundCorr = backgroundCorr;
this.Brightness = brightness;
}
}
}
@@ -1,16 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
namespace TBF.BenchControl.Cameras.IdcCamera.Command
{
public class Disconnect : IWorkerCmd
{
public string CmdName { get { return "Disconnect"; } }
public Disconnect()
{
}
}
}
@@ -1,34 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
namespace TBF.BenchControl.Cameras.IdcCamera.Command
{
public class Grab : IWorkerCmd
{
public string CmdName { get { return "Grab"; } }
public int X;
public int Y;
public int W;
public int H;
public int Scale;
public string FileName;
public FileFormat Format;
public float Brightness; /// Camera brightness 0.0 .. 1.0
bool WaitCompleted;
public Grab(string fileName, FileFormat format, float brihtness, bool waitCompleted)
{
X = 0;
Y = 0;
W = 640;
H = 480;
Scale = 1;
this.FileName = fileName;
this.Format = format;
this.Brightness = brihtness;
this.WaitCompleted = waitCompleted;
}
}
}
@@ -1,47 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
namespace TBF.BenchControl.Cameras.IdcCamera.Command
{
public class Measure : IWorkerCmd
{
public string CmdName { get { return "Measure"; } }
public int RoiNr; /// 1 or 2
public bool Triggered;
public int WMeterType;
public int IRoiX;
public int IRoiY;
public int IRoiW;
public int IRoiH;
public float CX;
public float CY;
public float ORoiW;
public float ORoiH;
public int MinMvmt;
public int MaxMvmt;
public float Brightness; /// Overal brightness 0.0 .. 1.0 obtained as a product of the camera and the ROI brightness
public Measure(int roiNr, bool triggered, int wMeterType,
int iRoiX, int iRoiY, int iRoiW, int iRoiH,
float cx, float cy, float oRoiW, float oRoiH,
int minMvmt, int maxMvmt, float brightness)
{
this.RoiNr = roiNr;
this.Triggered = triggered;
this.WMeterType = wMeterType;
this.IRoiX = iRoiX;
this.IRoiY = iRoiY;
this.IRoiW = iRoiW;
this.IRoiH = iRoiH;
this.CX = cx;
this.CY = cy;
this.ORoiW = oRoiW;
this.ORoiH = oRoiH;
this.MinMvmt = minMvmt;
this.MaxMvmt = maxMvmt;
this.Brightness = brightness;
}
}
}
@@ -1,18 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
namespace TBF.BenchControl.Cameras.IdcCamera.Command
{
public class Other : IWorkerCmd
{
public string CmdName { get { return "Other"; } }
public string Command;
public Other(string command)
{
this.Command = command;
}
}
}
@@ -1,24 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
namespace TBF.BenchControl.Cameras.IdcCamera.Command
{
class Save : IWorkerCmd
{
public string CmdName { get { return "Save"; } }
public string VariableName;
public string FileName;
public FileFormat Format;
public bool WaitCompleted;
public Save(string variableName, string fileName, FileFormat format, bool waitCompleted)
{
this.VariableName = variableName;
this.FileName = fileName;
this.Format = format;
this.WaitCompleted = waitCompleted;
}
}
}
@@ -1,18 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
namespace TBF.BenchControl.Cameras.IdcCamera.Command
{
public class SetBrightness : IWorkerCmd
{
public string CmdName { get { return "SetBrightness"; } }
public float Brightness; /// 0.0f .. 1.0f
public SetBrightness(float brightness)
{
this.Brightness = brightness;
}
}
}
@@ -1,16 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
namespace TBF.BenchControl.Cameras.IdcCamera.Command
{
public class StartNew : IWorkerCmd
{
public string CmdName { get { return "StartNew"; } }
public StartNew()
{
}
}
}
@@ -1,16 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
namespace TBF.BenchControl.Cameras.IdcCamera.Command
{
public class StopOp : IWorkerCmd
{
public string CmdName { get { return "StopOp"; } }
public StopOp()
{
}
}
}
@@ -1,16 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
namespace TBF.BenchControl.Cameras.IdcCamera.Command
{
public class StopStream : IWorkerCmd
{
public string CmdName { get { return "StopStream"; } }
public StopStream()
{
}
}
}
@@ -1,22 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
namespace TBF.BenchControl.Cameras.IdcCamera.Command
{
public class Stream : IWorkerCmd
{
public string CmdName { get { return "Stream"; } }
public StreamType Type;
public FileFormat Format;
public float Brightness; /// Camera brightness 0.0 .. 1.0
public Stream(StreamType type, FileFormat format, float brightness)
{
this.Type = type;
this.Format = format;
this.Brightness = brightness;
}
}
}
@@ -1,10 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
namespace TBF.BenchControl.Cameras.IdcCamera
{
public interface IWorkerCmd
{
string CmdName { get; }
}
}
File diff suppressed because it is too large Load Diff
@@ -1,307 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Threading;
using Config.Entities;
using TBF.BenchControl;
using TBF.BenchControl.Generic;
using log4net;
namespace TBF.BenchControl.Cameras.IdcCamera
{
/// <summary>
/// IdcCamera object represents all IDC cameras.
/// Camera ID is an argument of most methods.
/// </summary>
public class IdcCamera : ComponentBase, IDevice, IOperation, GenericDevices.ICamera
{
private static readonly ILog log = LogManager.GetLogger(typeof(IdcCamera));
public override string ToString() { return string.Format("IdcCamera({0})", Cfg.ToString(1)); }
readonly IdcCameraCfg idcCameraCfg;
const int MaxRoisCount = 4;
/// <summary>
/// Enumeration of cameras via static fields and methods
/// </summary>
static int nextCameraNr = 0;
public static new void ResetStaticProperties()
{
nextCameraNr = 0;
}
int cameraNr;
public int CameraNr { get { return cameraNr; } }
public float Brightness { get { return idcCameraCfg.BrightnessCam; } }
/// <summary>
/// Currently running camera operation.
/// ReadRegisterOp-s are not included in this list, they are independent.
/// </summary>
public enum CurrentOp
{
None,
StartNew,
SetBrightness,
Grab,
Live,
Focus,
Detect,
Measure,
}
/// Private fields
public Idc100 Idc100; /// Idc100 camera low level implementation
CurrentOp currentOp;
int currentRoiId;
IWorkerCmd detectCmd;
IWorkerCmd measureCmd;
public IdcCamera()
{
}
public IdcCamera(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
: base(cfg)
{
idcCameraCfg = cfg as IdcCameraCfg;
cameraNr = nextCameraNr++;
log.Debug(this.ToString());
}
public void Initialize()
{
if (idcCameraCfg.DebugLevel == DebugMode.Simulate)
{
log.WarnFormat("{0}: in simulation mode", Name);
return;
}
/// Initialize the camera
Idc100 = new Idc100(Name, cameraNr, idcCameraCfg.ComPortNr, idcCameraCfg.BaudRate, idcCameraCfg.BrightnessCam);
RetVal rVal = Idc100.StartOp(new Command.Connect(3000)); /// timeout in ms
if (idcCameraCfg.DebugLevel == DebugMode.AutoDetect)
{
if (rVal == RetVal.OK)
idcCameraCfg.DebugLevel = DebugMode.DetectedOn;
else
idcCameraCfg.DebugLevel = DebugMode.DetectedOff;
}
else if (rVal != RetVal.OK)
{
throw (new Exception(string.Format("Cannot make a connection to {0} on COM{1}", Name, idcCameraCfg.ComPortNr)));
}
if (idcCameraCfg.DebugLevel != DebugMode.DetectedOff)
{
log.FatalFormat("Successfully initialized device {0}", ToString());
}
}
public void RunDeviceBefore()
{
}
public void RunDeviceAfter()
{
}
public void StopDevice()
{
if (Idc100 != null)
{
RetVal rVal = Idc100.StartOp(new Command.Disconnect());
Idc100.ShutDown();
}
}
/// <summary>
/// Restart the camera with a new firmware.
/// </summary>
/// <returns>Reference to operation object instance</returns>
public IOperation StartNewOp()
{
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
currentOp = CurrentOp.StartNew;
return this;
}
/// <summary>
/// Set camera image brightness (camera aperture).
/// </summary>
/// <returns>Reference to operation object instance</returns>
public IOperation SetBrightnessOp()
{
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
currentOp = CurrentOp.SetBrightness;
return this;
}
/// <summary>
/// Grab an image.
/// </summary>
/// <returns>Reference to operation object instance</returns>
public IOperation GrabOp()
{
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
currentOp = CurrentOp.Grab;
return this;
}
/// <summary>
/// Display live image.
/// </summary>
/// <returns>Reference to operation object instance</returns>
public IOperation LiveOp()
{
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
currentOp = CurrentOp.Live;
return this;
}
/// <summary>
/// Display live detail to focus the camera.
/// </summary>
/// <returns>Reference to operation object instance</returns>
public IOperation FocusOp()
{
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
currentOp = CurrentOp.Focus;
return this;
}
/// <summary>
/// Watermeter wheel/arrow detection process.
/// </summary>
/// <param name="roiId">Region of interest (1..MaxRoisCount)</param>
/// <returns>Reference to operation object instance</returns>
public IOperation DetectOp(int roiId, IWorkerCmd detectCmd)
{
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
if (roiId < 1 || roiId > MaxRoisCount) throw new ArgumentOutOfRangeException("roiId");
currentOp = CurrentOp.Detect;
this.currentRoiId = roiId;
this.detectCmd = detectCmd;
return this;
}
/// <summary>
/// Watermeter wheel/arrow angle measurement process.
/// </summary>
/// <param name="roiId">Region of interest (1..MaxRoisCount)</param>
/// <returns>Reference to operation object instance</returns>
public IOperation MeasureOp(int roiId, IWorkerCmd measureCmd)
{
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
if (roiId < 1 || roiId > MaxRoisCount) throw new ArgumentOutOfRangeException("roiId");
currentOp = CurrentOp.Measure;
this.currentRoiId = roiId;
this.measureCmd = measureCmd;
return this;
}
/// <summary>Start the operation</summary>
public void Start()
{
if (Cfg.DebugLevel == DebugMode.Normal || Cfg.DebugLevel == DebugMode.DetectedOn)
{
switch (currentOp)
{
case CurrentOp.StartNew:
Idc100.StartOp(new Command.StartNew());
return;
case CurrentOp.Grab:
Idc100.StartOp(new Command.Grab("snap1", FileFormat.Jpeg, Brightness, false));
return;
case CurrentOp.Live:
Idc100.StartOp(new Command.Stream(StreamType.SubSampled, FileFormat.Jpeg, Brightness));
return;
case CurrentOp.Focus:
Idc100.StartOp(new Command.Stream(StreamType.Focus, FileFormat.Bmp, Brightness));
return;
case CurrentOp.Detect:
Idc100.StartOp(this.detectCmd);
return;
case CurrentOp.Measure:
Idc100.StartOp(this.measureCmd);
return;
}
}
}
/// <summary>
/// Check the cameraDev state (OP_COMPLETED or OP_FAILED)
/// </summary>
/// <returns></returns>
public Event Run()
{
if (Cfg.DebugLevel == DebugMode.Normal || Cfg.DebugLevel == DebugMode.DetectedOn)
{
switch (currentOp)
{
case CurrentOp.Grab:
if (Idc100.IdcState == IdcState.Idle) return Event.None;
else return Event.Error;
case CurrentOp.StartNew:
case CurrentOp.Live:
case CurrentOp.Focus:
case CurrentOp.Measure:
case CurrentOp.Detect:
if (Idc100.IdcState == IdcState.Busy)
{
return Event.CameraBusy;
}
else if (Idc100.IdcState == IdcState.OpCompleted)
{
log.InfoFormat("{0}: {1} - OpCompleted", cameraNr, currentOp);
return Event.CameraOpCompleted;
}
else if (Idc100.IdcState == IdcState.OpFailed)
{
log.WarnFormat("{0}: {1} - OpFailed", cameraNr, currentOp);
return Event.CameraOpFailed;
}
else if (Idc100.IdcState == IdcState.DetectionFailed)
{
log.WarnFormat("{0}: {1} - DetectionFailed", cameraNr, currentOp);
return Event.RoiDetectionFailed;
}
else return Event.Error;
default:
return Event.Error;
}
}
else
{
if (currentOp == CurrentOp.Grab)
{
return Event.None;
}
else
{
return Event.CameraOpCompleted;
}
}
}
/// <summary>Stop the operation</summary>
public void Stop()
{
if ((Cfg.DebugLevel == DebugMode.Normal || Cfg.DebugLevel == DebugMode.DetectedOn)
&& (Idc100.IdcState != IdcState.Idle))
{
Idc100.StopOp();
}
currentOp = CurrentOp.None;
}
}
}
@@ -1,48 +0,0 @@
///
/// Copyright (c) 2013-2016 Sensus Metering Systems
///
using System.IO;
using System.Collections.Generic;
using System.IO.Ports;
using System.Xml.Serialization;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Cameras.IdcCamera
{
public class IdcCameraCfg : ComponentCfgBase, Generic.IComponentCfg
{
public IComponentCfgCtrl GetControl() { return new IdcCameraCfgCtrl(); }
///
/// Serialized parameters
///
public int ComPortNr; /// Com port number 1..999
public int BaudRate; /// Baud rate 57600 or 115200
public float BrightnessCam; /// Relative brightness 0 .. 1.0f
/// Private parameterless constructor invoked by all other (public) constructors
IdcCameraCfg()
{
Name = "Idc";
ParentName = string.Empty;
ComPortNr = 20;
BaudRate = 57600;
BrightnessCam = 0.5f;
}
public IdcCameraCfg(IComponentFactory factory)
: this()
{
this.Factory = factory;
}
public string ToString(int i)
{
return string.Format("Name={0}, Com{1}, {2}Bd, brght={3}%",
Name,
ComPortNr,
BaudRate,
(int)(100.0f * BrightnessCam));
}
}
}
@@ -1,103 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using System.Windows.Forms;
using System.IO.Ports;
using log4net;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Cameras.IdcCamera
{
public partial class IdcCameraCfgCtrl : UserControl, IComponentCfgCtrl
{
static readonly ILog log = LogManager.GetLogger(typeof(IdcCameraCfgCtrl));
public bool ShowMore { get { return false; } }
IdcCameraCfg config;
public IComponentCfg Config
{
get { return config as IComponentCfg; }
set
{
config = value as IdcCameraCfg;
Redraw();
}
}
public IdcCameraCfgCtrl()
{
InitializeComponent();
}
private void IdcCameraCfgCtrl_Load(object sender, EventArgs e)
{
baudRateComboBox.Items.Add("57600");
baudRateComboBox.Items.Add("115200");
Redraw();
}
public void Closing()
{
}
void Redraw()
{
if (config == null) return; /// Control was not loaded, settings were not changed
classNameLabel.Text = config.Factory.ClassName;
nameTextBox.Text = config.Name;
comPortNrTextBox.Text = config.ComPortNr.ToString();
baudRateComboBox.Text = config.BaudRate.ToString();
brightnessTextBox.Text = (100.0f * config.BrightnessCam).ToString();
}
public void Unlock()
{
nameTextBox.Enabled = true;
comPortNrTextBox.Enabled = true;
baudRateComboBox.Enabled = true;
brightnessTextBox.Enabled = true;
}
public CfgUpdateFlags VerifyCfg(ref string message)
{
CfgUpdateFlags flags = CfgUpdateFlags.None;
int dummy;
if (!int.TryParse(comPortNrTextBox.Text, out dummy) || dummy < 1 || dummy > 999)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Serial Port Number' is not valid";
}
if (!int.TryParse(baudRateComboBox.Text, out dummy) || ((dummy != 57600) && (dummy != 115200)))
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Baud Rate' should be 57600 or 115200 Bd";
}
if (!int.TryParse(brightnessTextBox.Text, out dummy) || dummy < 0 || dummy > 100)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Brightness' should be between 0 and 100 %";
}
return flags;
}
public CfgUpdateFlags UpdateCfg()
{
CfgUpdateFlags flags = CfgUpdateFlags.RestartRqrd;
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
config.Name = nameTextBox.Text;
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
config.BaudRate = int.Parse(baudRateComboBox.Text);
config.BrightnessCam = ((float)int.Parse(brightnessTextBox.Text) / 100.0f);
return flags;
}
}
}
@@ -1,180 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
namespace TBF.BenchControl.Cameras.IdcCamera
{
partial class IdcCameraCfgCtrl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.nameTextBox = new System.Windows.Forms.TextBox();
this.nameLabel = new System.Windows.Forms.Label();
this.classNameLabel = new System.Windows.Forms.Label();
this.baudRateLabel = new System.Windows.Forms.Label();
this.comPortNrTextBox = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.brightnessTextBox = new System.Windows.Forms.TextBox();
this.brightnessLabel = new System.Windows.Forms.Label();
this.baudRateComboBox = new System.Windows.Forms.ComboBox();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// nameTextBox
//
this.nameTextBox.Enabled = false;
this.nameTextBox.Location = new System.Drawing.Point(139, 47);
this.nameTextBox.Name = "nameTextBox";
this.nameTextBox.Size = new System.Drawing.Size(130, 20);
this.nameTextBox.TabIndex = 2;
//
// nameLabel
//
this.nameLabel.AutoSize = true;
this.nameLabel.Location = new System.Drawing.Point(29, 50);
this.nameLabel.Name = "nameLabel";
this.nameLabel.Size = new System.Drawing.Size(35, 13);
this.nameLabel.TabIndex = 1;
this.nameLabel.Text = "Name";
//
// classNameLabel
//
this.classNameLabel.AutoSize = true;
this.classNameLabel.Location = new System.Drawing.Point(136, 21);
this.classNameLabel.Name = "classNameLabel";
this.classNameLabel.Size = new System.Drawing.Size(83, 13);
this.classNameLabel.TabIndex = 0;
this.classNameLabel.Text = "ComonentName";
//
// baudRateLabel
//
this.baudRateLabel.AutoSize = true;
this.baudRateLabel.Location = new System.Drawing.Point(28, 102);
this.baudRateLabel.Name = "baudRateLabel";
this.baudRateLabel.Size = new System.Drawing.Size(58, 13);
this.baudRateLabel.TabIndex = 5;
this.baudRateLabel.Text = "Baud Rate";
//
// comPortNrTextBox
//
this.comPortNrTextBox.Enabled = false;
this.comPortNrTextBox.Location = new System.Drawing.Point(139, 73);
this.comPortNrTextBox.Name = "comPortNrTextBox";
this.comPortNrTextBox.Size = new System.Drawing.Size(80, 20);
this.comPortNrTextBox.TabIndex = 4;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(28, 76);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(98, 13);
this.label1.TabIndex = 3;
this.label1.Text = "Serial Port Number:";
//
// brightnessTextBox
//
this.brightnessTextBox.Enabled = false;
this.brightnessTextBox.Location = new System.Drawing.Point(140, 126);
this.brightnessTextBox.Name = "brightnessTextBox";
this.brightnessTextBox.Size = new System.Drawing.Size(79, 20);
this.brightnessTextBox.TabIndex = 8;
//
// brightnessLabel
//
this.brightnessLabel.AutoSize = true;
this.brightnessLabel.Location = new System.Drawing.Point(28, 129);
this.brightnessLabel.Name = "brightnessLabel";
this.brightnessLabel.Size = new System.Drawing.Size(56, 13);
this.brightnessLabel.TabIndex = 7;
this.brightnessLabel.Text = "Brightness";
//
// baudRateComboBox
//
this.baudRateComboBox.Enabled = false;
this.baudRateComboBox.FormattingEnabled = true;
this.baudRateComboBox.Location = new System.Drawing.Point(139, 99);
this.baudRateComboBox.Name = "baudRateComboBox";
this.baudRateComboBox.Size = new System.Drawing.Size(80, 21);
this.baudRateComboBox.TabIndex = 6;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(226, 129);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(15, 13);
this.label2.TabIndex = 9;
this.label2.Text = "%";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(226, 102);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(20, 13);
this.label3.TabIndex = 10;
this.label3.Text = "Bd";
//
// IdcCameraCfgCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.baudRateComboBox);
this.Controls.Add(this.brightnessTextBox);
this.Controls.Add(this.brightnessLabel);
this.Controls.Add(this.nameTextBox);
this.Controls.Add(this.nameLabel);
this.Controls.Add(this.classNameLabel);
this.Controls.Add(this.baudRateLabel);
this.Controls.Add(this.comPortNrTextBox);
this.Controls.Add(this.label1);
this.Name = "IdcCameraCfgCtrl";
this.Size = new System.Drawing.Size(300, 240);
this.Load += new System.EventHandler(this.IdcCameraCfgCtrl_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox nameTextBox;
private System.Windows.Forms.Label nameLabel;
private System.Windows.Forms.Label classNameLabel;
private System.Windows.Forms.Label baudRateLabel;
private System.Windows.Forms.TextBox comPortNrTextBox;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox brightnessTextBox;
private System.Windows.Forms.Label brightnessLabel;
private System.Windows.Forms.ComboBox baudRateComboBox;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
}
}
@@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
@@ -1,26 +0,0 @@
///
/// Copyright (c) 2013-2016 Sensus Metering Systems
///
using System.Collections.Generic;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Cameras.IdcCamera
{
public class IdcCameraFactory : IComponentFactory
{
public string ClassName { get { return "IdcCamera"; } }
public void ResetStaticProperties() { IdcCamera.ResetStaticProperties(); }
public IComponent DummyComponent() { return new IdcCamera(); }
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new IdcCamera(cfg, components); }
public IComponentCfg DefaultConfig() { return new IdcCameraCfg(this); }
public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component)
{
return ComponentCfgBase.CreateFromDbEntity(typeof(IdcCameraCfg), component, this);
}
}
}
@@ -1,70 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
namespace TBF.BenchControl.Cameras.IdcCamera
{
/// <summary>IDC camera states</summary>
public enum IdcState
{
Unchanged = -1, /// not a state - used in state transition tables
NotConnected = 0, /// 'gray'
Idle, /// 'green'
Busy, /// 'yellow' or 'orange'
OpCompleted, /// 'green'
OpFailed, /// 'red'
DetectionFailed, /// 'red'
Halted, /// 'red'
}
public enum RetVal
{
OK = 0,
HOST_START = 1000, /// Start of error codes from HOST part of the software
Busy, /// OK - camera operation in progress
OpInterrupted, /// OK - camera operation interrupted
DetectionFailed, /// Camera operation is OK, however ROI detection failed -> fix and retry
OpFailed, /// RetVal - Camera operation failed
CameraNotConnected, /// RetVal - Camera is not connected
SequenceError, /// RetVal - Invalid sequence of calls
InvalidComPortNr, /// RetVal - Invalid COM-port number
CannotOpenComPort, /// RetVal - Cannot open COM-port
CannotCommWithCamera, /// RetVal - Cannot communicate with the camera
CommTimeout, /// RetVal - Communication timeout
CommError, /// RetVal - Unknown error during communication
ShutdownInProgress, /// RetVal - System is shutting down
FatalError, /// RetVal - Fatal error
}
public struct IdcTransition
{
public RetVal RetVal;
public IdcState NewState;
public IdcTransition(RetVal retVal, IdcState newState)
{
this.RetVal = retVal;
this.NewState = newState;
}
}
public enum FileFormat
{
Bmp,
Jpeg,
}
public enum StreamType
{
Full,
SubSampled,
Focus,
}
enum WorkerCommand
{
StopOp, /// Stop the current operation
Timeout, /// The expected WorkerCommand(s) have not arrived in time
}
}
@@ -1,230 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using log4net;
using TBF.UiBridge;
namespace TBF.BenchControl.Cameras.IdcCamera
{
///
/// File I/O implementation
///
public class SerialFileIO
{
static readonly ILog log = LogManager.GetLogger(typeof(SerialFileIO));
static TBF.Tools.ByteFormatter byteFormatter = new TBF.Tools.ByteFormatter();
const int BUFSIZE = 1024;
const int MAXFNAMESIZE = 62;
int cameraIdx;
string imagesPath;
StringBuilder fioFilenameBuilder;
string fioFullPathname;
int packetSize;
byte[] fioBuffer;
BinaryWriter fioWriter;
enum FioState
{
Command, /// 'o', 'c' or 'w'
Open, /// 'p'
Open2, /// 'e'
Open3, /// 'n'
Open4, /// 1
Filename,
Close, /// 'l'
Close2, /// 'o'
Close3, /// 's'
Close4, /// 'e'
Close5, /// 1
Write, /// 'r'
Write2, /// 'i'
Write3, /// 't'
Write4, /// 'e'
Write5, /// 1
PktSize1,
PktSize2,
PktSize3,
Data,
}
FioState state;
public string TransferredFile
{
get { return fioFullPathname; }
}
public SerialFileIO(int cameraIdx, string imagesPath)
{
this.cameraIdx = cameraIdx;
this.imagesPath = imagesPath;
state = FioState.Command;
fioFullPathname = string.Empty;
fioFilenameBuilder = new StringBuilder(16);
fioBuffer = new byte[BUFSIZE];
}
public void ProcessByte(byte b)
{
///
/// Reaching break in any case of the following switch is an error
///
if (state == FioState.Data)
{
if (packetSize > 0)
{
if (fioWriter != null)
{
fioWriter.Write(b);
}
if (--packetSize == 0)
{
state = FioState.Command;
}
return;
}
log.ErrorFormat("{0}: FIO error 17", cameraIdx);
}
else
{
switch (state)
{
case FioState.Command:
if ((char)b == 'o') { state = FioState.Open; return; }
if ((char)b == 'c') { state = FioState.Close; return; }
if ((char)b == 'w') { state = FioState.Write; return; }
log.ErrorFormat("{0}: FIO error 1, fullPathName={1}", cameraIdx, fioFullPathname);
break;
case FioState.Open:
if ((char)b == 'p') { state = FioState.Open2; return; }
log.ErrorFormat("{0}: FIO error 2", cameraIdx);
break;
case FioState.Open2:
if ((char)b == 'e') { state = FioState.Open3; return; }
log.ErrorFormat("{0}: FIO error 3", cameraIdx);
break;
case FioState.Open3:
if ((char)b == 'n') { state = FioState.Open4; return; }
log.ErrorFormat("{0}: FIO error 4", cameraIdx);
break;
case FioState.Open4:
if (b == 1)
{
fioFilenameBuilder.Clear();
state = FioState.Filename;
return;
}
log.ErrorFormat("{0}: FIO error 5", cameraIdx);
break;
case FioState.Filename:
if (b == 0)
{
if (fioWriter != null)
{
fioWriter.Close();
fioWriter.Dispose();
}
try
{
fioFullPathname = imagesPath + fioFilenameBuilder.ToString();
fioWriter = new BinaryWriter(File.Open(fioFullPathname, FileMode.Create));
log.DebugFormat("{0}: Open(\"{1}\")", cameraIdx, fioFullPathname);
}
catch
{
fioWriter = null;
log.WarnFormat("{0}: Failed to open(\"{1}\")", cameraIdx, fioFullPathname);
}
state = FioState.Command;
return;
}
else if (fioFilenameBuilder.Length < MAXFNAMESIZE)
{
fioFilenameBuilder.Append((char)b);
return;
}
log.ErrorFormat("{0}: FIO error 6", cameraIdx);
break;
case FioState.Close:
if ((char)b == 'l') { state = FioState.Close2; return; }
log.ErrorFormat("{0}: FIO error 7", cameraIdx);
break;
case FioState.Close2:
if ((char)b == 'o') { state = FioState.Close3; return; }
log.ErrorFormat("{0}: FIO error 8", cameraIdx);
break;
case FioState.Close3:
if ((char)b == 's') { state = FioState.Close4; return; }
log.ErrorFormat("{0}: FIO error 9", cameraIdx);
break;
case FioState.Close4:
if ((char)b == 'e') { state = FioState.Close5; return; }
log.ErrorFormat("{0}: FIO error 10", cameraIdx);
break;
case FioState.Close5:
if ((char)b == '1' && fioWriter != null)
{
log.DebugFormat("{0}: Close()", cameraIdx);
fioWriter.Close();
fioWriter.Dispose();
fioWriter = null;
Bridge.OnImageUpdated(this, new ImageUpdatedEventArgs(cameraIdx, fioFullPathname));
fioFullPathname = String.Empty;
state = FioState.Command;
return;
}
log.ErrorFormat("{0}: FIO error 11", cameraIdx);
break;
case FioState.Write:
if ((char)b == 'r') { state = FioState.Write2; return; }
log.ErrorFormat("{0}: FIO error 12", cameraIdx);
break;
case FioState.Write2:
if ((char)b == 'i') { state = FioState.Write3; return; }
log.ErrorFormat("{0}: FIO error 13", cameraIdx);
break;
case FioState.Write3:
if ((char)b == 't') { state = FioState.Write4; return; }
log.ErrorFormat("{0}: FIO error 14", cameraIdx);
break;
case FioState.Write4:
if ((char)b == 'e') { state = FioState.Write5; return; }
log.ErrorFormat("{0}: FIO error 15", cameraIdx);
break;
case FioState.Write5:
if ((char)b == '1') { state = FioState.PktSize1; return; }
log.ErrorFormat("{0}: FIO error 16", cameraIdx);
break;
case FioState.PktSize1:
packetSize = (int)b;
state = FioState.PktSize2;
return;
case FioState.PktSize2:
packetSize = (256 * packetSize) + (int)b;
state = FioState.PktSize3;
return;
case FioState.PktSize3:
packetSize = (256 * packetSize) + (int)b;
log.DebugFormat("{0}: write(len={1})", cameraIdx, packetSize);
state = FioState.Data;
return;
default:
log.ErrorFormat("{0}: FIO error 18", cameraIdx);
break;
}
}
state = FioState.Command;
}
}
}
@@ -1,622 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Ports;
using System.Text;
using System.Threading;
using log4net;
namespace TBF.BenchControl.Cameras.IdcCamera
{
public class SerialLayer
{
static readonly ILog log = LogManager.GetLogger(typeof(SerialLayer));
///
/// Set to true when shut-down is in progress
///
public static bool g_shutDown = false;
public bool m_disconnecting;
int cameraNr;
int comPortNr;
int baudRate;
int readTimeout;
string imagesPath;
Queue<byte> readQueue;
ManualResetEvent queueNotEmptyEvent;
SerialFileIO serialFileIO;
SerialPort serialPort;
byte[] singleCharWrBuff; /// predefined serial write buffer for 1 byte
byte[] twoCharsWrBuff; /// predefined serial write buffer for 2 bytes
#region Content switching, multiplexing
const byte CTRLZ = 26;
const byte CTRLQ = 17;
const byte XON = 17;
const byte CTRLS = 19;
const byte XOFF = 19;
/// <summary>
/// Multiplexed channel content ID (destination ID)
/// </summary>
enum Mux
{
Console, /// Command console, identified by CTRLZ + 'C' byte sequence
File, /// File download (ICD camera -> file), identified by CTRLZ = 'F' byte sequence
}
Mux lastWriteContentId;
Mux currentReadContentId;
bool lastReadCtrlZ;
#endregion
/// <summary>
/// Create a SerialLayer instance.
/// </summary>
/// <param name="cameraNr">0-based camera number</param>
/// <param name="comPortNr">COM port number 1..999</param>
/// <param name="baudRate">Baud rate 57600 or 115200</param>
/// <param name="readTimeout">Read timeout in ms</param>
/// <param name="imagesPath">Path to a folder where received files are stored</param>
public SerialLayer(int cameraNr, int comPortNr, int baudRate, int readTimeout, string imagesPath)
{
log.InfoFormat("new SerialLayer(ix={0}, com{1}, {2}Bd, tmout={3}ms, ipath={4})", cameraNr, comPortNr, baudRate, readTimeout, imagesPath);
this.cameraNr = cameraNr;
this.comPortNr = comPortNr;
this.baudRate = baudRate;
this.readTimeout = readTimeout;
this.imagesPath = imagesPath;
singleCharWrBuff = new byte[1];
twoCharsWrBuff = new byte[2];
twoCharsWrBuff[0] = CTRLZ;
m_disconnecting = false;
readQueue = new Queue<byte>();
queueNotEmptyEvent = new ManualResetEvent(false);
serialPort = new SerialPort();
serialPort.DataReceived += serialPort_DataReceived;
}
/// <summary>
/// Open the serial port.
/// </summary>
/// <returns>RetVal.OK or RetVal.CANNOT_OPEN_COMPORT</returns>
public RetVal OpenPort()
{
log.Info("OpenPort()");
if (serialPort.IsOpen) return RetVal.OK;
if (comPortNr<1 || comPortNr>999) return RetVal.CannotOpenComPort;
m_disconnecting = false;
/// Initialize FIFO, content switching, multiplexing
readQueue.Clear();
lastWriteContentId = Mux.Console;
currentReadContentId = Mux.Console;
lastReadCtrlZ = false;
serialFileIO = new SerialFileIO(cameraNr, imagesPath);
/// Finally open the serial port
try
{
serialPort.PortName = "COM" + comPortNr.ToString();
serialPort.BaudRate = baudRate;
serialPort.Parity = Parity.None;
serialPort.DataBits = 8;
serialPort.StopBits = StopBits.One;
serialPort.Handshake = Handshake.None;
serialPort.RtsEnable = true;
serialPort.DtrEnable = true;
serialPort.ReadTimeout = 1000000; /// Sufficiently large, read timeout is applied to FIFO read
serialPort.WriteTimeout = SerialPort.InfiniteTimeout;
serialPort.Open();
}
catch (Exception e)
{
log.Error("Cannot open serial port COM" + comPortNr.ToString(), e);
return RetVal.CannotOpenComPort;
}
return RetVal.OK;
}
/// <summary>
/// Close the serial port.
/// </summary>
public void ClosePort()
{
log.InfoFormat("{0}: ClosePort()", cameraNr);
if (!serialPort.IsOpen) return;
m_disconnecting = true; /// Complete any pending I/O operations
serialPort.Close();
}
public void FifoFlush()
{
lock (readQueue) { readQueue.Clear(); }
}
public void UnlockLastRead()
{
lock (readQueue) { readQueue.Enqueue((byte)' '); } /// quit infinite fifo.Get() waiting
}
/// <summary>
/// Serial port data received event handler method
/// </summary>
/// <param name="sender">SerialPort</param>
/// <param name="e"></param>
void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
byte[] data = new byte[serialPort.BytesToRead];
serialPort.Read(data, 0, data.Length);
foreach (byte dat in data)
{
byte b = dat;
if (lastReadCtrlZ)
{
lastReadCtrlZ = false;
if (dat == (byte)'C')
{
currentReadContentId = Mux.Console; /// Ctrl-Z + 'C' sequence detected: Mux.Console
continue;
}
if (dat == (byte)'F')
{
currentReadContentId = Mux.File; /// Ctrl-Z + 'F' sequence detected: Mux.File
continue;
}
if (dat == (byte)'1') b = (byte)XON; /// Ctrl-Z + '1' sequence detected: XON
if (dat == (byte)'2') b = (byte)XOFF; /// Ctrl-Z + '2' sequence detected: XOFF
}
else if (dat == CTRLZ)
{
lastReadCtrlZ = true;
continue;
}
///
/// Process demultiplexed data byte b appropriately
///
if (currentReadContentId == Mux.Console)
{
lock (readQueue)
{
readQueue.Enqueue(b);
queueNotEmptyEvent.Set();
}
}
else
{
serialFileIO.ProcessByte(b);
}
}
}
#region Read from readQueue
/// <summary>
/// Read one byte from the console content FIFO.
/// </summary>
/// <param name="response">Received byte</param>
/// <returns>RetVal.OK, RetVal.COMM_TIMEOUT or RetVal.SHUTDOWN</returns>
public RetVal ReadByte(out byte response)
{
if (g_shutDown || m_disconnecting)
{
response = 0;
log.DebugFormat("{0}: ReadByte() returns RetVal.SHUTDOWN", cameraNr);
return RetVal.ShutdownInProgress;
}
lock (readQueue)
{
if (readQueue.Count > 0)
{
response = readQueue.Dequeue();
return RetVal.OK;
}
else
{
queueNotEmptyEvent.Reset();
}
}
if (queueNotEmptyEvent.WaitOne(readTimeout))
{
lock (readQueue)
{
response = readQueue.Dequeue();
return RetVal.OK;
}
}
else
{
response = 0;
log.ErrorFormat("{0}: ReadByte() returns RetVal.COMM_TIMEOUT", cameraNr);
return RetVal.CommTimeout;
}
}
/// <summary>
/// Read bytes and form the output string until a delimiter character is received.
/// Output string excludes the delimiter.
/// </summary>
/// <param name="delimiter">Delimiter character</param>
/// <param name="text">Output string</param>
/// <returns>RetVal.OK, RetVal.COMM_TIMEOUT or RetVal.SHUTDOWN</returns>
RetVal ReadUntil(char delimiter, out string output)
{
StringBuilder buffer = new StringBuilder();
while (true)
{
RetVal retv;
byte znak;
if (RetVal.OK != (retv = ReadByte(out znak)))
{
output = buffer.ToString(); /// Copy data received so far to the output
log.Error("ReadUntil('" + delimiter.ToString() + "', out \"" + output + "\") returns " + retv.ToString());
return retv; /// Communication error
}
char c = (char)znak;
if (c == delimiter) break;
buffer.Append(c);
}
output = buffer.ToString();
return RetVal.OK;
}
/// <summary>
/// Read bytes and form the output string until "\r\n" is received.
/// Output string excludes "\r\n".
/// </summary>
/// <param name="text">Output string</param>
/// <returns>RetVal.OK, RetVal.COMM_TIMEOUT, RetVal.COMM_ERROR or RetVal.SHUTDOWN</returns>
RetVal ReadLine(out string output)
{
RetVal retv = ReadUntil('\r', out output);
if (retv != RetVal.OK) return retv;
/// Read the expected '\n'
byte znak;
if (RetVal.OK != (retv = ReadByte(out znak))) return retv;
if (znak != (byte)'\n')
{
log.Error("ReadLine(out \"" + output + "\") returns " + retv.ToString());
return RetVal.CommError;
}
return RetVal.OK;
}
#endregion
#region Write to serial port
/// <summary>
/// Write one byte (console content) to the serial port.
/// </summary>
/// <param name="b">Byte to send</param>
public void WriteByte(byte b)
{
WriteByte_Mux(b, Mux.Console);
}
/// <summary>
/// Write one byte from any source (either console or file) to the serial port.
/// Perform multiplexing - expansion to escape sequences using CTRLZ.
/// </summary>
/// <param name="b">Byte to send</param>
/// <param name="contentId">Mux.Console or Mux.File</param>
void WriteByte_Mux(byte b, Mux contentId)
{
if (contentId != lastWriteContentId)
{
/// Switching contentId when writing to a camera is not supported yet,
/// therefore this code within { } wont be invoked right now.
/// Send the content switch command CTRLZ + contentId
twoCharsWrBuff[1] = (contentId == Mux.Console) ? (byte)'C' : (byte)'F';
serialPort.Write(twoCharsWrBuff, 0, 2);
lastWriteContentId = contentId;
return;
}
if (b == CTRLZ)
{
/// If 'b'=CTRLZ send CTRLZ + CTRLZ
twoCharsWrBuff[1] = CTRLZ;
serialPort.Write(twoCharsWrBuff, 0, 2);
return;
}
else if (b == XON)
{
/// If 'b'=XON send CTRLZ + '1'
twoCharsWrBuff[1] = (byte)'1';
serialPort.Write(twoCharsWrBuff, 0, 2);
return;
}
else if (b == XOFF)
{
/// If 'b'=XON send CTRLZ + '2'
twoCharsWrBuff[1] = (byte)'2';
serialPort.Write(twoCharsWrBuff, 0, 2);
return;
}
else
{
/// Send a single regular byte 'b'
singleCharWrBuff[0] = b;
serialPort.Write(singleCharWrBuff, 0, 1);
return;
}
}
/// <summary>
/// Write a string (console content) to the serial port.
/// </summary>
/// <param name="str">String to send</param>
public void WriteString(string str)
{
if (str == null) return; /// There is nothing to send - return
if (str.EndsWith("\r\n"))
{
log.InfoFormat("{0}: WriteString(\"{1}\\r\\n\")", cameraNr, str.Substring(0, str.Length - 2));
}
else
{
log.InfoFormat("{0}: WriteString(\"{1}\")", cameraNr, str);
}
for (int i = 0; i < str.Length; i++) WriteByte((byte)str[i]);
}
#endregion
//-------------------------------------------------------------------------------
///////////////////////// Higher level console commands ///////////////////////
//-------------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Sends the specified command and waits for the following response.
// strings separated by spaces and terminated by <cr>
// Stores response into an array of CStrings pointed by pStrArray.
//
// Returns:
// positive numbers and 0
// The number of fields in the response. Returned number may be
// greater then arrayLen. Only the first arrayLen strings are saved.
// negative numbers
// negative error code returned by lower level functions:
// -RetVal.COMM_TIMEOUT = timeout occurred
// -RetVal.COMM_ERROR = all other errors
//---------------------------------------------------------------------------
public int CommandStr(string cmd, out string[] strArray, int nrFields, out string remaining)
{
StringBuilder tmp = new StringBuilder();
StringBuilder logStr = new StringBuilder();
StringBuilder rem = new StringBuilder();
lock (readQueue) { readQueue.Clear(); }
WriteString(cmd); /// send
strArray = null;
remaining = String.Empty;
string beforeGT;
RetVal retv = ReadUntil('>', out beforeGT);
if (retv != RetVal.OK) return -(int)retv; /// If Read... fails quit the loop ...
/// ... and return negative error code
/// Read the expected ' '
byte znak;
if (RetVal.OK != (retv = ReadByte(out znak))) return -(int)retv;
if (znak != (byte)' ') return -(int)RetVal.CommError;
/// Read fields after '>', parse the first field (the return code)
string received;
retv = ReadLine(out received);
if (retv != RetVal.OK) return -(int)retv;
strArray = received.Split(new char[] { ' ' }, nrFields + 1);
log.InfoFormat("{0}: Received: > {1}", cameraNr, received);
/// Skip until '$' received
retv = ReadUntil('$', out received);
if (retv != RetVal.OK) return -(int)retv;
/// Parse the return code (the 1st field)
int returnCode;
if (!int.TryParse(strArray[0], out returnCode) || returnCode < 0) return returnCode;
if (strArray.GetLength(0) == nrFields + 1) remaining = strArray[nrFields];
return Math.Min(strArray.GetLength(0), nrFields);
}
//---------------------------------------------------------------------------
// Sends the specified command and waits for the following response.
// integers separated by spaces and terminated by <cr>
// Stores response into an integer array pointed by pIntArray;
//
// Returns:
// positive numbers and 0
// The number of fields in the response. Returned number may be
// greater then arrayLen. Only the first arrayLen strings are saved.
// negative numbers
// negative error code returned by lower level functions
//---------------------------------------------------------------------------
public int CommandInt(string cmd, out int[] intArray, int nrFields, out string remaining)
{
string[] strArray;
int retv = CommandStr(cmd, out strArray, nrFields, out remaining);
if (retv <= 0)
{
intArray = null;
return retv;
}
intArray = new int[retv];
for (int i = 0; i < retv; i++)
{
int.TryParse(strArray[i], out intArray[i]);
}
return retv;
}
//---------------------------------------------------------------------------
// Sends the specified command and waits for the following response.
// real numbers separated by spaces and terminated by <cr>
// Stores response into a double array pointed by pDblArray;
//
// Returns:
// positive numbers and 0
// The number of fields in the response. Returned number may be
// greater then arrayLen. Only the first arrayLen strings are saved.
// negative numbers
// negative error code returned by lower level functions
//---------------------------------------------------------------------------
public int CommandDbl(string cmd, out double[] dblArray, int arrayLen, out string remaining)
{
string[] strArray;
int retv = CommandStr(cmd, out strArray, arrayLen, out remaining);
if (retv <= 0)
{
dblArray = null;
return retv;
}
dblArray = new double[retv];
for (int i = 0; i < retv; i++)
{
double.TryParse(strArray[i], out dblArray[i]);
}
return retv;
}
/// <summary>
/// Get camera version string
/// </summary>
/// <param name="versionStr">Version string</param>
/// <returns>RetVal.OK, RetVal.COMM_TIMEOUT, RetVal.COMM_ERROR, RetVal.SHUTDOWN or a camera ret.code (1..999)</returns>
public RetVal GetVer(out string versionStr)
{
log.DebugFormat("{0}: GetVer()", cameraNr);
versionStr = String.Empty;
StringBuilder tmp = new StringBuilder();
const int arrayLen = 1;
string[] strArray = new string[arrayLen];
lock (readQueue) { readQueue.Clear(); }
WriteString("info\r\n"); /// Send
/// Read info message until '>'
string infoMessage;
RetVal retv = ReadUntil('>', out infoMessage);
if (retv != RetVal.OK) return retv;
log.DebugFormat("{0}: InfoMessage: {1}", cameraNr, infoMessage);
/// Read the expected ' '
byte znak;
if (RetVal.OK != (retv = ReadByte(out znak))) return retv;
if (znak != (byte)' ') return RetVal.CommError;
/// Read fields after '>', parse the first field (the return code)
string tempStr;
retv = ReadLine(out tempStr);
if (retv != RetVal.OK) return retv;
string[] fields = tempStr.Split(new char[] { ' ' }, 2);
int returnCode;
if (!int.TryParse(fields[0], out returnCode) || returnCode < 0) return (RetVal)(-returnCode);
/// Skip until '$' received
retv = ReadUntil('$', out tempStr);
if (retv != RetVal.OK) return retv;
/// Parse the infoMessage
int pos1 = infoMessage.IndexOf("version = ");
if (pos1 != -1)
{
pos1 += "version = ".Length;
int pos2 = infoMessage.IndexOf("\r\n", pos1);
versionStr = infoMessage.Substring(pos1, pos2 - pos1);
log.InfoFormat("{0}: GetVer(out \"" + versionStr + "\")", cameraNr);
return RetVal.OK;
}
log.ErrorFormat("{0}: GetVer(...) returns RetVal.OP_FAILED", cameraNr);
return RetVal.CommError; /// Cannot read the version string
}
//----------------------------------------------------------------------------
// Check if livestream of serial characters is coming.
//
// Returns:
// RetVal.OK ..... not (OK),
// RetVal.BUSY ... yes (camera needs to be restarted)
//----------------------------------------------------------------------------
RetVal CheckLiveStream()
{
byte znak;
// 500 characters without timeout = stream
// copyright message is +/-350 characters long
for (int i=0; i<500; i++)
{
if (RetVal.CommTimeout == ReadByte(out znak)) return RetVal.OK; /// timeout ... no stream (OK)
}
#if true
// try to stop the stream
lock (readQueue) { readQueue.Clear(); }
WriteString("\r\nstopstream\r\n");
while (RetVal.CommTimeout != ReadByte(out znak)) { };
return RetVal.OK;
#else
// just report a running stream (RetVal.Busy)
return RetVal.Busy;
#endif
}
}
}
@@ -35,15 +35,13 @@ namespace TBF.BenchControl.GenericDevices
/// <summary>
/// Watermeter wheel/arrow detection process.
/// </summary>
/// <param name="roiId">Region of interest (1..4)</param>
/// <returns>Reference to operation object instance</returns>
IOperation DetectOp(int roiId, Cameras.IdcCamera.IWorkerCmd cmd);
IOperation DetectOp();
/// <summary>
/// Watermeter wheel/arrow angle measurement process.
/// </summary>
/// <param name="roiId">Region of interest (1..4)</param>
/// <returns>Reference to operation object instance</returns>
IOperation MeasureOp(int roiId, Cameras.IdcCamera.IWorkerCmd cmd);
IOperation MeasureOp();
}
}
@@ -126,15 +126,6 @@ namespace TBF.BenchControl.Sequences
IntBox remainingTime = new IntBox();
State startNew = State.Create("MainSeq : Emptying tanks, Starting cameras")
.AddOperation(checkUiOp);
foreach (var cmpnt in StateMachine.Components)
{
Cameras.IdcCamera.IdcCamera camera = cmpnt as Cameras.IdcCamera.IdcCamera;
if ((camera != null) && (camera.Cfg.DebugLevel != DebugMode.DetectedOff))
{
startNew.AddOperation(camera.StartNewOp());
}
}
IList<IValve> allEmptyingValves = new List<IValve>();
if (StateMachine.EmptyTankValve1 != null) allEmptyingValves.Add(StateMachine.EmptyTankValve1);
if (StateMachine.EmptyTankValve2 != null) allEmptyingValves.Add(StateMachine.EmptyTankValve2);
@@ -18,7 +18,6 @@ namespace TBF.BenchControl
Factories.Add(new ResultsPrinters.Basic.PrinterFactory());
Factories.Add(new BenchInfo.Munich.ComponentFactory());
Factories.Add(new BenchInfo.Polska.ComponentFactory());
Factories.Add(new Cameras.CameraRoi.CameraRoiFactory());
Factories.Add(new Elde.ControlBoardFactory());
Factories.Add(new DataEntry.Combined.EntryFormFactory());
Factories.Add(new DataEntry.HeatMeters6.Factory());
@@ -55,12 +54,11 @@ namespace TBF.BenchControl
Factories.Add(new TestMethods.OuterLoop.End.Factory());
Factories.Add(new TestMethods.PMaxTest.TestMethodFactory());
Factories.Add(new TestMethods.iPerlCommunication.TestMethodFactory()); /// iPerlCommunication
Factories.Add(new TestMethods.CameraRoiDetection.RoiDetectionFactory());
Factories.Add(new TestMethods.RoiDetection.RoiDetectionFactory());
Factories.Add(new TestMethods.ReferenceFlowmeterCalibration.TestMethodFactory());
Factories.Add(new DataEntry.WMStates.EntryFormFactory());
Factories.Add(new Ambient.Comet.Factory());
Factories.Add(new Ambient.Greco.Factory());
Factories.Add(new Cameras.IdcCamera.IdcCameraFactory());
Factories.Add(new WaterMeters.iPerl.WaterMeterFactory()); /// iPerl
Factories.Add(new Keithley.Multimeter_2010_RS232.Factory()); /// Keithley.Multimeter_2010_RS232
Factories.Add(new Keithley.TempMeter.Factory()); /// Keithley.TempMeter
@@ -1,5 +1,5 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
/// Copyright (c) 2017 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
@@ -7,12 +7,12 @@ using log4net;
using Config.Entities;
using TBF.BenchControl;
namespace TBF.BenchControl.TestMethods.CameraRoiDetection
namespace TBF.BenchControl.TestMethods.RoiDetection
{
public class RoiDetection : ComponentBase, GenericDevices.ITestMethod
{
private static readonly ILog log = LogManager.GetLogger(typeof(RoiDetection));
public override string ToString() { return string.Format("TestMethods.CameraRoiDetection({0})", Cfg.ToString(1)); }
public override string ToString() { return string.Format("TestMethods.RoiDetection({0})", Cfg.ToString(1)); }
public bool Evaluate(Test test) { return false; }
public bool Publish(Test test) { return false; }
@@ -1,5 +1,5 @@
///
/// Copyright (c) 2013-2016 Sensus Metering Systems
/// Copyright (c) 2017 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
@@ -7,7 +7,7 @@ using System.IO;
using System.Xml.Serialization;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.TestMethods.CameraRoiDetection
namespace TBF.BenchControl.TestMethods.RoiDetection
{
public class RoiDetectionCfg : ComponentCfgBase, Generic.IComponentCfg
{
@@ -1,12 +1,12 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
/// Copyright (c) 2017 Sensus Metering Systems
///
using System;
using System.Windows.Forms;
using log4net;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.TestMethods.CameraRoiDetection
namespace TBF.BenchControl.TestMethods.RoiDetection
{
public partial class RoiDetectionCfgCtrl : UserControl, IComponentCfgCtrl
{
@@ -1,7 +1,7 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
/// Copyright (c) 2017 Sensus Metering Systems
///
namespace TBF.BenchControl.TestMethods.CameraRoiDetection
namespace TBF.BenchControl.TestMethods.RoiDetection
{
partial class RoiDetectionCfgCtrl
{
@@ -1,14 +1,14 @@
///
/// Copyright (c) 2013-2016 Sensus Metering Systems
/// Copyright (c) 2017 Sensus Metering Systems
///
using System.Collections.Generic;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.TestMethods.CameraRoiDetection
namespace TBF.BenchControl.TestMethods.RoiDetection
{
public class RoiDetectionFactory : IComponentFactory
{
public string ClassName { get { return "ROI Detection"; } }
public string ClassName { get { return this.GetType().Namespace.Substring(17); } }
public void ResetStaticProperties() { RoiDetection.ResetStaticProperties(); }
@@ -1,5 +1,5 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
/// Copyright (c) 2017 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
@@ -9,7 +9,7 @@ using Config.Entities;
using TBF.Resources;
using TBF.UiBridge;
namespace TBF.BenchControl.TestMethods.CameraRoiDetection
namespace TBF.BenchControl.TestMethods.RoiDetection
{
public class RoiDetectionSeq : Sequences.SequenceBase
{
@@ -16,15 +16,6 @@ namespace TBF.Screens
Localize();
Bridge.CameraStateChangedHandler += delegate(object sender, CameraStateChangedEventArgs args)
{
if (InvokeRequired)
{
Invoke(new EventHandler<CameraStateChangedEventArgs>(OnCameraStateChanged), sender, args);
}
else OnCameraStateChanged(sender, args);
};
Bridge.ImageUpdatedHandler += delegate(object sender, ImageUpdatedEventArgs args)
{
if (InvokeRequired)
@@ -43,20 +34,6 @@ namespace TBF.Screens
focusButton.Text = Strings.Focus;
}
void OnCameraStateChanged(object sender, CameraStateChangedEventArgs args)
{
switch (args.CameraIdx)
{
case 0: cameraPictureCtrl1.CameraState = args.State; break;
case 1: cameraPictureCtrl2.CameraState = args.State; break;
case 2: cameraPictureCtrl3.CameraState = args.State; break;
case 3: cameraPictureCtrl4.CameraState = args.State; break;
case 4: cameraPictureCtrl5.CameraState = args.State; break;
case 5: cameraPictureCtrl6.CameraState = args.State; break;
default: break;
}
}
void OnImageUpdated(object sender, ImageUpdatedEventArgs args)
{
switch (args.CameraIdx)
+7 -51
View File
@@ -799,43 +799,6 @@
<Compile Include="PrintOrderDocument.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="BenchControl\Cameras\CameraRoi\CameraRoi.cs" />
<Compile Include="BenchControl\Cameras\CameraRoi\CameraRoiCfg.cs" />
<Compile Include="BenchControl\Cameras\CameraRoi\CameraRoiCfgCtrl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="BenchControl\Cameras\CameraRoi\CameraRoiCfgCtrl.designer.cs">
<DependentUpon>CameraRoiCfgCtrl.cs</DependentUpon>
</Compile>
<Compile Include="BenchControl\Cameras\CameraRoi\CameraRoiFactory.cs" />
<Compile Include="BenchControl\Cameras\CameraRoi\ReadRegisterOp.cs" />
<Compile Include="BenchControl\Cameras\CameraRoi\RoiProcedureParams.cs" />
<Compile Include="BenchControl\Cameras\IdcCamera\Command\Connect.cs" />
<Compile Include="BenchControl\Cameras\IdcCamera\Command\Disconnect.cs" />
<Compile Include="BenchControl\Cameras\IdcCamera\Command\StopOp.cs" />
<Compile Include="BenchControl\Cameras\IdcCamera\Command\StopStream.cs" />
<Compile Include="BenchControl\Cameras\IdcCamera\IWorkerCmd.cs" />
<Compile Include="BenchControl\Cameras\IdcCamera\Command\Detect.cs" />
<Compile Include="BenchControl\Cameras\IdcCamera\Command\Grab.cs" />
<Compile Include="BenchControl\Cameras\IdcCamera\IdcCamera.cs" />
<Compile Include="BenchControl\Cameras\IdcCamera\Idc100.cs" />
<Compile Include="BenchControl\Cameras\IdcCamera\IdcCameraCfg.cs" />
<Compile Include="BenchControl\Cameras\IdcCamera\IdcCameraCfgCtrl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="BenchControl\Cameras\IdcCamera\IdcCameraCfgCtrl.designer.cs">
<DependentUpon>IdcCameraCfgCtrl.cs</DependentUpon>
</Compile>
<Compile Include="BenchControl\Cameras\IdcCamera\IdcCameraFactory.cs" />
<Compile Include="BenchControl\Cameras\IdcCamera\IdcEnums.cs" />
<Compile Include="BenchControl\Cameras\IdcCamera\Command\Measure.cs" />
<Compile Include="BenchControl\Cameras\IdcCamera\Command\Other.cs" />
<Compile Include="BenchControl\Cameras\IdcCamera\Command\Save.cs" />
<Compile Include="BenchControl\Cameras\IdcCamera\SerialFileIO.cs" />
<Compile Include="BenchControl\Cameras\IdcCamera\SerialLayer.cs" />
<Compile Include="BenchControl\Cameras\IdcCamera\Command\SetBrightness.cs" />
<Compile Include="BenchControl\Cameras\IdcCamera\Command\StartNew.cs" />
<Compile Include="BenchControl\Cameras\IdcCamera\Command\Stream.cs" />
<Compile Include="BenchControl\CfgChangeArgs.cs" />
<Compile Include="BenchControl\CmdResponseArgs.cs" />
<Compile Include="BenchControl\ComponentBase.cs" />
@@ -1148,13 +1111,13 @@
<Compile Include="BenchControl\TestMethods\Adjustment\WMErrorsForm.designer.cs">
<DependentUpon>WMErrorsForm.cs</DependentUpon>
</Compile>
<Compile Include="BenchControl\TestMethods\CameraRoiDetection\RoiDetectionSeq.cs" />
<Compile Include="BenchControl\TestMethods\CameraRoiDetection\RoiDetection.cs" />
<Compile Include="BenchControl\TestMethods\CameraRoiDetection\RoiDetectionCfg.cs" />
<Compile Include="BenchControl\TestMethods\CameraRoiDetection\RoiDetectionCfgCtrl.cs">
<Compile Include="BenchControl\TestMethods\RoiDetection\RoiDetectionSeq.cs" />
<Compile Include="BenchControl\TestMethods\RoiDetection\RoiDetection.cs" />
<Compile Include="BenchControl\TestMethods\RoiDetection\RoiDetectionCfg.cs" />
<Compile Include="BenchControl\TestMethods\RoiDetection\RoiDetectionCfgCtrl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="BenchControl\TestMethods\CameraRoiDetection\RoiDetectionFactory.cs" />
<Compile Include="BenchControl\TestMethods\RoiDetection\RoiDetectionFactory.cs" />
<Compile Include="BenchControl\TestMethods\CombinedWithDetection\CombinedWithDetectionSeq.cs" />
<Compile Include="BenchControl\TestMethods\CombinedWithDetection\CombinedWithDetTestParams.cs" />
<Compile Include="BenchControl\TestMethods\CombinedWithDetection\TestMethod.cs" />
@@ -1168,7 +1131,7 @@
<Compile Include="BenchControl\TestMethods\CombinedWithDetection\TestMethodFactory.cs" />
<Compile Include="BenchControl\TestMethods\FixedStartMassCollection\FixedStartMassCollectionSeq.cs" />
<Compile Include="BenchControl\TestMethods\FlyingStartMassCollection\FlyingStartMassCollectionSeq.cs" />
<Compile Include="BenchControl\TestMethods\CameraRoiDetection\RoiDetectionCfgCtrl.designer.cs" />
<Compile Include="BenchControl\TestMethods\RoiDetection\RoiDetectionCfgCtrl.designer.cs" />
<Compile Include="BenchControl\TestMethods\FlyingStart\FlyingStartSeq.cs" />
<Compile Include="BenchControl\TestMethods\LeakTest\LeakTestSeq.cs" />
<Compile Include="BenchControl\TestMethods\LeakTest\LeakTestParams.cs" />
@@ -1502,7 +1465,6 @@
<Compile Include="UiBridge\AdjustmentInProgressEventArgs.cs" />
<Compile Include="UiBridge\Bridge.cs" />
<Compile Include="UiBridge\ButtonsEtcEventArgs.cs" />
<Compile Include="UiBridge\CameraStateChangedEventArgs.cs" />
<Compile Include="UiBridge\EmergencyStopEventArgs.cs" />
<Compile Include="UiBridge\Enums.cs" />
<Compile Include="UiBridge\ImageUpdatedEventArgs.cs" />
@@ -1623,12 +1585,6 @@
<EmbeddedResource Include="BenchControl\BenchInfo\Polska\ComponentCfgCtrl.resx">
<DependentUpon>ComponentCfgCtrl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="BenchControl\Cameras\CameraRoi\CameraRoiCfgCtrl.resx">
<DependentUpon>CameraRoiCfgCtrl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="BenchControl\Cameras\IdcCamera\IdcCameraCfgCtrl.resx">
<DependentUpon>IdcCameraCfgCtrl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="BenchControl\Configs\NameOnly\TestMethodCfgCtrl.resx">
<DependentUpon>TestMethodCfgCtrl.cs</DependentUpon>
</EmbeddedResource>
@@ -1887,7 +1843,7 @@
<EmbeddedResource Include="BenchControl\TestMethods\Adjustment\WMErrorsForm24.resx">
<DependentUpon>WMErrorsForm24.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="BenchControl\TestMethods\CameraRoiDetection\RoiDetectionCfgCtrl.resx">
<EmbeddedResource Include="BenchControl\TestMethods\RoiDetection\RoiDetectionCfgCtrl.resx">
<DependentUpon>RoiDetectionCfgCtrl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="BenchControl\TestMethods\CombinedWithDetection\TestMethodCfgCtrl.resx">
-12
View File
@@ -140,18 +140,6 @@ namespace TBF.UiBridge
public static event EventHandler<ProcedureCompletedEventArgs> ProcedureCompletedHandler;
/// <summary>
/// Called from the state machine when the procedure is completed and UI needs to be updated.
/// </summary>
public static void OnCameraStateChanged(object sender, CameraStateChangedEventArgs data)
{
if (CameraStateChangedHandler == null) return;
try { CameraStateChangedHandler(sender, data); }
catch (Exception e) { log.Error("CameraStateChangedHandler(...) failed", e); }
}
public static event EventHandler<CameraStateChangedEventArgs> CameraStateChangedHandler;
/// <summary>
/// Called from the state machine when the procedure is completed and UI needs to be updated.
/// </summary>
@@ -1,20 +0,0 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using TBF.BenchControl;
namespace TBF.UiBridge
{
class CameraStateChangedEventArgs : EventArgs
{
public int CameraIdx;
public BenchControl.Cameras.IdcCamera.IdcState State;
public CameraStateChangedEventArgs(int cameraIdx, BenchControl.Cameras.IdcCamera.IdcState state)
{
CameraIdx = cameraIdx;
State = state;
}
}
}
@@ -1,10 +1,9 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
/// Copyright (c) 2017 Sensus Metering Systems
///
using System;
using System.Drawing;
using System.Windows.Forms;
using TBF.BenchControl.Cameras.IdcCamera;
using TBF.Resources;
namespace TBF.UiControls
@@ -13,32 +12,6 @@ namespace TBF.UiControls
{
public PictureBox PictureBox { get { return pictureBox; } }
/// <summary>
/// Setting the state updated the background color
/// </summary>
public IdcState CameraState
{
set
{
switch (value)
{
case IdcState.NotConnected:
ledPictureBox.BackColor = Color.Gray;
break;
case IdcState.Busy:
ledPictureBox.BackColor = Color.Orange;
break;
case IdcState.Idle:
case IdcState.OpCompleted:
ledPictureBox.BackColor = Color.LawnGreen;
break;
default:
ledPictureBox.BackColor = Color.Tomato;
break;
}
}
}
public CameraPictureCtrl()
{
InitializeComponent();