diff --git a/DeviceTest/DeviceTestDlg.cs b/DeviceTest/DeviceTestDlg.cs index 4b89aefb5..fa1e6fc61 100644 --- a/DeviceTest/DeviceTestDlg.cs +++ b/DeviceTest/DeviceTestDlg.cs @@ -58,7 +58,10 @@ namespace DeviceTest { compClasses.Add(componentFactory.ClassName); } - } + + tbfComponents = new List(); + tbfDevices = new List(); + } private void DeviceTestDlg_Load(object sender, EventArgs e) { @@ -262,8 +265,8 @@ namespace DeviceTest private void startButton_Click(object sender, EventArgs e) { - tbfComponents = new List(); - tbfDevices = new List(); + tbfComponents.Clear(); + tbfDevices.Clear(); tbfComponent4Op = null; operation1 = null; operation2 = null; @@ -278,24 +281,30 @@ namespace DeviceTest { TBF.BenchControl.Generic.IComponent component = parentFactory.GetComponent(parentCfg, tbfComponents); tbfComponents.Add(component); - if (component is IDevice) tbfDevices.Add(component as IDevice); + 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; - if (component is IDevice) tbfDevices.Add(component as IDevice); + tbfComponent4Op = component; + IDevice dev = component as IDevice; + if (dev != null) + { + initializedDeviceName = dev.Name; + dev.Initialize(); + tbfDevices.Add(dev); + } } if (tbfComponents.Count == 0) throw new Exception("There are no components"); - foreach (var d in tbfDevices) - { - initializedDeviceName = d.Name; - d.Initialize(); - } - SaveSettings(); /// Save settings after successful initialization workerThread = new Thread(Worker); @@ -319,6 +328,9 @@ namespace DeviceTest MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + foreach (var dev in tbfDevices) dev.StopDevice(); + tbfDevices.Clear(); + startButton.Enabled = true; stopButton.Enabled = false; configureButton.Enabled = true; @@ -399,7 +411,7 @@ namespace DeviceTest Cursor = Cursors.WaitCursor; workerThreadRunning = false; - workerThread.Join(3000); + workerThread.Join(5000); workerThread = null; Cursor = Cursors.Default; @@ -421,6 +433,8 @@ namespace DeviceTest workerThread = null; } + Cursor = Cursors.Default; + SaveSettings(); Cursor = Cursors.Default; diff --git a/TestBenchFramework/BenchControl/Network/Adapter/Netadapter.cs b/TestBenchFramework/BenchControl/Network/Adapter/Netadapter.cs index b72955117..370f17f07 100644 --- a/TestBenchFramework/BenchControl/Network/Adapter/Netadapter.cs +++ b/TestBenchFramework/BenchControl/Network/Adapter/Netadapter.cs @@ -14,6 +14,9 @@ namespace TBF.BenchControl.Network.Adapter return string.Format("Component={0} IPAddress={1} NetMask={2} Description={3}", Cfg.Name, IPAddress, NetMask, (Cfg as NetadapterCfg).Description); } + public bool Running { get { return running; } } + bool running; + readonly NetadapterCfg netadapterCfg; readonly IPAddress ipAddress; readonly IPAddress netMask; @@ -39,6 +42,8 @@ namespace TBF.BenchControl.Network.Adapter netMask = netadapter.NetMask; broadcastAddress = netadapter.GetBroadcastAddress(); + running = false; + log.Debug(this.ToString()); } @@ -57,6 +62,10 @@ namespace TBF.BenchControl.Network.Adapter tftpServer = null; } } + + running = true; + + log.FatalFormat("Successfully initialized device {0}", ToString()); } public void StopDevice() @@ -65,6 +74,8 @@ namespace TBF.BenchControl.Network.Adapter { if (tftpServer != null) tftpServer.Stop(); } + + running = false; } public void RunDeviceBefore() {} diff --git a/TestBenchFramework/BenchControl/Network/Camera/CLP1611/Camera.cs b/TestBenchFramework/BenchControl/Network/Camera/CLP1611/Camera.cs index 0f3c5d3b1..202a51245 100644 --- a/TestBenchFramework/BenchControl/Network/Camera/CLP1611/Camera.cs +++ b/TestBenchFramework/BenchControl/Network/Camera/CLP1611/Camera.cs @@ -15,10 +15,6 @@ namespace TBF.BenchControl.Network.Camera.CLP1611 { public class Camera : ComponentBase, Generic.IDevice { - const string ClpUserName = "tbf"; - const string ClpPassword = "C1ern4V0d4"; - const string ClpPrompt = "$ "; - private static readonly ILog log = LogManager.GetLogger(typeof(Camera)); public override string ToString() { @@ -31,6 +27,14 @@ namespace TBF.BenchControl.Network.Camera.CLP1611 string.IsNullOrEmpty(image) ? "not detected" : image); } + public bool Running { get { return running; } } + bool running; + + + const string ClpUserName = "tbf"; + const string ClpPassword = "C1ern4V0d4"; + const string ClpPrompt = "$ "; + readonly CameraCfg cameraCfg; readonly GenericDevices.INetworkAdapter netAdapter; @@ -65,6 +69,11 @@ namespace TBF.BenchControl.Network.Camera.CLP1611 netAdapter = TbfComponents.FindComponent(cfg.ParentName, components) as GenericDevices.INetworkAdapter; if (netAdapter == null) throw new ArgumentNullException("no network adapter"); + telnet = null; + terminalDlg = null; + + running = false; + log.Debug(this.ToString()); } @@ -74,10 +83,12 @@ namespace TBF.BenchControl.Network.Camera.CLP1611 { if (cameraCfg.DebugLevel == DebugMode.Simulate) return; + /// Detect a camera bool cameraDetected = DetectCamera(cameraCfg.HardwareAddress, true, out ipAddress, out hardware, out revision, out serial, out image); if (!cameraDetected) throw new Exception("No camera detected"); + /// Open telnet clint and start the log-in process telnet = new Telnet.TelnetClient(this, cameraCfg.Name, ClpUserName, ClpPassword, ClpPrompt); if (cameraCfg.DisplayTerminal) @@ -88,6 +99,8 @@ namespace TBF.BenchControl.Network.Camera.CLP1611 telnet.Enqueue(new Telnet.Command(Telnet.CmdAction.CONNECT, ipAddress.ToString(), 10, 30)); + running = true; + log.FatalFormat("Successfully initialized device {0}", ToString()); } @@ -104,6 +117,8 @@ namespace TBF.BenchControl.Network.Camera.CLP1611 telnet.Dispose(); telnet = null; } + + running = false; } public void RunDeviceBefore() {} diff --git a/TestBenchFramework/BenchControl/StateMachine.cs b/TestBenchFramework/BenchControl/StateMachine.cs index f27c2bcc0..c51fce76b 100644 --- a/TestBenchFramework/BenchControl/StateMachine.cs +++ b/TestBenchFramework/BenchControl/StateMachine.cs @@ -279,8 +279,8 @@ namespace TBF.BenchControl if (cmpnt is IDevice) { - AddDevice(cmpnt as IDevice); (cmpnt as IDevice).Initialize(); + AddDevice(cmpnt as IDevice); /// Only components that were initialized are added } } @@ -303,6 +303,17 @@ namespace TBF.BenchControl return null; } + /// + /// Stop devices that were started by InitializeDevices(). + /// Works correctly also after exeption from InitializeDevices() as only ... + /// ... correctly started devices were added in 'devices' list. + /// + public static void StopDevices() + { + foreach (var dev in devices) dev.StopDevice(); + } + + /// /// Start the state machine /// diff --git a/TestBenchFramework/MainWnd.cs b/TestBenchFramework/MainWnd.cs index 5c37d29f5..7b88fce4a 100644 --- a/TestBenchFramework/MainWnd.cs +++ b/TestBenchFramework/MainWnd.cs @@ -478,6 +478,7 @@ namespace TBF MessageBoxIcon.Question)) { BenchControl.StateMachine.Stop(); + BenchControl.StateMachine.StopDevices(); UiBridge.Bridge.OnEmergencyStopChanged(this, UiBridge.EmergencyStopEventArgs.State.CloseForm); new Forms.ClosingProgram().ShowDialog(); DialogResult = DialogResult.OK;