2016-10-11 14:18:54 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2016-10-18 07:52:17 +00:00
|
|
|
|
using System.Diagnostics;
|
2016-10-18 11:15:15 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Text;
|
2016-10-16 20:43:55 +00:00
|
|
|
|
using System.Threading;
|
2016-10-11 14:18:54 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
using TBF.BenchControl;
|
2016-10-14 12:28:23 +00:00
|
|
|
|
using TBF.BenchControl.Generic;
|
2016-10-18 07:52:17 +00:00
|
|
|
|
using TBF.BenchControl.GenericDevices;
|
2016-10-18 11:15:15 +00:00
|
|
|
|
using System.Xml.Serialization;
|
2016-10-14 12:28:23 +00:00
|
|
|
|
|
2016-10-11 14:18:54 +00:00
|
|
|
|
|
|
|
|
|
|
namespace DeviceTest
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class DeviceTestDlg : Form
|
|
|
|
|
|
{
|
|
|
|
|
|
IList<string> compClasses;
|
|
|
|
|
|
|
2016-10-14 12:28:23 +00:00
|
|
|
|
IComponentFactory parentFactory;
|
|
|
|
|
|
IComponentFactory componentFactory;
|
|
|
|
|
|
|
|
|
|
|
|
IComponentCfg parentCfg;
|
|
|
|
|
|
IComponentCfg componentCfg;
|
|
|
|
|
|
|
2016-10-16 20:43:55 +00:00
|
|
|
|
static IList<TBF.BenchControl.Generic.IDevice> tbfDevices;
|
2016-10-18 07:52:17 +00:00
|
|
|
|
static IList<TBF.BenchControl.Generic.IComponent> tbfComponents;
|
|
|
|
|
|
static TBF.BenchControl.Generic.IComponent tbfComponent4Op;
|
2016-10-16 20:43:55 +00:00
|
|
|
|
|
|
|
|
|
|
static Thread workerThread;
|
2016-10-18 07:52:17 +00:00
|
|
|
|
static bool workerThreadRunning;
|
|
|
|
|
|
|
|
|
|
|
|
static int activeOperationId;
|
|
|
|
|
|
|
|
|
|
|
|
static TBF.Boxes.FloatBox floatBox;
|
|
|
|
|
|
|
|
|
|
|
|
static IOperation operation1;
|
|
|
|
|
|
static IOperation operation2;
|
|
|
|
|
|
static IOperation operation3;
|
|
|
|
|
|
static IOperation operation4;
|
|
|
|
|
|
|
|
|
|
|
|
static Event evnt;
|
|
|
|
|
|
|
|
|
|
|
|
static DeviceTestDlg()
|
|
|
|
|
|
{
|
|
|
|
|
|
floatBox = new TBF.Boxes.FloatBox();
|
2016-10-18 11:15:15 +00:00
|
|
|
|
floatBox.Format = "F2";
|
2016-10-18 07:52:17 +00:00
|
|
|
|
}
|
2016-10-14 12:28:23 +00:00
|
|
|
|
|
2016-10-11 14:18:54 +00:00
|
|
|
|
public DeviceTestDlg()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
compClasses = new List<string>();
|
2016-10-18 07:52:17 +00:00
|
|
|
|
radioButton0.Checked = true;
|
|
|
|
|
|
stopButton.Enabled = false;
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var componentFactory in TbfComponents.Factories)
|
2016-10-11 14:18:54 +00:00
|
|
|
|
{
|
|
|
|
|
|
compClasses.Add(componentFactory.ClassName);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void DeviceTestDlg_Load(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2016-10-16 20:43:55 +00:00
|
|
|
|
|
|
|
|
|
|
foreach (var clName in compClasses)
|
|
|
|
|
|
{
|
|
|
|
|
|
parentClassNameComboBox.Items.Add(clName);
|
2016-10-18 11:15:15 +00:00
|
|
|
|
componentClassNameComboBox.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;
|
2016-12-29 14:15:45 +00:00
|
|
|
|
config.ParentName = string.IsNullOrEmpty(Program.LocalSettings.ParentComponentName) ? string.Empty : Program.LocalSettings.ParentComponentName;
|
2016-10-18 11:15:15 +00:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
componentFactory = null;
|
|
|
|
|
|
componentCfg = null;
|
|
|
|
|
|
componentClassNameComboBox.Text = string.Empty;
|
|
|
|
|
|
componentNameTextBox.Text = string.Empty;
|
2016-10-16 20:43:55 +00:00
|
|
|
|
}
|
2016-10-11 14:18:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-10-18 11:15:15 +00:00
|
|
|
|
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;
|
2016-12-29 14:15:45 +00:00
|
|
|
|
Program.LocalSettings.ParentComponentName = componentCfg.ParentName;
|
2016-10-18 11:15:15 +00:00
|
|
|
|
Program.LocalSettings.ComponentSettings = (componentCfg != null) ? componentCfg.CreateDbEntity().Parameters : string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
Program.LocalSettings.Save();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-10-16 20:43:55 +00:00
|
|
|
|
|
2016-10-18 07:52:17 +00:00
|
|
|
|
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(); }
|
|
|
|
|
|
|
|
|
|
|
|
int GetActiveOperationId()
|
|
|
|
|
|
{
|
2016-10-18 11:15:15 +00:00
|
|
|
|
if (radioButton1.Checked) return 1;
|
2016-10-18 07:52:17 +00:00
|
|
|
|
else if (radioButton2.Checked) return 2;
|
|
|
|
|
|
else if (radioButton3.Checked) return 3;
|
|
|
|
|
|
else if (radioButton4.Checked) return 4;
|
|
|
|
|
|
else return 0; /// stopOperationRadioButton.Checked
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-10-18 11:15:15 +00:00
|
|
|
|
/// <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)
|
2016-10-14 12:28:23 +00:00
|
|
|
|
{
|
2016-10-18 11:15:15 +00:00
|
|
|
|
if (className == fac.ClassName)
|
2016-10-14 12:28:23 +00:00
|
|
|
|
{
|
2016-10-18 11:15:15 +00:00
|
|
|
|
if (factory != fac)
|
2016-10-16 20:43:55 +00:00
|
|
|
|
{
|
2016-10-18 11:15:15 +00:00
|
|
|
|
factory = fac;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
2016-10-16 20:43:55 +00:00
|
|
|
|
}
|
2016-10-14 12:28:23 +00:00
|
|
|
|
}
|
2016-10-16 20:43:55 +00:00
|
|
|
|
}
|
2016-10-18 11:15:15 +00:00
|
|
|
|
|
|
|
|
|
|
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)
|
2016-10-16 20:43:55 +00:00
|
|
|
|
{
|
2016-10-18 11:15:15 +00:00
|
|
|
|
MessageBox.Show("Invalid parent class", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
2016-10-14 12:28:23 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-10-16 20:43:55 +00:00
|
|
|
|
if (factoryChanged || parentCfg == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
parentCfg = parentFactory.DefaultConfig();
|
|
|
|
|
|
}
|
|
|
|
|
|
IComponentCfgCtrl cfgControl = parentCfg.GetControl();
|
|
|
|
|
|
cfgControl.Config = parentCfg;
|
2016-10-14 12:28:23 +00:00
|
|
|
|
cfgControl.Config.ItemNr = 0;
|
2016-10-11 14:18:54 +00:00
|
|
|
|
|
2016-10-14 12:28:23 +00:00
|
|
|
|
TBF.ComponentParametersDlg cfgForm = new TBF.ComponentParametersDlg();
|
|
|
|
|
|
cfgForm.TbfComponents = new List<Config.Entities.Component>();
|
2016-10-16 20:43:55 +00:00
|
|
|
|
|
2016-10-14 12:28:23 +00:00
|
|
|
|
cfgForm.ComponentCfgCtrl = cfgControl;
|
|
|
|
|
|
cfgForm.UnlockAfterStart = true;
|
|
|
|
|
|
DialogResult dr = cfgForm.ShowDialog();
|
|
|
|
|
|
if (dr != DialogResult.OK) return;
|
|
|
|
|
|
|
2016-10-16 20:43:55 +00:00
|
|
|
|
parentNameTextBox.Text = parentCfg.Name;
|
2016-10-11 14:18:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-10-16 20:43:55 +00:00
|
|
|
|
|
2016-10-14 12:28:23 +00:00
|
|
|
|
private void configureButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2016-10-18 11:15:15 +00:00
|
|
|
|
bool factoryChanged = FactoryFromClassName(componentClassNameComboBox.Text, ref componentFactory);
|
|
|
|
|
|
if (componentFactory == null)
|
2016-10-16 20:43:55 +00:00
|
|
|
|
{
|
2016-10-18 11:15:15 +00:00
|
|
|
|
MessageBox.Show("Invalid component class", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
2016-10-16 20:43:55 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2016-10-14 12:28:23 +00:00
|
|
|
|
|
2016-10-16 20:43:55 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
2016-10-18 11:15:15 +00:00
|
|
|
|
componentNameTextBox.Text = componentCfg.Name;
|
2016-10-14 12:28:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-10-16 20:43:55 +00:00
|
|
|
|
|
2016-10-18 07:52:17 +00:00
|
|
|
|
private void startButton_Click(object sender, EventArgs e)
|
2016-10-14 12:28:23 +00:00
|
|
|
|
{
|
2016-10-16 20:43:55 +00:00
|
|
|
|
tbfComponents = new List<TBF.BenchControl.Generic.IComponent>();
|
|
|
|
|
|
tbfDevices = new List<IDevice>();
|
2016-10-18 07:52:17 +00:00
|
|
|
|
tbfComponent4Op = null;
|
|
|
|
|
|
operation1 = null;
|
|
|
|
|
|
operation2 = null;
|
|
|
|
|
|
operation3 = null;
|
|
|
|
|
|
operation4 = null;
|
|
|
|
|
|
workerThreadRunning = false;
|
2016-10-16 20:43:55 +00:00
|
|
|
|
|
2016-12-29 11:30:31 +00:00
|
|
|
|
string initializedDeviceName = "none";
|
2016-10-16 20:43:55 +00:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (parentFactory != null && parentCfg != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
TBF.BenchControl.Generic.IComponent component = parentFactory.GetComponent(parentCfg, tbfComponents);
|
|
|
|
|
|
tbfComponents.Add(component);
|
|
|
|
|
|
if (component is IDevice) tbfDevices.Add(component as IDevice);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (componentFactory != null && componentCfg != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
TBF.BenchControl.Generic.IComponent component = componentFactory.GetComponent(componentCfg, tbfComponents);
|
|
|
|
|
|
tbfComponents.Add(component);
|
2016-10-18 07:52:17 +00:00
|
|
|
|
tbfComponent4Op = component;
|
2016-10-16 20:43:55 +00:00
|
|
|
|
if (component is IDevice) tbfDevices.Add(component as IDevice);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (tbfComponents.Count == 0) throw new Exception("There are no components");
|
|
|
|
|
|
|
2016-12-29 14:15:45 +00:00
|
|
|
|
foreach (var d in tbfDevices)
|
|
|
|
|
|
{
|
2016-12-29 11:30:31 +00:00
|
|
|
|
initializedDeviceName = d.Name;
|
2016-12-29 14:15:45 +00:00
|
|
|
|
d.Initialize();
|
|
|
|
|
|
}
|
2016-10-14 12:28:23 +00:00
|
|
|
|
|
2016-10-18 11:15:15 +00:00
|
|
|
|
SaveSettings(); /// Save settings after successful initialization
|
|
|
|
|
|
|
2016-10-16 20:43:55 +00:00
|
|
|
|
workerThread = new Thread(Worker);
|
|
|
|
|
|
workerThread.CurrentCulture = Thread.CurrentThread.CurrentCulture;
|
|
|
|
|
|
workerThread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
|
2016-10-18 07:52:17 +00:00
|
|
|
|
workerThreadRunning = true;
|
2016-10-16 20:43:55 +00:00
|
|
|
|
workerThread.Start();
|
2016-10-18 07:52:17 +00:00
|
|
|
|
|
|
|
|
|
|
startButton.Enabled = false;
|
|
|
|
|
|
stopButton.Enabled = true;
|
|
|
|
|
|
configureButton.Enabled = false;
|
|
|
|
|
|
configureParentButton.Enabled = false;
|
2016-10-16 20:43:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception exc)
|
|
|
|
|
|
{
|
2016-10-18 07:52:17 +00:00
|
|
|
|
workerThreadRunning = false;
|
|
|
|
|
|
workerThread = null;
|
|
|
|
|
|
|
2016-12-29 11:30:31 +00:00
|
|
|
|
MessageBox.Show(exc.Message,
|
|
|
|
|
|
string.Format("'{0}' initialization failed", initializedDeviceName),
|
|
|
|
|
|
MessageBoxButtons.OK,
|
|
|
|
|
|
MessageBoxIcon.Exclamation);
|
2016-10-18 07:52:17 +00:00
|
|
|
|
|
|
|
|
|
|
startButton.Enabled = true;
|
|
|
|
|
|
stopButton.Enabled = false;
|
2016-10-16 20:43:55 +00:00
|
|
|
|
configureButton.Enabled = true;
|
|
|
|
|
|
configureParentButton.Enabled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-10-14 12:28:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-10-11 14:18:54 +00:00
|
|
|
|
|
2016-10-18 07:52:17 +00:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
2016-12-29 11:30:31 +00:00
|
|
|
|
else if (tbfComponent4Op is TBF.BenchControl.Network.Camera.CLP1611.Camera)
|
|
|
|
|
|
{
|
|
|
|
|
|
operation1 = (tbfComponent4Op as TBF.BenchControl.Network.Camera.CLP1611.Camera).LiveStreamOp();
|
|
|
|
|
|
}
|
2016-10-18 07:52:17 +00:00
|
|
|
|
|
|
|
|
|
|
while (workerThreadRunning)
|
|
|
|
|
|
{
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
|
|
|
|
|
|
if (workerThreadRunning)
|
|
|
|
|
|
{
|
2016-12-29 11:30:31 +00:00
|
|
|
|
foreach (var d in tbfDevices) d.RunDeviceBefore();
|
2016-10-18 07:52:17 +00:00
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (previousOperation == activeOperationLocal && activeOperationLocal != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (activeOperationLocal)
|
|
|
|
|
|
{
|
2016-10-18 11:15:15 +00:00
|
|
|
|
case 1: if (operation1 != null) evnt = operation1.Run(); Debug.WriteLine("op1.Run() -> {0}, pressure = {1} kPa", evnt, floatBox); break;
|
2016-10-18 07:52:17 +00:00
|
|
|
|
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;
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-12-29 11:30:31 +00:00
|
|
|
|
foreach (var d in tbfDevices) d.RunDeviceAfter();
|
2016-10-18 07:52:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-12-29 11:30:31 +00:00
|
|
|
|
foreach (var d in tbfDevices) d.StopDevice();
|
2016-10-18 07:52:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void stopButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2016-10-18 11:15:15 +00:00
|
|
|
|
Cursor = Cursors.WaitCursor;
|
|
|
|
|
|
|
2016-10-18 07:52:17 +00:00
|
|
|
|
workerThreadRunning = false;
|
|
|
|
|
|
workerThread.Join(3000);
|
|
|
|
|
|
workerThread = null;
|
|
|
|
|
|
|
2016-10-18 11:15:15 +00:00
|
|
|
|
Cursor = Cursors.Default;
|
|
|
|
|
|
|
2016-10-16 20:43:55 +00:00
|
|
|
|
startButton.Enabled = true;
|
|
|
|
|
|
stopButton.Enabled = false;
|
2016-10-18 07:52:17 +00:00
|
|
|
|
configureButton.Enabled = true;
|
|
|
|
|
|
configureParentButton.Enabled = true;
|
2016-10-16 20:43:55 +00:00
|
|
|
|
}
|
2016-10-11 14:18:54 +00:00
|
|
|
|
|
2016-10-18 07:52:17 +00:00
|
|
|
|
private void DeviceTestDlg_FormClosing(object sender, FormClosingEventArgs e)
|
2016-10-16 20:43:55 +00:00
|
|
|
|
{
|
2016-10-18 11:15:15 +00:00
|
|
|
|
Cursor = Cursors.WaitCursor;
|
|
|
|
|
|
|
2016-10-18 07:52:17 +00:00
|
|
|
|
if (workerThread != null)
|
2016-10-16 20:43:55 +00:00
|
|
|
|
{
|
2016-10-18 07:52:17 +00:00
|
|
|
|
workerThreadRunning = false;
|
|
|
|
|
|
workerThread.Join(3000);
|
|
|
|
|
|
workerThread = null;
|
2016-10-16 20:43:55 +00:00
|
|
|
|
}
|
2016-10-18 11:15:15 +00:00
|
|
|
|
|
|
|
|
|
|
SaveSettings();
|
|
|
|
|
|
|
|
|
|
|
|
Cursor = Cursors.Default;
|
2016-10-16 20:43:55 +00:00
|
|
|
|
}
|
2016-10-11 14:18:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|