tbf/DeviceTest/DeviceTestDlg.cs

836 lines
32 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using TBF.BenchControl;
using TBF.BenchControl.Generic;
using TBF.BenchControl.GenericDevices;
using System.Xml.Serialization;
namespace DeviceTest
{
public partial class DeviceTestDlg : Form
{
IList<string> compClasses;
IComponentFactory parentFactory;
IComponentFactory component1Factory;
IComponentFactory component2Factory;
IComponentFactory component3Factory;
IComponentCfg parentCfg;
IComponentCfg component1Cfg;
IComponentCfg component2Cfg;
IComponentCfg component3Cfg;
static IList<TBF.BenchControl.Generic.IDevice> tbfDevices;
static IList<TBF.BenchControl.Generic.IComponent> tbfComponents;
static TBF.BenchControl.Generic.IComponent tbfComponent1forOp;
static TBF.BenchControl.Generic.IComponent tbfComponent2forOp;
static TBF.BenchControl.Generic.IComponent tbfComponent3forOp;
static Thread workerThread;
static bool workerThreadRunning;
static int activeOperationId;
static IOperation operation1;
static IOperation operation2;
static IOperation operation3;
static IOperation operation4;
static IOperation operation21;
static IOperation operation22;
static IOperation operation23;
static IOperation operation24;
static IOperation operation31;
static IOperation operation32;
static IOperation operation33;
static IOperation operation34;
static TBF.Boxes.FloatBox floatBox;
static Event evnt;
static DeviceTestDlg()
{
floatBox = new TBF.Boxes.FloatBox();
floatBox.Format = "F2";
}
public DeviceTestDlg()
{
InitializeComponent();
radioButton0.Checked = true;
stopButton.Enabled = false;
compClasses = new List<string>();
foreach (var componentFactory in TbfComponents.Factories)
{
compClasses.Add(componentFactory.ClassName);
}
tbfComponents = new List<TBF.BenchControl.Generic.IComponent>();
tbfDevices = new List<IDevice>();
}
private void DeviceTestDlg_Load(object sender, EventArgs e)
{
foreach (var clName in compClasses)
{
parentClassNameComboBox.Items.Add(clName);
component1ClassNameComboBox.Items.Add(clName);
component2ClassNameComboBox.Items.Add(clName);
component3ClassNameComboBox.Items.Add(clName);
}
try
{
if (!string.IsNullOrEmpty(Program.LocalSettings.ParentClassName) &&
!string.IsNullOrEmpty(Program.LocalSettings.ParentName) &&
!string.IsNullOrEmpty(Program.LocalSettings.ParentSettings))
{
FactoryFromClassName(Program.LocalSettings.ParentClassName, ref parentFactory);
using (var reader = new StringReader(Program.LocalSettings.ParentSettings))
{
IComponentCfg config = (IComponentCfg)(new XmlSerializer(parentFactory.DefaultConfig().GetType())).Deserialize(reader);
config.Name = Program.LocalSettings.ParentName;
config.ParentName = string.Empty;
config.ItemNr = 0;
config.DebugLevel = Config.Entities.DebugMode.Normal;
config.LogLevel = Config.Entities.LogLevel.Debug;
config.Corrections = null;
config.Factory = parentFactory;
parentCfg = config;
}
parentClassNameComboBox.Text = Program.LocalSettings.ParentClassName;
parentNameTextBox.Text = Program.LocalSettings.ParentName;
}
}
catch
{
parentFactory = null;
parentCfg = null;
parentClassNameComboBox.Text = string.Empty;
parentNameTextBox.Text = string.Empty;
}
try
{
if (!string.IsNullOrEmpty(Program.LocalSettings.ComponentClassName) &&
!string.IsNullOrEmpty(Program.LocalSettings.ComponentName) &&
!string.IsNullOrEmpty(Program.LocalSettings.ComponentSettings))
{
FactoryFromClassName(Program.LocalSettings.ComponentClassName, ref component1Factory);
using (var reader = new StringReader(Program.LocalSettings.ComponentSettings))
{
IComponentCfg config = (IComponentCfg)(new XmlSerializer(component1Factory.DefaultConfig().GetType())).Deserialize(reader);
config.Name = Program.LocalSettings.ComponentName;
config.ParentName = string.IsNullOrEmpty(Program.LocalSettings.ComponentParentName) ? string.Empty : Program.LocalSettings.ComponentParentName;
config.ItemNr = 1;
config.DebugLevel = Config.Entities.DebugMode.Normal;
config.LogLevel = Config.Entities.LogLevel.Debug;
config.Corrections = null;
config.Factory = component1Factory;
component1Cfg = config;
}
component1ClassNameComboBox.Text = Program.LocalSettings.ComponentClassName;
componentNameTextBox.Text = Program.LocalSettings.ComponentName;
UpdateOperations(component1ClassNameComboBox.Text);
}
}
catch
{
component1Factory = null;
component1Cfg = null;
component1ClassNameComboBox.Text = string.Empty;
componentNameTextBox.Text = string.Empty;
}
try
{
if (!string.IsNullOrEmpty(Program.LocalSettings.Component2ClassName) &&
!string.IsNullOrEmpty(Program.LocalSettings.Component2Name) &&
!string.IsNullOrEmpty(Program.LocalSettings.Component2Settings))
{
FactoryFromClassName(Program.LocalSettings.Component2ClassName, ref component2Factory);
using (var reader = new StringReader(Program.LocalSettings.Component2Settings))
{
IComponentCfg config = (IComponentCfg)(new XmlSerializer(component2Factory.DefaultConfig().GetType())).Deserialize(reader);
config.Name = Program.LocalSettings.Component2Name;
config.ParentName = string.IsNullOrEmpty(Program.LocalSettings.Component2ParentName) ? string.Empty : Program.LocalSettings.Component2ParentName;
config.ItemNr = 2;
config.DebugLevel = Config.Entities.DebugMode.Normal;
config.LogLevel = Config.Entities.LogLevel.Debug;
config.Corrections = null;
config.Factory = component2Factory;
component2Cfg = config;
}
component2ClassNameComboBox.Text = Program.LocalSettings.Component2ClassName;
component2NameTextBox.Text = Program.LocalSettings.Component2Name;
UpdateOperations2(component2ClassNameComboBox.Text);
}
}
catch
{
component2Factory = null;
component2Cfg = null;
component2ClassNameComboBox.Text = string.Empty;
component2NameTextBox.Text = string.Empty;
}
try
{
if (!string.IsNullOrEmpty(Program.LocalSettings.Component3ClassName) &&
!string.IsNullOrEmpty(Program.LocalSettings.Component3Name) &&
!string.IsNullOrEmpty(Program.LocalSettings.Component3Settings))
{
FactoryFromClassName(Program.LocalSettings.Component3ClassName, ref component3Factory);
using (var reader = new StringReader(Program.LocalSettings.Component3Settings))
{
IComponentCfg config = (IComponentCfg)(new XmlSerializer(component3Factory.DefaultConfig().GetType())).Deserialize(reader);
config.Name = Program.LocalSettings.Component3Name;
config.ParentName = string.IsNullOrEmpty(Program.LocalSettings.Component3ParentName) ? string.Empty : Program.LocalSettings.Component3ParentName;
config.ItemNr = 3;
config.DebugLevel = Config.Entities.DebugMode.Normal;
config.LogLevel = Config.Entities.LogLevel.Debug;
config.Corrections = null;
config.Factory = component3Factory;
component3Cfg = config;
}
component3ClassNameComboBox.Text = Program.LocalSettings.Component3ClassName;
component3NameTextBox.Text = Program.LocalSettings.Component3Name;
UpdateOperations3(component3ClassNameComboBox.Text);
}
}
catch
{
component3Factory = null;
component3Cfg = null;
component3ClassNameComboBox.Text = string.Empty;
component3NameTextBox.Text = string.Empty;
}
}
void SaveSettings()
{
Program.LocalSettings.ParentClassName = parentClassNameComboBox.Text;
Program.LocalSettings.ParentName = parentNameTextBox.Text;
Program.LocalSettings.ParentSettings = (parentCfg != null) ? parentCfg.CreateDbEntity().Parameters : string.Empty;
Program.LocalSettings.ComponentClassName = component1ClassNameComboBox.Text;
Program.LocalSettings.ComponentName = componentNameTextBox.Text;
Program.LocalSettings.ComponentParentName = (component1Cfg != null) ? component1Cfg.ParentName : string.Empty;
Program.LocalSettings.ComponentSettings = (component1Cfg != null) ? component1Cfg.CreateDbEntity().Parameters : string.Empty;
Program.LocalSettings.Component2ClassName = component2ClassNameComboBox.Text;
Program.LocalSettings.Component2Name = component2NameTextBox.Text;
Program.LocalSettings.Component2ParentName = (component2Cfg != null) ? component2Cfg.ParentName : string.Empty;
Program.LocalSettings.Component2Settings = (component2Cfg != null) ? component2Cfg.CreateDbEntity().Parameters : string.Empty;
Program.LocalSettings.Component3ClassName = component3ClassNameComboBox.Text;
Program.LocalSettings.Component3Name = component3NameTextBox.Text;
Program.LocalSettings.Component3ParentName = (component3Cfg != null) ? component3Cfg.ParentName : string.Empty;
Program.LocalSettings.Component3Settings = (component3Cfg != null) ? component3Cfg.CreateDbEntity().Parameters : string.Empty;
Program.LocalSettings.Save();
}
void UpdateOperations(string className)
{
if (className == "Keithley.TempMeter") radioButton1.Text = "ReadPressureOp";
else if (className == "Network.Camera.CLP1611") radioButton1.Text = "Livestream";
else if (className == "Network.Camera.Roi") radioButton1.Text = "RoiDetection";
else if (className == "Modbus.Easytherm")
{
radioButton1.Text = "SetTemperature(10)";
radioButton2.Text = "SetTemperature(20)";
}
else if (className == "Modbus.TankSelector")
{
radioButton1.Text = "SelectTank 1";
radioButton2.Text = "SelectTank 2";
radioButton3.Text = "SelectTank 3";
radioButton4.Text = "SelectTank -";
}
else radioButton1.Text = "spare";
}
///
void UpdateOperations2(string className)
{
if (className == "Keithley.TempMeter") radioButton21.Text = "ReadPressureOp";
else if (className == "Network.Camera.CLP1611") radioButton21.Text = "Livestream";
else if (className == "Network.Camera.Roi") radioButton21.Text = "RoiDetection";
else if (className == "Modbus.Easytherm")
{
radioButton21.Text = "SetTemperature(10)";
radioButton22.Text = "SetTemperature(20)";
}
else if (className == "Modbus.TankSelector")
{
radioButton21.Text = "SelectTank 1";
radioButton22.Text = "SelectTank 2";
radioButton23.Text = "SelectTank 3";
radioButton24.Text = "SelectTank -";
}
else radioButton21.Text = "spare";
}
///
void UpdateOperations3(string className)
{
if (className == "Keithley.TempMeter") radioButton31.Text = "ReadPressureOp";
else if (className == "Network.Camera.CLP1611") radioButton31.Text = "Livestream";
else if (className == "Network.Camera.Roi") radioButton31.Text = "RoiDetection";
else if (className == "Modbus.Easytherm")
{
radioButton31.Text = "SetTemperature(10)";
radioButton32.Text = "SetTemperature(20)";
}
else if (className == "Modbus.TankSelector")
{
radioButton31.Text = "SelectTank 1";
radioButton32.Text = "SelectTank 2";
radioButton33.Text = "SelectTank 3";
radioButton34.Text = "SelectTank -";
}
else radioButton31.Text = "spare";
}
int GetActiveOperationId()
{
if (radioButton1.Checked) { return 1; }
else if (radioButton2.Checked) { return 2; }
else if (radioButton3.Checked) { return 3; }
else if (radioButton4.Checked) { return 4; }
else if (radioButton21.Checked) { return 21; }
else if (radioButton22.Checked) { return 22; }
else if (radioButton23.Checked) { return 23; }
else if (radioButton24.Checked) { return 24; }
else if (radioButton31.Checked) { return 31; }
else if (radioButton32.Checked) { return 32; }
else if (radioButton33.Checked) { return 33; }
else if (radioButton34.Checked) { return 34; }
else return 0; /// stopOperationRadioButton.Checked
}
private void radioButton0_CheckedChanged(object sender, EventArgs e) { activeOperationId = GetActiveOperationId(); }
private void radioButton1_CheckedChanged(object sender, EventArgs e) { activeOperationId = GetActiveOperationId(); }
private void radioButton2_CheckedChanged(object sender, EventArgs e) { activeOperationId = GetActiveOperationId(); }
private void radioButton3_CheckedChanged(object sender, EventArgs e) { activeOperationId = GetActiveOperationId(); }
private void radioButton4_CheckedChanged(object sender, EventArgs e) { activeOperationId = GetActiveOperationId(); }
///
private void radioButton21_CheckedChanged(object sender, EventArgs e) { activeOperationId = GetActiveOperationId(); }
private void radioButton22_CheckedChanged(object sender, EventArgs e) { activeOperationId = GetActiveOperationId(); }
private void radioButton23_CheckedChanged(object sender, EventArgs e) { activeOperationId = GetActiveOperationId(); }
private void radioButton24_CheckedChanged(object sender, EventArgs e) { activeOperationId = GetActiveOperationId(); }
///
private void radioButton31_CheckedChanged(object sender, EventArgs e) { activeOperationId = GetActiveOperationId(); }
private void radioButton32_CheckedChanged(object sender, EventArgs e) { activeOperationId = GetActiveOperationId(); }
private void radioButton33_CheckedChanged(object sender, EventArgs e) { activeOperationId = GetActiveOperationId(); }
private void radioButton34_CheckedChanged(object sender, EventArgs e) { activeOperationId = GetActiveOperationId(); }
/// <summary>
/// Updates component factory
/// </summary>
/// <param name="className">Component class name</param>
/// <param name="factory">Reference to a factory</param>
/// <returns>true when factory changed</returns>
bool FactoryFromClassName(string className, ref IComponentFactory factory)
{
foreach (var fac in TbfComponents.Factories)
{
if (className == fac.ClassName)
{
if (factory != fac)
{
factory = fac;
return true;
}
else
{
return false;
}
}
}
if (factory != null)
{
factory = null;
return true;
}
return false;
}
private void configureParentButton_Click(object sender, EventArgs e)
{
bool factoryChanged = FactoryFromClassName(parentClassNameComboBox.Text, ref parentFactory);
if (parentFactory == null)
{
MessageBox.Show("Invalid parent class", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
if (factoryChanged || parentCfg == null)
{
parentCfg = parentFactory.DefaultConfig();
}
IComponentCfgCtrl cfgControl = parentCfg.GetControl();
cfgControl.Config = parentCfg;
cfgControl.Config.ItemNr = 0;
TBF.ComponentParametersDlg cfgForm = new TBF.ComponentParametersDlg();
cfgForm.TbfComponents = new List<Config.Entities.Component>();
cfgForm.ComponentCfgCtrl = cfgControl;
cfgForm.UnlockAfterStart = true;
DialogResult dr = cfgForm.ShowDialog();
if (dr != DialogResult.OK) return;
parentNameTextBox.Text = parentCfg.Name;
}
private void configureComponent1Button_Click(object sender, EventArgs e)
{
bool factoryChanged = FactoryFromClassName(component1ClassNameComboBox.Text, ref component1Factory);
if (component1Factory == null)
{
MessageBox.Show("Invalid component class", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
if (factoryChanged || component1Cfg == null)
{
component1Cfg = component1Factory.DefaultConfig();
}
IComponentCfgCtrl cfgControl = component1Cfg.GetControl();
cfgControl.Config = component1Cfg;
cfgControl.Config.ItemNr = 1;
TBF.ComponentParametersDlg cfgForm = new TBF.ComponentParametersDlg();
///
IList<Config.Entities.Component> compEntities = new List<Config.Entities.Component>();
if (parentFactory != null && parentCfg != null) compEntities.Add(parentCfg.CreateDbEntity());
cfgForm.TbfComponents = compEntities;
cfgForm.ComponentCfgCtrl = cfgControl;
cfgForm.UnlockAfterStart = true;
DialogResult dr = cfgForm.ShowDialog();
if (dr != DialogResult.OK) return;
componentNameTextBox.Text = component1Cfg.Name;
UpdateOperations(component1ClassNameComboBox.Text);
}
private void configureComponent2Button_Click(object sender, EventArgs e)
{
bool factoryChanged = FactoryFromClassName(component2ClassNameComboBox.Text, ref component2Factory);
if (component2Factory == null)
{
MessageBox.Show("Invalid component class", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
if (factoryChanged || component2Cfg == null)
{
component2Cfg = component2Factory.DefaultConfig();
}
IComponentCfgCtrl cfgControl = component2Cfg.GetControl();
cfgControl.Config = component2Cfg;
cfgControl.Config.ItemNr = 1;
TBF.ComponentParametersDlg cfgForm = new TBF.ComponentParametersDlg();
///
IList<Config.Entities.Component> compEntities = new List<Config.Entities.Component>();
if (parentFactory != null && parentCfg != null) compEntities.Add(parentCfg.CreateDbEntity());
if (component1Factory != null && component1Cfg != null) compEntities.Add(component1Cfg.CreateDbEntity());
cfgForm.TbfComponents = compEntities;
cfgForm.ComponentCfgCtrl = cfgControl;
cfgForm.UnlockAfterStart = true;
DialogResult dr = cfgForm.ShowDialog();
if (dr != DialogResult.OK) return;
component2NameTextBox.Text = component2Cfg.Name;
UpdateOperations2(component2ClassNameComboBox.Text);
}
private void configureComponent3Button_Click(object sender, EventArgs e)
{
bool factoryChanged = FactoryFromClassName(component3ClassNameComboBox.Text, ref component3Factory);
if (component3Factory == null)
{
MessageBox.Show("Invalid component class", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
if (factoryChanged || component3Cfg == null)
{
component3Cfg = component3Factory.DefaultConfig();
}
IComponentCfgCtrl cfgControl = component3Cfg.GetControl();
cfgControl.Config = component3Cfg;
cfgControl.Config.ItemNr = 1;
TBF.ComponentParametersDlg cfgForm = new TBF.ComponentParametersDlg();
///
IList<Config.Entities.Component> compEntities = new List<Config.Entities.Component>();
if (parentFactory != null && parentCfg != null) compEntities.Add(parentCfg.CreateDbEntity());
if (component1Factory != null && component1Cfg != null) compEntities.Add(component1Cfg.CreateDbEntity());
if (component2Factory != null && component2Cfg != null) compEntities.Add(component2Cfg.CreateDbEntity());
cfgForm.TbfComponents = compEntities;
cfgForm.ComponentCfgCtrl = cfgControl;
cfgForm.UnlockAfterStart = true;
DialogResult dr = cfgForm.ShowDialog();
if (dr != DialogResult.OK) return;
component3NameTextBox.Text = component3Cfg.Name;
UpdateOperations3(component3ClassNameComboBox.Text);
}
private void startButton_Click(object sender, EventArgs e)
{
tbfComponents.Clear();
tbfDevices.Clear();
tbfComponent1forOp = null;
operation1 = null;
operation2 = null;
operation3 = null;
operation4 = null;
tbfComponent2forOp = null;
operation21 = null;
operation22 = null;
operation23 = null;
operation24 = null;
tbfComponent3forOp = null;
operation31 = null;
operation32 = null;
operation33 = null;
operation34 = null;
workerThreadRunning = false;
string initializedDeviceName = "none";
try
{
if (parentFactory != null && parentCfg != null)
{
TBF.BenchControl.Generic.IComponent component = parentFactory.GetComponent(parentCfg, tbfComponents);
tbfComponents.Add(component);
IDevice dev = component as IDevice;
if (dev != null)
{
initializedDeviceName = dev.Name;
dev.Initialize();
tbfDevices.Add(dev);
}
}
if (component1Factory != null && component1Cfg != null)
{
TBF.BenchControl.Generic.IComponent component = component1Factory.GetComponent(component1Cfg, tbfComponents);
tbfComponents.Add(component);
tbfComponent1forOp = component;
IDevice dev = component as IDevice;
if (dev != null)
{
initializedDeviceName = dev.Name;
dev.Initialize();
tbfDevices.Add(dev);
}
}
if (component2Factory != null && component2Cfg != null)
{
TBF.BenchControl.Generic.IComponent component2 = component2Factory.GetComponent(component2Cfg, tbfComponents);
tbfComponents.Add(component2);
tbfComponent2forOp = component2;
IDevice dev = component2 as IDevice;
if (dev != null)
{
initializedDeviceName = dev.Name;
dev.Initialize();
tbfDevices.Add(dev);
}
}
if (component3Factory != null && component3Cfg != null)
{
TBF.BenchControl.Generic.IComponent component3 = component3Factory.GetComponent(component3Cfg, tbfComponents);
tbfComponents.Add(component3);
tbfComponent3forOp = component3;
IDevice dev = component3 as IDevice;
if (dev != null)
{
initializedDeviceName = dev.Name;
dev.Initialize();
tbfDevices.Add(dev);
}
}
if (tbfComponents.Count == 0) throw new Exception("There are no components");
SaveSettings(); /// Save settings after successful initialization
workerThread = new Thread(Worker);
workerThread.CurrentCulture = Thread.CurrentThread.CurrentCulture;
workerThread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
workerThreadRunning = true;
workerThread.Start();
startButton.Enabled = false;
stopButton.Enabled = true;
configureComponent2Button.Enabled = false;
configureComponent1Button.Enabled = false;
configureParentButton.Enabled = false;
}
catch (Exception exc)
{
workerThreadRunning = false;
workerThread = null;
MessageBox.Show(exc.Message,
string.Format("'{0}' initialization failed", initializedDeviceName),
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
foreach (var dev in tbfDevices) dev.StopDevice();
tbfDevices.Clear();
startButton.Enabled = true;
stopButton.Enabled = false;
configureComponent2Button.Enabled = true;
configureComponent1Button.Enabled = true;
configureParentButton.Enabled = true;
}
}
static void Worker()
{
int activeOperationLocal = 0;
int previousOperation = 0;
if (tbfComponent1forOp is TBF.BenchControl.Modbus.PressureMeter.Meret.PressureMeter)
{
operation1 = (tbfComponent1forOp as TBF.BenchControl.Modbus.PressureMeter.Meret.PressureMeter).ReadPressureOp(ref floatBox);
}
else if (tbfComponent1forOp is TBF.BenchControl.Network.Camera.CLP1611.Camera)
{
operation1 = (tbfComponent1forOp as TBF.BenchControl.Network.Camera.CLP1611.Camera).LiveStreamOp(false);
operation2 = (tbfComponent1forOp as TBF.BenchControl.Network.Camera.CLP1611.Camera).LiveStreamOp(true);
}
else if (tbfComponent1forOp is TBF.BenchControl.Network.Camera.Roi.Roi)
{
operation1 = (tbfComponent1forOp as TBF.BenchControl.Network.Camera.Roi.Roi).RoiDetectionOp();
}
else if (tbfComponent1forOp is TBF.BenchControl.Modbus.Easytherm.Easytherm)
{
operation1 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(10);
operation2 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(20);
}
else if (tbfComponent1forOp is TBF.BenchControl.Modbus.TankSelector.TankSelector)
{
//operation1 = (tbfComponent1forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(1);
//operation2 = (tbfComponent1forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(2);
//operation3 = (tbfComponent1forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(3);
//operation4 = (tbfComponent1forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(0);
}
if (tbfComponent2forOp is TBF.BenchControl.Modbus.PressureMeter.Meret.PressureMeter)
{
operation21 = (tbfComponent2forOp as TBF.BenchControl.Modbus.PressureMeter.Meret.PressureMeter).ReadPressureOp(ref floatBox);
}
else if (tbfComponent2forOp is TBF.BenchControl.Network.Camera.CLP1611.Camera)
{
operation21 = (tbfComponent2forOp as TBF.BenchControl.Network.Camera.CLP1611.Camera).LiveStreamOp(false);
operation22 = (tbfComponent2forOp as TBF.BenchControl.Network.Camera.CLP1611.Camera).LiveStreamOp(true);
}
else if (tbfComponent2forOp is TBF.BenchControl.Network.Camera.Roi.Roi)
{
operation21 = (tbfComponent2forOp as TBF.BenchControl.Network.Camera.Roi.Roi).RoiDetectionOp();
}
else if (tbfComponent2forOp is TBF.BenchControl.Modbus.Easytherm.Easytherm)
{
operation21 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(10);
operation22 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(20);
}
else if (tbfComponent2forOp is TBF.BenchControl.Modbus.TankSelector.TankSelector)
{
//operation21 = (tbfComponent2forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(1);
//operation22 = (tbfComponent2forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(2);
//operation23 = (tbfComponent2forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(3);
//operation24 = (tbfComponent2forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(0);
}
if (tbfComponent3forOp is TBF.BenchControl.Modbus.PressureMeter.Meret.PressureMeter)
{
operation31 = (tbfComponent3forOp as TBF.BenchControl.Modbus.PressureMeter.Meret.PressureMeter).ReadPressureOp(ref floatBox);
}
else if (tbfComponent3forOp is TBF.BenchControl.Network.Camera.CLP1611.Camera)
{
operation31 = (tbfComponent3forOp as TBF.BenchControl.Network.Camera.CLP1611.Camera).LiveStreamOp(false);
operation33 = (tbfComponent3forOp as TBF.BenchControl.Network.Camera.CLP1611.Camera).LiveStreamOp(true);
}
else if (tbfComponent3forOp is TBF.BenchControl.Network.Camera.Roi.Roi)
{
operation31 = (tbfComponent3forOp as TBF.BenchControl.Network.Camera.Roi.Roi).RoiDetectionOp();
}
else if (tbfComponent3forOp is TBF.BenchControl.Modbus.Easytherm.Easytherm)
{
operation31 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(10);
operation32 = (tbfComponent1forOp as TBF.BenchControl.Modbus.Easytherm.Easytherm).SetTemperatureOp(20);
}
else if (tbfComponent3forOp is TBF.BenchControl.Modbus.TankSelector.TankSelector)
{
//operation31 = (tbfComponent3forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(1);
//operation32 = (tbfComponent3forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(2);
//operation33 = (tbfComponent3forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(3);
//operation34 = (tbfComponent3forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(0);
}
while (workerThreadRunning)
{
Thread.Sleep(1000);
if (workerThreadRunning)
{
foreach (var d in tbfDevices) d.RunDeviceBefore();
if (tbfComponent1forOp != null)
{
previousOperation = activeOperationLocal;
activeOperationLocal = activeOperationId;
if (previousOperation == 0 && activeOperationLocal != 0)
{
switch (activeOperationLocal)
{
case 1: if (operation1 != null) operation1.Start(); Debug.WriteLine("op1.Start()"); break;
case 2: if (operation2 != null) operation2.Start(); Debug.WriteLine("op2.Start()"); break;
case 3: if (operation3 != null) operation3.Start(); Debug.WriteLine("op3.Start()"); break;
case 4: if (operation4 != null) operation4.Start(); Debug.WriteLine("op4.Start()"); break;
case 21: if (operation21 != null) operation21.Start(); Debug.WriteLine("op21.Start()"); break;
case 22: if (operation22 != null) operation22.Start(); Debug.WriteLine("op22.Start()"); break;
case 23: if (operation23 != null) operation23.Start(); Debug.WriteLine("op23.Start()"); break;
case 24: if (operation24 != null) operation24.Start(); Debug.WriteLine("op24.Start()"); break;
case 31: if (operation31 != null) operation31.Start(); Debug.WriteLine("op31.Start()"); break;
case 32: if (operation32 != null) operation32.Start(); Debug.WriteLine("op32.Start()"); break;
case 33: if (operation33 != null) operation33.Start(); Debug.WriteLine("op33.Start()"); break;
case 34: if (operation34 != null) operation34.Start(); Debug.WriteLine("op34.Start()"); break;
}
}
else if (previousOperation == activeOperationLocal && activeOperationLocal != 0)
{
switch (activeOperationLocal)
{
case 1: if (operation1 != null) evnt = operation1.Run(); Debug.WriteLine("op1.Run() -> {0}", evnt); break;
case 2: if (operation2 != null) evnt = operation2.Run(); Debug.WriteLine("op2.Run() -> {0}", evnt); break;
case 3: if (operation3 != null) evnt = operation3.Run(); Debug.WriteLine("op3.Run() -> {0}", evnt); break;
case 4: if (operation4 != null) evnt = operation4.Run(); Debug.WriteLine("op4.Run() -> {0}", evnt); break;
case 21: if (operation21 != null) evnt = operation21.Run(); Debug.WriteLine("op21.Run() -> {0}", evnt); break;
case 22: if (operation22 != null) evnt = operation22.Run(); Debug.WriteLine("op22.Run() -> {0}", evnt); break;
case 23: if (operation23 != null) evnt = operation23.Run(); Debug.WriteLine("op23.Run() -> {0}", evnt); break;
case 24: if (operation24 != null) evnt = operation24.Run(); Debug.WriteLine("op24.Run() -> {0}", evnt); break;
case 31: if (operation31 != null) evnt = operation31.Run(); Debug.WriteLine("op31.Run() -> {0}", evnt); break;
case 32: if (operation32 != null) evnt = operation32.Run(); Debug.WriteLine("op32.Run() -> {0}", evnt); break;
case 33: if (operation33 != null) evnt = operation33.Run(); Debug.WriteLine("op33.Run() -> {0}", evnt); break;
case 34: if (operation34 != null) evnt = operation34.Run(); Debug.WriteLine("op34.Run() -> {0}", evnt); break;
default: evnt = Event.None; break;
}
}
else if (previousOperation != 0 && activeOperationLocal == 0)
{
switch (previousOperation)
{
case 1: if (operation1 != null) operation1.Stop(); Debug.WriteLine("op1.Stop()"); break;
case 2: if (operation2 != null) operation2.Stop(); Debug.WriteLine("op2.Stop()"); break;
case 3: if (operation3 != null) operation3.Stop(); Debug.WriteLine("op3.Stop()"); break;
case 4: if (operation4 != null) operation4.Stop(); Debug.WriteLine("op4.Stop()"); break;
case 21: if (operation21 != null) operation21.Stop(); Debug.WriteLine("op21.Stop()"); break;
case 22: if (operation22 != null) operation22.Stop(); Debug.WriteLine("op22.Stop()"); break;
case 23: if (operation23 != null) operation23.Stop(); Debug.WriteLine("op23.Stop()"); break;
case 24: if (operation24 != null) operation24.Stop(); Debug.WriteLine("op24.Stop()"); break;
case 31: if (operation31 != null) operation31.Stop(); Debug.WriteLine("op31.Stop()"); break;
case 32: if (operation32 != null) operation32.Stop(); Debug.WriteLine("op32.Stop()"); break;
case 33: if (operation33 != null) operation33.Stop(); Debug.WriteLine("op33.Stop()"); break;
case 34: if (operation34 != null) operation34.Stop(); Debug.WriteLine("op34.Stop()"); break;
}
}
}
foreach (var d in tbfDevices) d.RunDeviceAfter();
}
}
foreach (var d in tbfDevices) d.StopDevice();
}
private void stopButton_Click(object sender, EventArgs e)
{
Cursor = Cursors.WaitCursor;
workerThreadRunning = false;
workerThread.Join(5000);
workerThread = null;
Cursor = Cursors.Default;
startButton.Enabled = true;
stopButton.Enabled = false;
configureParentButton.Enabled = true;
configureComponent1Button.Enabled = true;
configureComponent2Button.Enabled = true;
configureComponent3Button.Enabled = true;
}
private void DeviceTestDlg_FormClosing(object sender, FormClosingEventArgs e)
{
Cursor = Cursors.WaitCursor;
if (workerThread != null)
{
workerThreadRunning = false;
workerThread.Join(3000);
workerThread = null;
}
Cursor = Cursors.Default;
SaveSettings();
Cursor = Cursors.Default;
}
}
}