/// <summary> /// Load LM config state and create DAQ and FileCtrl controller instances /// </summary> public void Initialize(Object mainWindowForm) { if (LoadConfiguration()) { InitializeFileController(); InitializeDAQController(); measStatus = new LMProcessor.MeasurementStatus(); } }
static public string MeasStatusString(MeasurementStatus ms) { return ms.ToString(); }
static public string MeasStatusString(Measurement m) { LMProcessor.MeasurementStatus ms = new LMProcessor.MeasurementStatus(); return MeasStatusString(ms); }
/// <summary> /// Set up timer callback and action event handlers for a DAQController instance, uses DAQBind subclass /// </summary> /// <returns></returns> public bool InitializeDAQController() { // DAQ daqbind = new DAQBind((MLMEmulation.IEmulatorDiversion)(new LMProcessor.NullEmulation())); LMLoggers.LognLM applog = NC.App.Logger(LMLoggers.AppSection.App); daqbind.SetEventHandler(ActionEvents.EventType.PreAction, (object o) => { string s = LMDAQ.DAQControl.LogAndSkimDAQProcessingStatus(ActionEvents.EventType.PreAction, applog, LogLevels.Verbose, o); daqbind.mProgressTracker.ReportProgress(0, s);//"..."); }); daqbind.SetEventHandler(ActionEvents.EventType.ActionPrep, (object o) => { string s = "Action Prep: "; //can also look at active instrument list here LogLevels.Verbose, s = s + LMDAQ.Instruments.Active.Count + " devices found, [" + NC.App.Opstate.SOH + "] " + DateTimeOffset.Now.ToString("MMM dd yyy HH:mm:ss.ff K"); applog.TraceEvent(LogLevels.Verbose, 0xABCE, "Action Prep: SOH " + o.ToString() + "'"); daqbind.mProgressTracker.ReportProgress(0, s);//"Prep"); }); daqbind.SetEventHandler(ActionEvents.EventType.ActionStart, (object o) => { enablecontrols(false); string s = LMDAQ.DAQControl.LogAndSkimDAQProcessingStatus(ActionEvents.EventType.ActionStart, applog, LogLevels.Verbose, o); daqbind.mProgressTracker.ReportProgress(1, s);//"Starting..."); }); daqbind.SetEventHandler(ActionEvents.EventType.ActionInProgress, (object o) => { measStatus = new LMProcessor.MeasurementStatus(); measStatus.UpdateWithMeasurement(); measStatus.UpdateWithInstruments(); updateGUIWithChannelRatesData = true; string s2 = LMDAQ.DAQControl.LogAndSkimDAQProcessingStatus(ActionEvents.EventType.ActionInProgress, applog, LogLevels.Verbose, o); int per = Math.Min(100, (int)Math.Round(100.0 * ((double)measStatus.CurrentRepetition / (double)measStatus.RequestedRepetitions))); daqbind.mProgressTracker.ReportProgress(per, // a % est of files String.Format("{0} of {1} ({2})", measStatus.CurrentRepetition, measStatus.RequestedRepetitions, s2)); // dev note: need a better focused description of the state }); daqbind.SetEventHandler(ActionEvents.EventType.ActionStop, (object o) => { string s = LMDAQ.DAQControl.LogAndSkimDAQProcessingStatus(ActionEvents.EventType.ActionStop, applog, LogLevels.Warning, o); daqbind.mProgressTracker.ReportProgress(100, s); }); daqbind.SetEventHandler(ActionEvents.EventType.ActionCancel, (object o) => { string s = LMDAQ.DAQControl.LogAndSkimDAQProcessingStatus(ActionEvents.EventType.ActionCancel, applog, LogLevels.Warning, o); daqbind.mProgressTracker.ReportProgress(100, s); }); daqbind.SetEventHandler(ActionEvents.EventType.ActionFinished, (object o) => { string s = ""; if (o != null && o is LMDAQ.DAQControl) { LMDAQ.DAQControl f = (LMDAQ.DAQControl)o; measStatus = new LMProcessor.MeasurementStatus(); // preps local state for refresh on channel and computed rates for now, follow up with all other state measStatus.UpdateWithMeasurement(); s = LMDAQ.DAQControl.MeasStatusString(measStatus); updateGUIWithChannelRatesData = true; UpdateGUIWithNewdata(); } else { s = "Finished: SOH " + NC.App.Opstate.SOH + " but no processing occurred " + LMDAQ.DAQControl.LogAndSkimDAQProcessingStatus(ActionEvents.EventType.ActionFinished, applog, LogLevels.Verbose, o); } NC.App.Opstate.SOH = NCC.OperatingState.Stopped; // in case we got here after a Cancel // general logger: to the console, and/or listbox and/or log file or DB applog.TraceEvent(LogLevels.Verbose, FileCtrl.logid[ActionEvents.EventType.ActionFinished], s); // specialized updater for UI or file daqbind.mProgressTracker.ReportProgress(100, s); enablecontrols(true); }); return true; }
/// <summary> /// Set up action event handlers for a FileCtrl instance, uses FCtrlBind subclass /// </summary> /// <returns></returns> public bool InitializeFileController() { fctrlbind = new FCtrlBind(); LMLoggers.LognLM applog = NC.App.Logger(LMLoggers.AppSection.App); fctrlbind.mProgressTracker.ProgressChanged += new ProgressChangedEventHandler(Progress); /* * The action event handlers. * * There are 7 event types, see ActionEvents.EventType. * * The code fires a registered event handler at appropriate processing stages based on the action event type. * Unregistered handlers are simply ignored. * E.g. The ActionStart event is fired when an action starts. An action is a specific user task such as 'assay' * over NCD files or an assay from live LMMM DAQ. * * In the examples shown here for NCD file processing, very little reporting actually occurs. * The parameter for each event hnadler is an object, and as yet undefined. * I would use delegates to force the appropriate parameter types here, unlike the timer callbacks above. * But I've not yet completed this design and implementation * * Implementing these to report complex status to the logger and the UI control is the next step. * * I do not know which approach will serve us better for a large system, but we do have both timer pull and system push approaches here, so I'll keep them for now. * */ /// set up the 7 magic event handlers /// here I have a base handler that does the same thing for every event (writes a string to the log), /// and I reuse that string by posting it to the progress handler fctrlbind.SetEventHandler(ActionEvents.EventType.PreAction, (object o) => { string s = FileCtrl.LogAndSkimFileProcessingStatus(ActionEvents.EventType.PreAction, applog, LogLevels.Verbose, o); fctrlbind.mProgressTracker.ReportProgress(0, s);// "..."); }); fctrlbind.SetEventHandler(ActionEvents.EventType.ActionPrep, (object o) => { string s = FileCtrl.LogAndSkimFileProcessingStatus(ActionEvents.EventType.ActionPrep, applog, LogLevels.Verbose, o); fctrlbind.mProgressTracker.ReportProgress(0, s);//"Prep"); }); fctrlbind.SetEventHandler(ActionEvents.EventType.ActionStart, (object o) => { enablecontrols(false); string s = FileCtrl.LogAndSkimFileProcessingStatus(ActionEvents.EventType.ActionStart, applog, LogLevels.Verbose, o); fctrlbind.mProgressTracker.ReportProgress(1, s);//"Starting..."); }); fctrlbind.SetEventHandler(ActionEvents.EventType.ActionInProgress, (object o) => { measStatus = new LMProcessor.MeasurementStatus(); measStatus.UpdateWithMeasurement(); measStatus.UpdateWithInstruments(); updateGUIWithChannelRatesData = true; string s2 = FileCtrl.LogAndSkimFileProcessingStatus(ActionEvents.EventType.ActionInProgress, applog, LogLevels.Verbose, o); int per = Math.Min(100, (int)Math.Round(100.0 * ((double)measStatus.CurrentRepetition / (double)measStatus.RequestedRepetitions))); fctrlbind.mProgressTracker.ReportProgress(per, // a % est of files String.Format("{0} of {1} {2}", measStatus.CurrentRepetition, measStatus.RequestedRepetitions, s2)); // n of m, and file name }); fctrlbind.SetEventHandler(ActionEvents.EventType.ActionStop, (object o) => { string s = FileCtrl.LogAndSkimFileProcessingStatus(ActionEvents.EventType.ActionStop, applog, LogLevels.Warning, o); fctrlbind.mProgressTracker.ReportProgress(100, s);//"Stopping..."); }); fctrlbind.SetEventHandler(ActionEvents.EventType.ActionCancel, (object o) => { string s = FileCtrl.LogAndSkimFileProcessingStatus(ActionEvents.EventType.ActionCancel, applog, LogLevels.Warning, o); fctrlbind.mProgressTracker.ReportProgress(100, s);//"Cancelling..."); }); fctrlbind.SetEventHandler(ActionEvents.EventType.ActionFinished, (object o) => { String s = ""; if (o != null && o is FileCtrl) { FileCtrl f = (FileCtrl)o; measStatus = new LMProcessor.MeasurementStatus(); // preps local state for refresh on channel and computed rates for now, follow up with all other state measStatus.UpdateWithMeasurement(); s = FileCtrl.MeasStatusString(measStatus); updateGUIWithChannelRatesData = true; UpdateGUIWithNewdata(); } NC.App.Opstate.SOH = NCC.OperatingState.Stopped; // in case we got here after a Cancel // general logger: to the console, and/or listbox and/or log file or DB applog.TraceEvent(LogLevels.Verbose, FileCtrl.logid[ActionEvents.EventType.ActionFinished], s); // specialized updater for UI or file fctrlbind.mProgressTracker.ReportProgress(100, "Completed"); enablecontrols(true); }); NC.App.Opstate.SOH = NCC.OperatingState.Void; return true; }
/// <summary> /// Set up timer callback and action event handlers for a DAQController instance, uses DAQBind subclass /// </summary> /// <returns></returns> public bool InitializeDAQController() { // DAQ daqbind = new DAQBind((MLMEmulation.IEmulatorDiversion)(new LMProcessor.NullEmulation())); LMLoggers.LognLM applog = NC.App.Logger(LMLoggers.AppSection.App); daqbind.SetEventHandler(ActionEvents.EventType.PreAction, (object o) => { string s = LMDAQ.DAQControl.LogAndSkimDAQProcessingStatus(ActionEvents.EventType.PreAction, applog, LogLevels.Verbose, o); daqbind.mProgressTracker.ReportProgress(0, s); //"..."); }); daqbind.SetEventHandler(ActionEvents.EventType.ActionPrep, (object o) => { string s = "Action Prep: "; //can also look at active instrument list here LogLevels.Verbose, s = s + LMDAQ.Instruments.Active.Count + " devices found, [" + NC.App.Opstate.SOH + "] " + DateTimeOffset.Now.ToString("MMM dd yyy HH:mm:ss.ff K"); applog.TraceEvent(LogLevels.Verbose, 0xABCE, "Action Prep: SOH " + o.ToString() + "'"); daqbind.mProgressTracker.ReportProgress(0, s); //"Prep"); }); daqbind.SetEventHandler(ActionEvents.EventType.ActionStart, (object o) => { enablecontrols(false); string s = LMDAQ.DAQControl.LogAndSkimDAQProcessingStatus(ActionEvents.EventType.ActionStart, applog, LogLevels.Verbose, o); daqbind.mProgressTracker.ReportProgress(1, s);//"Starting..."); }); daqbind.SetEventHandler(ActionEvents.EventType.ActionInProgress, (object o) => { measStatus = new LMProcessor.MeasurementStatus(); measStatus.UpdateWithMeasurement(); measStatus.UpdateWithInstruments(); updateGUIWithChannelRatesData = true; string s2 = LMDAQ.DAQControl.LogAndSkimDAQProcessingStatus(ActionEvents.EventType.ActionInProgress, applog, LogLevels.Verbose, o); int per = Math.Min(100, (int)Math.Round(100.0 * ((double)measStatus.CurrentRepetition / (double)measStatus.RequestedRepetitions))); daqbind.mProgressTracker.ReportProgress(per, // a % est of files String.Format("{0} of {1} ({2})", measStatus.CurrentRepetition, measStatus.RequestedRepetitions, s2)); // dev note: need a better focused description of the state }); daqbind.SetEventHandler(ActionEvents.EventType.ActionStop, (object o) => { string s = LMDAQ.DAQControl.LogAndSkimDAQProcessingStatus(ActionEvents.EventType.ActionStop, applog, LogLevels.Warning, o); daqbind.mProgressTracker.ReportProgress(100, s); }); daqbind.SetEventHandler(ActionEvents.EventType.ActionCancel, (object o) => { string s = LMDAQ.DAQControl.LogAndSkimDAQProcessingStatus(ActionEvents.EventType.ActionCancel, applog, LogLevels.Warning, o); daqbind.mProgressTracker.ReportProgress(100, s); }); daqbind.SetEventHandler(ActionEvents.EventType.ActionFinished, (object o) => { string s = ""; if (o != null && o is LMDAQ.DAQControl) { LMDAQ.DAQControl f = (LMDAQ.DAQControl)o; measStatus = new LMProcessor.MeasurementStatus(); // preps local state for refresh on channel and computed rates for now, follow up with all other state measStatus.UpdateWithMeasurement(); s = LMDAQ.DAQControl.MeasStatusString(measStatus); updateGUIWithChannelRatesData = true; UpdateGUIWithNewdata(); } else { s = "Finished: SOH " + NC.App.Opstate.SOH + " but no processing occurred " + LMDAQ.DAQControl.LogAndSkimDAQProcessingStatus(ActionEvents.EventType.ActionFinished, applog, LogLevels.Verbose, o); } NC.App.Opstate.SOH = NCC.OperatingState.Stopped; // in case we got here after a Cancel // general logger: to the console, and/or listbox and/or log file or DB applog.TraceEvent(LogLevels.Verbose, FileCtrl.logid[ActionEvents.EventType.ActionFinished], s); // specialized updater for UI or file daqbind.mProgressTracker.ReportProgress(100, s); enablecontrols(true); }); return(true); }
/// <summary> /// Set up action event handlers for a FileCtrl instance, uses FCtrlBind subclass /// </summary> /// <returns></returns> public bool InitializeFileController() { fctrlbind = new FCtrlBind(); LMLoggers.LognLM applog = NC.App.Logger(LMLoggers.AppSection.App); fctrlbind.mProgressTracker.ProgressChanged += new ProgressChangedEventHandler(Progress); /* * The action event handlers. * * There are 7 event types, see ActionEvents.EventType. * * The code fires a registered event handler at appropriate processing stages based on the action event type. * Unregistered handlers are simply ignored. * E.g. The ActionStart event is fired when an action starts. An action is a specific user task such as 'assay' * over NCD files or an assay from live LMMM DAQ. * * In the examples shown here for NCD file processing, very little reporting actually occurs. * The parameter for each event hnadler is an object, and as yet undefined. * I would use delegates to force the appropriate parameter types here, unlike the timer callbacks above. * But I've not yet completed this design and implementation * * Implementing these to report complex status to the logger and the UI control is the next step. * * I do not know which approach will serve us better for a large system, but we do have both timer pull and system push approaches here, so I'll keep them for now. * */ /// set up the 7 magic event handlers /// here I have a base handler that does the same thing for every event (writes a string to the log), /// and I reuse that string by posting it to the progress handler fctrlbind.SetEventHandler(ActionEvents.EventType.PreAction, (object o) => { string s = FileCtrl.LogAndSkimFileProcessingStatus(ActionEvents.EventType.PreAction, applog, LogLevels.Verbose, o); fctrlbind.mProgressTracker.ReportProgress(0, s);// "..."); }); fctrlbind.SetEventHandler(ActionEvents.EventType.ActionPrep, (object o) => { string s = FileCtrl.LogAndSkimFileProcessingStatus(ActionEvents.EventType.ActionPrep, applog, LogLevels.Verbose, o); fctrlbind.mProgressTracker.ReportProgress(0, s);//"Prep"); }); fctrlbind.SetEventHandler(ActionEvents.EventType.ActionStart, (object o) => { enablecontrols(false); string s = FileCtrl.LogAndSkimFileProcessingStatus(ActionEvents.EventType.ActionStart, applog, LogLevels.Verbose, o); fctrlbind.mProgressTracker.ReportProgress(1, s);//"Starting..."); }); fctrlbind.SetEventHandler(ActionEvents.EventType.ActionInProgress, (object o) => { measStatus = new LMProcessor.MeasurementStatus(); measStatus.UpdateWithMeasurement(); measStatus.UpdateWithInstruments(); updateGUIWithChannelRatesData = true; string s2 = FileCtrl.LogAndSkimFileProcessingStatus(ActionEvents.EventType.ActionInProgress, applog, LogLevels.Verbose, o); int per = Math.Min(100, (int)Math.Round(100.0 * ((double)measStatus.CurrentRepetition / (double)measStatus.RequestedRepetitions))); fctrlbind.mProgressTracker.ReportProgress(per, // a % est of files String.Format("{0} of {1} {2}", measStatus.CurrentRepetition, measStatus.RequestedRepetitions, s2)); // n of m, and file name }); fctrlbind.SetEventHandler(ActionEvents.EventType.ActionStop, (object o) => { string s = FileCtrl.LogAndSkimFileProcessingStatus(ActionEvents.EventType.ActionStop, applog, LogLevels.Warning, o); fctrlbind.mProgressTracker.ReportProgress(100, s);//"Stopping..."); }); fctrlbind.SetEventHandler(ActionEvents.EventType.ActionCancel, (object o) => { string s = FileCtrl.LogAndSkimFileProcessingStatus(ActionEvents.EventType.ActionCancel, applog, LogLevels.Warning, o); fctrlbind.mProgressTracker.ReportProgress(100, s);//"Cancelling..."); }); fctrlbind.SetEventHandler(ActionEvents.EventType.ActionFinished, (object o) => { String s = ""; if (o != null && o is FileCtrl) { FileCtrl f = (FileCtrl)o; measStatus = new LMProcessor.MeasurementStatus(); // preps local state for refresh on channel and computed rates for now, follow up with all other state measStatus.UpdateWithMeasurement(); s = FileCtrl.MeasStatusString(measStatus); updateGUIWithChannelRatesData = true; UpdateGUIWithNewdata(); } NC.App.Opstate.SOH = NCC.OperatingState.Stopped; // in case we got here after a Cancel // general logger: to the console, and/or listbox and/or log file or DB applog.TraceEvent(LogLevels.Verbose, FileCtrl.logid[ActionEvents.EventType.ActionFinished], s); // specialized updater for UI or file fctrlbind.mProgressTracker.ReportProgress(100, "Completed"); enablecontrols(true); }); NC.App.Opstate.SOH = NCC.OperatingState.Void; return(true); }