617 lines
22 KiB
C#
617 lines
22 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 componentFactory;
|
|
IComponentFactory component2Factory;
|
|
|
|
IComponentCfg parentCfg;
|
|
IComponentCfg componentCfg;
|
|
IComponentCfg component2Cfg;
|
|
|
|
static IList<TBF.BenchControl.Generic.IDevice> tbfDevices;
|
|
static IList<TBF.BenchControl.Generic.IComponent> tbfComponents;
|
|
static TBF.BenchControl.Generic.IComponent tbfComponent4Op;
|
|
static TBF.BenchControl.Generic.IComponent tbfComponent24Op;
|
|
|
|
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 TBF.Boxes.FloatBox floatBox;
|
|
static Event evnt;
|
|
|
|
|
|
static DeviceTestDlg()
|
|
{
|
|
floatBox = new TBF.Boxes.FloatBox();
|
|
floatBox.Format = "F2";
|
|
}
|
|
|
|
public DeviceTestDlg()
|
|
{
|
|
InitializeComponent();
|
|
compClasses = new List<string>();
|
|
radioButton0.Checked = true;
|
|
stopButton.Enabled = false;
|
|
|
|
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);
|
|
componentClassNameComboBox.Items.Add(clName);
|
|
component2ClassNameComboBox.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 componentFactory);
|
|
|
|
using (var reader = new StringReader(Program.LocalSettings.ComponentSettings))
|
|
{
|
|
IComponentCfg config = (IComponentCfg)(new XmlSerializer(componentFactory.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 = componentFactory;
|
|
componentCfg = config;
|
|
}
|
|
|
|
componentClassNameComboBox.Text = Program.LocalSettings.ComponentClassName;
|
|
componentNameTextBox.Text = Program.LocalSettings.ComponentName;
|
|
|
|
UpdateOperations(componentClassNameComboBox.Text);
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
componentFactory = null;
|
|
componentCfg = null;
|
|
componentClassNameComboBox.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;
|
|
}
|
|
}
|
|
|
|
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 = componentClassNameComboBox.Text;
|
|
Program.LocalSettings.ComponentName = componentNameTextBox.Text;
|
|
Program.LocalSettings.ComponentParentName = componentCfg.ParentName;
|
|
Program.LocalSettings.ComponentSettings = (componentCfg != null) ? componentCfg.CreateDbEntity().Parameters : string.Empty;
|
|
|
|
Program.LocalSettings.Component2ClassName = component2ClassNameComboBox.Text;
|
|
Program.LocalSettings.Component2Name = component2NameTextBox.Text;
|
|
Program.LocalSettings.Component2ParentName = component2Cfg.ParentName;
|
|
Program.LocalSettings.Component2Settings = (component2Cfg != null) ? component2Cfg.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 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 radioButton21.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 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 radioButton20_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(); }
|
|
|
|
|
|
/// <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 configureComponentButton_Click(object sender, EventArgs e)
|
|
{
|
|
bool factoryChanged = FactoryFromClassName(componentClassNameComboBox.Text, ref componentFactory);
|
|
if (componentFactory == null)
|
|
{
|
|
MessageBox.Show("Invalid component class", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
return;
|
|
}
|
|
|
|
if (factoryChanged || componentCfg == null)
|
|
{
|
|
componentCfg = componentFactory.DefaultConfig();
|
|
}
|
|
IComponentCfgCtrl cfgControl = componentCfg.GetControl();
|
|
cfgControl.Config = componentCfg;
|
|
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 = componentCfg.Name;
|
|
|
|
UpdateOperations(componentClassNameComboBox.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 (componentFactory != null && componentCfg != null) compEntities.Add(componentCfg.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 startButton_Click(object sender, EventArgs e)
|
|
{
|
|
tbfComponents.Clear();
|
|
tbfDevices.Clear();
|
|
tbfComponent4Op = null;
|
|
operation1 = null;
|
|
operation2 = null;
|
|
operation3 = null;
|
|
operation4 = null;
|
|
tbfComponent24Op = null;
|
|
operation21 = null;
|
|
operation22 = null;
|
|
operation23 = null;
|
|
operation24 = 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 (componentFactory != null && componentCfg != null)
|
|
{
|
|
TBF.BenchControl.Generic.IComponent component = componentFactory.GetComponent(componentCfg, tbfComponents);
|
|
tbfComponents.Add(component);
|
|
tbfComponent4Op = 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);
|
|
tbfComponent24Op = component2;
|
|
IDevice dev = component2 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;
|
|
configureComponentButton.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;
|
|
configureComponentButton.Enabled = true;
|
|
configureParentButton.Enabled = true;
|
|
}
|
|
}
|
|
|
|
|
|
static void Worker()
|
|
{
|
|
int activeOperationLocal = 0;
|
|
int previousOperation = 0;
|
|
|
|
|
|
if (tbfComponent4Op is TBF.BenchControl.Modbus.PressureMeter.Meret.PressureMeter)
|
|
{
|
|
operation1 = (tbfComponent4Op as TBF.BenchControl.Modbus.PressureMeter.Meret.PressureMeter).ReadPressureOp(ref floatBox);
|
|
}
|
|
else if (tbfComponent4Op is TBF.BenchControl.Network.Camera.CLP1611.Camera)
|
|
{
|
|
operation1 = (tbfComponent4Op as TBF.BenchControl.Network.Camera.CLP1611.Camera).LiveStreamOp();
|
|
operation2 = (tbfComponent4Op as TBF.BenchControl.Network.Camera.CLP1611.Camera).HRLiveStreamOp();
|
|
}
|
|
else if (tbfComponent4Op is TBF.BenchControl.Network.Camera.Roi.Roi)
|
|
{
|
|
operation1 = (tbfComponent4Op as TBF.BenchControl.Network.Camera.Roi.Roi).RoiDetectionOp();
|
|
}
|
|
|
|
|
|
if (tbfComponent24Op is TBF.BenchControl.Modbus.PressureMeter.Meret.PressureMeter)
|
|
{
|
|
operation21 = (tbfComponent24Op as TBF.BenchControl.Modbus.PressureMeter.Meret.PressureMeter).ReadPressureOp(ref floatBox);
|
|
}
|
|
else if (tbfComponent24Op is TBF.BenchControl.Network.Camera.CLP1611.Camera)
|
|
{
|
|
operation21 = (tbfComponent24Op as TBF.BenchControl.Network.Camera.CLP1611.Camera).LiveStreamOp();
|
|
operation22 = (tbfComponent24Op as TBF.BenchControl.Network.Camera.CLP1611.Camera).HRLiveStreamOp();
|
|
}
|
|
else if (tbfComponent24Op is TBF.BenchControl.Network.Camera.Roi.Roi)
|
|
{
|
|
operation21 = (tbfComponent24Op as TBF.BenchControl.Network.Camera.Roi.Roi).RoiDetectionOp();
|
|
}
|
|
|
|
|
|
while (workerThreadRunning)
|
|
{
|
|
Thread.Sleep(1000);
|
|
|
|
if (workerThreadRunning)
|
|
{
|
|
foreach (var d in tbfDevices) d.RunDeviceBefore();
|
|
|
|
if (tbfComponent4Op != 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;
|
|
}
|
|
}
|
|
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;
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
configureComponent2Button.Enabled = true;
|
|
configureComponentButton.Enabled = true;
|
|
configureParentButton.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;
|
|
}
|
|
}
|
|
}
|