123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- namespace OINA.Extender.Testharness
- {
- using System;
- using System.Globalization;
- using System.Windows.Forms;
- using OINA.Extender.DetectorControl;
- /// <summary>
- /// Detector Control Panel Form
- /// </summary>
- public partial class DetectorControlPanel : Form
- {
- /// <summary>
- /// IEdDetectorControl object
- /// </summary>
- private IEdDetectorControl currentDetector = null;
- /// <summary>
- /// Detector Control Panel constructor
- /// </summary>
- /// <param name="currentDetector">current detector</param>
- public DetectorControlPanel(IEdDetectorControl currentDetector)
- {
- this.InitializeComponent();
- if (currentDetector != null)
- {
- this.currentDetector = currentDetector;
- // Hook up detector controller status events
- this.currentDetector.SlideControl.StatusChanged += this.OnDetectorSlideStatusChanged;
- this.currentDetector.ThermalControl.StatusChanged += this.OnDetectorOperatingStatusChanged;
- this.currentDetector.ShutterControl.StatusChanged += this.OnDetectorShutterStatusChanged;
- this.currentDetector.OverloadControl.StatusChanged += this.OnDetectorOverloadStatusChanged;
- // Initial UI contents
- this.UpdateDetectorStatusText();
- this.UpdateSlideStatusText();
- this.UpdateThermalStatusText();
- this.UpdateShutterStatusText();
- this.UpdateOverloadStatusText();
- this.tbDelay.Text = this.currentDetector.OverloadControl.Status.OverloadDelay.ToString(@"F2", CultureInfo.InvariantCulture);
- this.tbThreshold.Text = this.currentDetector.OverloadControl.Status.OverloadThreshold.ToString(@"F2", CultureInfo.InvariantCulture);
- }
- }
- #region Event handlers
- /// <summary>
- /// OnDetectorOverloadStatusChanged
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void OnDetectorOverloadStatusChanged(object sender, EventArgs e)
- {
- this.BeginInvoke((Action)this.UpdateOverloadStatusText);
- }
- /// <summary>
- /// OnDetectorShutterStatusChanged
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void OnDetectorShutterStatusChanged(object sender, EventArgs e)
- {
- this.BeginInvoke((Action)this.UpdateShutterStatusText);
- }
- /// <summary>
- /// OnDetectorOperatingStatusChanged
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void OnDetectorOperatingStatusChanged(object sender, EventArgs e)
- {
- this.BeginInvoke((Action)this.UpdateThermalStatusText);
- }
- /// <summary>
- /// OnDetectorSlideStatusChanged
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void OnDetectorSlideStatusChanged(object sender, EventArgs e)
- {
- this.BeginInvoke((Action)this.UpdateSlideStatusText);
- }
- #endregion
- #region Get detector status and Update the UI
- /// <summary>
- /// UpdateDetectorStatusText Method
- /// Gets and updates the UI with the detector status information
- /// </summary>
- private void UpdateDetectorStatusText()
- {
- this.textDetectorIsReady.Text = this.currentDetector.DetectorStatus.IsDetectorReady.ToString(CultureInfo.InvariantCulture);
- this.tbDetectorDescription.Text = this.currentDetector.DetectorStatus.StatusDescription;
- }
- /// <summary>
- /// UpdatePositionText Method
- /// Gets and updates the UI with the detectors slide status.
- /// </summary>
- private void UpdateSlideStatusText()
- {
- switch (this.currentDetector.SlideControl.Status.PositionState)
- {
- case DetectorSlidePositionState.In:
- this.textPositionStatus.Text = @"Fully Inserted";
- break;
- case DetectorSlidePositionState.Out:
- this.textPositionStatus.Text = @"Fully Retracted";
- break;
- case DetectorSlidePositionState.Indeterminate:
- this.textPositionStatus.Text = @"Indeterminate Position";
- break;
- default:
- this.textPositionStatus.Text = @"Unknown";
- break;
- }
- switch (this.currentDetector.SlideControl.Status.Activity)
- {
- case DetectorSlideActivity.NotMoving:
- this.textActivityStatus.Text = @"Not Moving";
- break;
- case DetectorSlideActivity.MovingIn:
- this.textActivityStatus.Text = @"Moving In";
- break;
- case DetectorSlideActivity.MovingOut:
- this.textActivityStatus.Text = @"Moving Out";
- break;
- case DetectorSlideActivity.AutoRetracting:
- this.textActivityStatus.Text = @"Auto Retracting";
- break;
- default:
- this.textActivityStatus.Text = @"Unknown";
- break;
- }
- this.UpdateDetectorStatusText();
- }
- /// <summary>
- /// UpdateShutterStatusText Method
- /// Gets and updates the UI with the detectors shutter status.
- /// </summary>
- private void UpdateShutterStatusText()
- {
- if (this.currentDetector.ShutterControl.Status.Enabled)
- {
- switch (this.currentDetector.ShutterControl.Status.State)
- {
- case DetectorShutterState.Closed:
- this.textShutterStatus.Text = @"Closed";
- break;
- case DetectorShutterState.Open:
- this.textShutterStatus.Text = @"Open";
- break;
- case DetectorShutterState.Fault:
- this.textShutterStatus.Text = @"Fault";
- break;
- case DetectorShutterState.ClosedDueToOverload:
- this.textShutterStatus.Text = @"Closed due to overload";
- break;
- default:
- this.textShutterStatus.Text = @"Unknown";
- break;
- }
- }
- this.UpdateDetectorStatusText();
- }
- /// <summary>
- /// UpdateOverloadStatusText Method
- /// Gets and updates the UI with the detectors overload status.
- /// </summary>
- private void UpdateOverloadStatusText()
- {
- if (this.currentDetector.OverloadControl.Status.OverloadDetectionEnabled)
- {
- this.textOverloadProtection.Text = @"Enabled";
- }
- else
- {
- this.textOverloadProtection.Text = @"Disabled";
- }
- this.textDelay.Text = this.currentDetector.OverloadControl.Status.OverloadDelay.ToString(@"F2", CultureInfo.InvariantCulture);
- this.textThreshold.Text = this.currentDetector.OverloadControl.Status.OverloadThreshold.ToString(@"F2", CultureInfo.InvariantCulture);
- switch (this.currentDetector.OverloadControl.Status.LowMagInterlock)
- {
- case LowMagInterlock.Enabled:
- this.textInterlockStatus.Text = @"Enabled";
- break;
- case LowMagInterlock.Disabled:
- this.textInterlockStatus.Text = @"Disabled";
- break;
- case LowMagInterlock.Unknown:
- default:
- this.textInterlockStatus.Text = @"Unknown";
- break;
- }
- this.UpdateDetectorStatusText();
- }
- /// <summary>
- /// UpdateOperatingStatusText Method
- /// Gets and updates the UI with the detectors Thermal status.
- /// </summary>
- private void UpdateThermalStatusText()
- {
- this.textOperatingStatus.Text = this.currentDetector.ThermalControl.Status.OperatingState.ToString();
- this.UpdateDetectorStatusText();
- }
- #endregion
- #region Control Detector from UI
- /// <summary>
- /// Move in button click handler
- /// If the detectors slide control can be driven in,
- /// then this commands the slide controller for the detector to move the slide in.
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void MoveInButton_Click(object sender, EventArgs e)
- {
- if (this.currentDetector.SlideControl.CanDriveIn())
- {
- this.currentDetector.SlideControl.DriveIn();
- }
- }
- /// <summary>
- /// Move out button click handler
- /// If the detectors slide control can be driven out,
- /// then this commands the slide controller for the detector to move the slide out.
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void MoveOutButton_Click(object sender, EventArgs e)
- {
- if (this.currentDetector.SlideControl.CanDriveOut())
- {
- this.currentDetector.SlideControl.DriveOut();
- }
- }
- /// <summary>
- /// Stop button click handler
- /// If the detectors slide control can be stopped,
- /// then this commands the slide controller for the detector to stop moving.
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void StopButton_Click(object sender, EventArgs e)
- {
- if (this.currentDetector.SlideControl.CanStop())
- {
- this.currentDetector.SlideControl.Stop();
- }
- }
- /// <summary>
- /// Opearte button click handler
- /// If the detectors thermal control can be under automatic control,
- /// then this commands it to enter automatic mode.
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void OperateButton_Click(object sender, EventArgs e)
- {
- if (this.currentDetector.ThermalControl.CanEnterAutomaticMode())
- {
- this.currentDetector.ThermalControl.EnterAutomaticMode();
- }
- }
- /// <summary>
- /// Standby button click handler
- /// If the detectors thermal control can be placed into standby mode,
- /// then this commands it to enter standby mode.
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void StandbyButton_Click(object sender, EventArgs e)
- {
- if (this.currentDetector.ThermalControl.CanEnterStandbyMode())
- {
- this.currentDetector.ThermalControl.EnterStandbyMode();
- }
- }
- /// <summary>
- /// Open button click handler
- /// If the detectors shutter control can be opened, this commands it to open.
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void OpenButton_Click(object sender, EventArgs e)
- {
- if (this.currentDetector.ShutterControl.CanOpenShutter())
- {
- this.currentDetector.ShutterControl.OpenShutter();
- }
- }
- /// <summary>
- /// Close button click handler
- /// If the detectors shutter control can be closed, this commands it to close.
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void CloseButton_Click(object sender, EventArgs e)
- {
- if (this.currentDetector.ShutterControl.CanCloseShutter())
- {
- this.currentDetector.ShutterControl.CloseShutter();
- }
- }
- /// <summary>
- /// SetOverloadValue button click handler
- /// This sets the overload delay and threshold for a detector's overload control
- /// to the values specified in the UI if we are allowed.
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void SetOverloadValueButton_Click(object sender, EventArgs e)
- {
- float delay = float.Parse(this.tbDelay.Text, CultureInfo.InvariantCulture);
- float threshold = float.Parse(this.tbThreshold.Text, CultureInfo.InvariantCulture);
- if (this.currentDetector.OverloadControl.CanSetOverloadDelay(delay))
- {
- this.currentDetector.OverloadControl.SetOverloadDelay(delay);
- }
- if (this.currentDetector.OverloadControl.CanSetOverloadThreshold(threshold))
- {
- this.currentDetector.OverloadControl.SetOverloadThreshold(threshold);
- }
- this.UpdateOverloadStatusText();
- }
- /// <summary>
- /// ToggleOverloadProtection button click handler
- /// Toggles the detectors overload detection if allowed.
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void ToggleOverloadProtectionButton_Click(object sender, EventArgs e)
- {
- if (this.currentDetector.OverloadControl.CanToggleOverloadDetection())
- {
- if (!this.currentDetector.OverloadControl.Status.OverloadDetectionEnabled)
- {
- this.currentDetector.OverloadControl.ToggleOverloadDetection(true);
- }
- else
- {
- this.currentDetector.OverloadControl.ToggleOverloadDetection(false);
- }
- }
- this.UpdateOverloadStatusText();
- }
- /// <summary>
- /// Raises the <see cref="E:System.Windows.Forms.Form.Closing" /> event.
- /// </summary>
- /// <param name="e">A <see cref="T:System.ComponentModel.CancelEventArgs" /> that contains the event data.</param>
- protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
- {
- IEdDetectorControl detector = this.currentDetector;
- if (detector != null)
- {
- // un-hook detector controller status events
- detector.SlideControl.StatusChanged -= this.OnDetectorSlideStatusChanged;
- detector.ThermalControl.StatusChanged -= this.OnDetectorOperatingStatusChanged;
- detector.ShutterControl.StatusChanged -= this.OnDetectorShutterStatusChanged;
- detector.OverloadControl.StatusChanged -= this.OnDetectorOverloadStatusChanged;
- }
- base.OnClosing(e);
- }
- #endregion
- }
- }
|