/// /// Copyright (c) 2019 Sensus Slovensko a.s. /// using System; using System.Drawing; using log4net; using TBF.Boxes; using TBF.Resources; namespace TBF.Rig.Modbus.QuidoRS { public class ShowBenchWaitingOp : IOperation { private static readonly ILog log = LogManager.GetLogger(typeof(ShowBenchWaitingOp)); public override string ToString() { return string.Format("ShowBenchWaitingOp(.)"); } const ushort BenchReadyValue = 0x01; const ushort BenchWaitingValue = 0x06; const ushort BenchConfirmedValue = 0x02; /// Set by the constructor readonly QuidoRS quidoRS; bool confirmed = false; /// ConfirmationForm confirmationForm; /// delegate void MessageBoxFormDlgt(ShowBenchWaitingOp myRef); /// void OpenFormDlg(ShowBenchWaitingOp myRef) { myRef.confirmationForm = new ConfirmationForm(Strings.Mute_alarm, Color.Yellow); confirmationForm.Show(); } /// /// Events: Event.None /// /// Pressure meter reference public ShowBenchWaitingOp(QuidoRS quidoRS) { if (quidoRS == null) throw new ArgumentNullException("quidoRS"); this.quidoRS = quidoRS; log.Debug(this.ToString()); } /// Start this operation public void Start() { log.WarnFormat("ShowBenchWaitingOp.Start()"); quidoRS.SetOutputs(BenchWaitingValue); confirmed = false; Program.MainWnd.Invoke(new MessageBoxFormDlgt(OpenFormDlg), this); } /// Run this operation public Event Run() { if (confirmed || confirmationForm.Completed) { log.WarnFormat("ShowBenchWaitingOp.Run() --> Confirmed"); quidoRS.SetOutputs(BenchConfirmedValue); confirmed = true; confirmationForm = null; } return Event.None; } /// Stop this operation public void Stop() { log.WarnFormat("ShowBenchWaitingOp.Stop()"); quidoRS.SetOutputs(BenchReadyValue); if (confirmationForm != null) { confirmationForm.OnCloseThisForm(this, null); confirmationForm = null; } } } }