DetectorControlPanel.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. namespace OINA.Extender.Testharness
  2. {
  3. using System;
  4. using System.Globalization;
  5. using System.Windows.Forms;
  6. using OINA.Extender.DetectorControl;
  7. /// <summary>
  8. /// Detector Control Panel Form
  9. /// </summary>
  10. public partial class DetectorControlPanel : Form
  11. {
  12. /// <summary>
  13. /// IEdDetectorControl object
  14. /// </summary>
  15. private IEdDetectorControl currentDetector = null;
  16. /// <summary>
  17. /// Detector Control Panel constructor
  18. /// </summary>
  19. /// <param name="currentDetector">current detector</param>
  20. public DetectorControlPanel(IEdDetectorControl currentDetector)
  21. {
  22. this.InitializeComponent();
  23. if (currentDetector != null)
  24. {
  25. this.currentDetector = currentDetector;
  26. // Hook up detector controller status events
  27. this.currentDetector.SlideControl.StatusChanged += this.OnDetectorSlideStatusChanged;
  28. this.currentDetector.ThermalControl.StatusChanged += this.OnDetectorOperatingStatusChanged;
  29. this.currentDetector.ShutterControl.StatusChanged += this.OnDetectorShutterStatusChanged;
  30. this.currentDetector.OverloadControl.StatusChanged += this.OnDetectorOverloadStatusChanged;
  31. // Initial UI contents
  32. this.UpdateDetectorStatusText();
  33. this.UpdateSlideStatusText();
  34. this.UpdateThermalStatusText();
  35. this.UpdateShutterStatusText();
  36. this.UpdateOverloadStatusText();
  37. this.tbDelay.Text = this.currentDetector.OverloadControl.Status.OverloadDelay.ToString(@"F2", CultureInfo.InvariantCulture);
  38. this.tbThreshold.Text = this.currentDetector.OverloadControl.Status.OverloadThreshold.ToString(@"F2", CultureInfo.InvariantCulture);
  39. }
  40. }
  41. #region Event handlers
  42. /// <summary>
  43. /// OnDetectorOverloadStatusChanged
  44. /// </summary>
  45. /// <param name="sender">sender object</param>
  46. /// <param name="e">EventArgs</param>
  47. private void OnDetectorOverloadStatusChanged(object sender, EventArgs e)
  48. {
  49. this.BeginInvoke((Action)this.UpdateOverloadStatusText);
  50. }
  51. /// <summary>
  52. /// OnDetectorShutterStatusChanged
  53. /// </summary>
  54. /// <param name="sender">sender object</param>
  55. /// <param name="e">EventArgs</param>
  56. private void OnDetectorShutterStatusChanged(object sender, EventArgs e)
  57. {
  58. this.BeginInvoke((Action)this.UpdateShutterStatusText);
  59. }
  60. /// <summary>
  61. /// OnDetectorOperatingStatusChanged
  62. /// </summary>
  63. /// <param name="sender">sender object</param>
  64. /// <param name="e">EventArgs</param>
  65. private void OnDetectorOperatingStatusChanged(object sender, EventArgs e)
  66. {
  67. this.BeginInvoke((Action)this.UpdateThermalStatusText);
  68. }
  69. /// <summary>
  70. /// OnDetectorSlideStatusChanged
  71. /// </summary>
  72. /// <param name="sender">sender object</param>
  73. /// <param name="e">EventArgs</param>
  74. private void OnDetectorSlideStatusChanged(object sender, EventArgs e)
  75. {
  76. this.BeginInvoke((Action)this.UpdateSlideStatusText);
  77. }
  78. #endregion
  79. #region Get detector status and Update the UI
  80. /// <summary>
  81. /// UpdateDetectorStatusText Method
  82. /// Gets and updates the UI with the detector status information
  83. /// </summary>
  84. private void UpdateDetectorStatusText()
  85. {
  86. this.textDetectorIsReady.Text = this.currentDetector.DetectorStatus.IsDetectorReady.ToString(CultureInfo.InvariantCulture);
  87. this.tbDetectorDescription.Text = this.currentDetector.DetectorStatus.StatusDescription;
  88. }
  89. /// <summary>
  90. /// UpdatePositionText Method
  91. /// Gets and updates the UI with the detectors slide status.
  92. /// </summary>
  93. private void UpdateSlideStatusText()
  94. {
  95. switch (this.currentDetector.SlideControl.Status.PositionState)
  96. {
  97. case DetectorSlidePositionState.In:
  98. this.textPositionStatus.Text = @"Fully Inserted";
  99. break;
  100. case DetectorSlidePositionState.Out:
  101. this.textPositionStatus.Text = @"Fully Retracted";
  102. break;
  103. case DetectorSlidePositionState.Indeterminate:
  104. this.textPositionStatus.Text = @"Indeterminate Position";
  105. break;
  106. default:
  107. this.textPositionStatus.Text = @"Unknown";
  108. break;
  109. }
  110. switch (this.currentDetector.SlideControl.Status.Activity)
  111. {
  112. case DetectorSlideActivity.NotMoving:
  113. this.textActivityStatus.Text = @"Not Moving";
  114. break;
  115. case DetectorSlideActivity.MovingIn:
  116. this.textActivityStatus.Text = @"Moving In";
  117. break;
  118. case DetectorSlideActivity.MovingOut:
  119. this.textActivityStatus.Text = @"Moving Out";
  120. break;
  121. case DetectorSlideActivity.AutoRetracting:
  122. this.textActivityStatus.Text = @"Auto Retracting";
  123. break;
  124. default:
  125. this.textActivityStatus.Text = @"Unknown";
  126. break;
  127. }
  128. this.UpdateDetectorStatusText();
  129. }
  130. /// <summary>
  131. /// UpdateShutterStatusText Method
  132. /// Gets and updates the UI with the detectors shutter status.
  133. /// </summary>
  134. private void UpdateShutterStatusText()
  135. {
  136. if (this.currentDetector.ShutterControl.Status.Enabled)
  137. {
  138. switch (this.currentDetector.ShutterControl.Status.State)
  139. {
  140. case DetectorShutterState.Closed:
  141. this.textShutterStatus.Text = @"Closed";
  142. break;
  143. case DetectorShutterState.Open:
  144. this.textShutterStatus.Text = @"Open";
  145. break;
  146. case DetectorShutterState.Fault:
  147. this.textShutterStatus.Text = @"Fault";
  148. break;
  149. case DetectorShutterState.ClosedDueToOverload:
  150. this.textShutterStatus.Text = @"Closed due to overload";
  151. break;
  152. default:
  153. this.textShutterStatus.Text = @"Unknown";
  154. break;
  155. }
  156. }
  157. this.UpdateDetectorStatusText();
  158. }
  159. /// <summary>
  160. /// UpdateOverloadStatusText Method
  161. /// Gets and updates the UI with the detectors overload status.
  162. /// </summary>
  163. private void UpdateOverloadStatusText()
  164. {
  165. if (this.currentDetector.OverloadControl.Status.OverloadDetectionEnabled)
  166. {
  167. this.textOverloadProtection.Text = @"Enabled";
  168. }
  169. else
  170. {
  171. this.textOverloadProtection.Text = @"Disabled";
  172. }
  173. this.textDelay.Text = this.currentDetector.OverloadControl.Status.OverloadDelay.ToString(@"F2", CultureInfo.InvariantCulture);
  174. this.textThreshold.Text = this.currentDetector.OverloadControl.Status.OverloadThreshold.ToString(@"F2", CultureInfo.InvariantCulture);
  175. switch (this.currentDetector.OverloadControl.Status.LowMagInterlock)
  176. {
  177. case LowMagInterlock.Enabled:
  178. this.textInterlockStatus.Text = @"Enabled";
  179. break;
  180. case LowMagInterlock.Disabled:
  181. this.textInterlockStatus.Text = @"Disabled";
  182. break;
  183. case LowMagInterlock.Unknown:
  184. default:
  185. this.textInterlockStatus.Text = @"Unknown";
  186. break;
  187. }
  188. this.UpdateDetectorStatusText();
  189. }
  190. /// <summary>
  191. /// UpdateOperatingStatusText Method
  192. /// Gets and updates the UI with the detectors Thermal status.
  193. /// </summary>
  194. private void UpdateThermalStatusText()
  195. {
  196. this.textOperatingStatus.Text = this.currentDetector.ThermalControl.Status.OperatingState.ToString();
  197. this.UpdateDetectorStatusText();
  198. }
  199. #endregion
  200. #region Control Detector from UI
  201. /// <summary>
  202. /// Move in button click handler
  203. /// If the detectors slide control can be driven in,
  204. /// then this commands the slide controller for the detector to move the slide in.
  205. /// </summary>
  206. /// <param name="sender">sender object</param>
  207. /// <param name="e">EventArgs</param>
  208. private void MoveInButton_Click(object sender, EventArgs e)
  209. {
  210. if (this.currentDetector.SlideControl.CanDriveIn())
  211. {
  212. this.currentDetector.SlideControl.DriveIn();
  213. }
  214. }
  215. /// <summary>
  216. /// Move out button click handler
  217. /// If the detectors slide control can be driven out,
  218. /// then this commands the slide controller for the detector to move the slide out.
  219. /// </summary>
  220. /// <param name="sender">sender object</param>
  221. /// <param name="e">EventArgs</param>
  222. private void MoveOutButton_Click(object sender, EventArgs e)
  223. {
  224. if (this.currentDetector.SlideControl.CanDriveOut())
  225. {
  226. this.currentDetector.SlideControl.DriveOut();
  227. }
  228. }
  229. /// <summary>
  230. /// Stop button click handler
  231. /// If the detectors slide control can be stopped,
  232. /// then this commands the slide controller for the detector to stop moving.
  233. /// </summary>
  234. /// <param name="sender">sender object</param>
  235. /// <param name="e">EventArgs</param>
  236. private void StopButton_Click(object sender, EventArgs e)
  237. {
  238. if (this.currentDetector.SlideControl.CanStop())
  239. {
  240. this.currentDetector.SlideControl.Stop();
  241. }
  242. }
  243. /// <summary>
  244. /// Opearte button click handler
  245. /// If the detectors thermal control can be under automatic control,
  246. /// then this commands it to enter automatic mode.
  247. /// </summary>
  248. /// <param name="sender">sender object</param>
  249. /// <param name="e">EventArgs</param>
  250. private void OperateButton_Click(object sender, EventArgs e)
  251. {
  252. if (this.currentDetector.ThermalControl.CanEnterAutomaticMode())
  253. {
  254. this.currentDetector.ThermalControl.EnterAutomaticMode();
  255. }
  256. }
  257. /// <summary>
  258. /// Standby button click handler
  259. /// If the detectors thermal control can be placed into standby mode,
  260. /// then this commands it to enter standby mode.
  261. /// </summary>
  262. /// <param name="sender">sender object</param>
  263. /// <param name="e">EventArgs</param>
  264. private void StandbyButton_Click(object sender, EventArgs e)
  265. {
  266. if (this.currentDetector.ThermalControl.CanEnterStandbyMode())
  267. {
  268. this.currentDetector.ThermalControl.EnterStandbyMode();
  269. }
  270. }
  271. /// <summary>
  272. /// Open button click handler
  273. /// If the detectors shutter control can be opened, this commands it to open.
  274. /// </summary>
  275. /// <param name="sender">sender object</param>
  276. /// <param name="e">EventArgs</param>
  277. private void OpenButton_Click(object sender, EventArgs e)
  278. {
  279. if (this.currentDetector.ShutterControl.CanOpenShutter())
  280. {
  281. this.currentDetector.ShutterControl.OpenShutter();
  282. }
  283. }
  284. /// <summary>
  285. /// Close button click handler
  286. /// If the detectors shutter control can be closed, this commands it to close.
  287. /// </summary>
  288. /// <param name="sender">sender object</param>
  289. /// <param name="e">EventArgs</param>
  290. private void CloseButton_Click(object sender, EventArgs e)
  291. {
  292. if (this.currentDetector.ShutterControl.CanCloseShutter())
  293. {
  294. this.currentDetector.ShutterControl.CloseShutter();
  295. }
  296. }
  297. /// <summary>
  298. /// SetOverloadValue button click handler
  299. /// This sets the overload delay and threshold for a detector's overload control
  300. /// to the values specified in the UI if we are allowed.
  301. /// </summary>
  302. /// <param name="sender">sender object</param>
  303. /// <param name="e">EventArgs</param>
  304. private void SetOverloadValueButton_Click(object sender, EventArgs e)
  305. {
  306. float delay = float.Parse(this.tbDelay.Text, CultureInfo.InvariantCulture);
  307. float threshold = float.Parse(this.tbThreshold.Text, CultureInfo.InvariantCulture);
  308. if (this.currentDetector.OverloadControl.CanSetOverloadDelay(delay))
  309. {
  310. this.currentDetector.OverloadControl.SetOverloadDelay(delay);
  311. }
  312. if (this.currentDetector.OverloadControl.CanSetOverloadThreshold(threshold))
  313. {
  314. this.currentDetector.OverloadControl.SetOverloadThreshold(threshold);
  315. }
  316. this.UpdateOverloadStatusText();
  317. }
  318. /// <summary>
  319. /// ToggleOverloadProtection button click handler
  320. /// Toggles the detectors overload detection if allowed.
  321. /// </summary>
  322. /// <param name="sender">sender object</param>
  323. /// <param name="e">EventArgs</param>
  324. private void ToggleOverloadProtectionButton_Click(object sender, EventArgs e)
  325. {
  326. if (this.currentDetector.OverloadControl.CanToggleOverloadDetection())
  327. {
  328. if (!this.currentDetector.OverloadControl.Status.OverloadDetectionEnabled)
  329. {
  330. this.currentDetector.OverloadControl.ToggleOverloadDetection(true);
  331. }
  332. else
  333. {
  334. this.currentDetector.OverloadControl.ToggleOverloadDetection(false);
  335. }
  336. }
  337. this.UpdateOverloadStatusText();
  338. }
  339. /// <summary>
  340. /// Raises the <see cref="E:System.Windows.Forms.Form.Closing" /> event.
  341. /// </summary>
  342. /// <param name="e">A <see cref="T:System.ComponentModel.CancelEventArgs" /> that contains the event data.</param>
  343. protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
  344. {
  345. IEdDetectorControl detector = this.currentDetector;
  346. if (detector != null)
  347. {
  348. // un-hook detector controller status events
  349. detector.SlideControl.StatusChanged -= this.OnDetectorSlideStatusChanged;
  350. detector.ThermalControl.StatusChanged -= this.OnDetectorOperatingStatusChanged;
  351. detector.ShutterControl.StatusChanged -= this.OnDetectorShutterStatusChanged;
  352. detector.OverloadControl.StatusChanged -= this.OnDetectorOverloadStatusChanged;
  353. }
  354. base.OnClosing(e);
  355. }
  356. #endregion
  357. }
  358. }