Пример #1
0
        /// <summary>
        /// Create SR state controller and initialize the SR
        /// </summary>
        /// <param name="meas"></param>
        /// <returns>SR codes, e.g. SR_SUCCESS/SR_INVPORT/SR_IOERR/SR_TIMEOUT/ZERO_COUNT_TIME</returns>
        public int InitializeSR(CancellationTokenSource controllingThreadCTS)
        {
            // dev note: add-a-source <snip>
            if (sr == null)
            {
                sr = new SR(detector.SRParams, detector.Id, meas.AcquireState, meas.Tests, log);
                sr.LinkedCancelSource = NC.App.Opstate.CancelStopAbort.NewLinkedCancelStopAbortAndClientTokenSources(controllingThreadCTS.Token);
                if (runtime == -1.0) // not set for HVP so use the expected values
                {
                    runtime = meas.AcquireState.run_count_time;
                    hvsetpt = detector.SRParams.highVoltage;
                }
            }

            /* open, set parameters and initialize shift register */
            int init_status = sr.sr_init(runtime, hvsetpt);

            if (init_status != sr_h.SR_SUCCESS)
            {
                //LastSRStatus= sr.sr_stop();  // init retries to stop twice
                LastMeasStatus = SR.SR_FAIL;
            }
            else
            {
                LastMeasStatus = SR.SUCCESS;
            }
            LastSRStatus = init_status;
            return(init_status);
        }
Пример #2
0
        // need to call this AFTER the instruments are identified from the sys config
        internal void ConnectSRInstruments()
        {
            // start the control thread for each SR and and make sure it is waiting for a command
            IEnumerator iter = Instruments.Active.GetSREnumerator();

            while (iter.MoveNext())
            {
                SRInstrument sri = (SRInstrument)iter.Current;
                sri.SRCtrl = SRWrangler.StartSRControl(sri, pceh: (sender, args) =>  // the report progress eh
                {
                    SRControl srctrl = args.UserState as SRControl;
                    if (srctrl.IsInitialized)
                    {
                        SRWrangler.Logger.TraceEvent(LogLevels.Verbose, 383, "{0}, SRControl {1}: SR status '{2}', SR Control Status '{3}' ({4})",
                                                     args.ProgressPercentage, srctrl.Identifier,
                                                     INCCSR.SRAPIReturnStatusCode(srctrl.LastSRStatus), INCCSR.SRAPIReturnStatusCode(srctrl.LastMeasStatus), srctrl.fraction);
                    }
                    else
                    {
                        SRWrangler.Logger.TraceEvent(LogLevels.Verbose, 384, "{0}, SRControl {1}", args.ProgressPercentage, srctrl.Identifier);
                    }
                },
                                                       // the operation complete eh
                                                       opeh: SREventHandler
                                                       );
            }

            iter = Instruments.Active.GetSREnumerator();
            // associate each new SR thread with the current measurement
            while (iter.MoveNext())
            {
                SRInstrument sri = (SRInstrument)iter.Current;
                SRWrangler.StartSRActionAndWait(sri.id, SRTakeDataHandler.SROp.InitializeContext);
            }

            // devnote: the attempt to connect occurs in StartLMCAssay
        }
Пример #3
0
        // register this using StartSRControl
        public static void SREventHandler(object sender, SRTakeDataHandler.SROpCompletedEventArgs e)
        {
            SRControl sr = (SRControl)e.UserState;

            // SRTakeDataHandler.SROp next = SRTakeDataHandler.NextOp(e.Op, e.OpStatus);
            sr.Log.TraceEvent(LogLevels.Verbose, 87266, "SR {0} operation {1} completed '{2}'",
                              sr.Identifier, e.Op, INCCSR.SRAPIReturnStatusCode(e.OpStatus));
            try
            {
                switch (e.Op)
                {
                case SRTakeDataHandler.SROp.Shutdown:

                    break;

                case SRTakeDataHandler.SROp.Nothing:

                    break;

                case SRTakeDataHandler.SROp.InitializeContext:

                    break;

                case SRTakeDataHandler.SROp.InitializeSR:
                case SRTakeDataHandler.SROp.ReInitializeSR:
                    if (!(e.OpStatus == INCCSR.SUCCESS || e.OpStatus == INCCSR.MEAS_CONTINUE))
                    {
                        StopThisSRAssayImmediately((SRTakeDataHandler.SRControlThread)sender);
                        //Action<object> action = (object obj) =>
                        //{
                        //    StopThisSRAssayImmediately((SRTakeDataHandler.SRControlThread)obj);
                        //};
                        //Task signifyingnothing = Task.Factory.StartNew(action, sender);
                    }
                    break;

                case SRTakeDataHandler.SROp.StartSRDAQ:
                    if (!(e.OpStatus == INCCSR.SUCCESS || e.OpStatus == INCCSR.MEAS_CONTINUE))
                    {
                        StopThisSRAssayImmediately((SRTakeDataHandler.SRControlThread)sender);
                        //Action<object> action = (object obj) =>
                        //{
                        //    StopThisSRAssayImmediately((SRTakeDataHandler.SRControlThread)obj);
                        //};
                        //Task signifyingnothing = Task.Factory.StartNew(action, sender);
                    }
                    break;

                case SRTakeDataHandler.SROp.WaitForResults:
                    if (!(e.OpStatus == INCCSR.SUCCESS || e.OpStatus == INCCSR.MEAS_CONTINUE))
                    {
                        StopThisSRAssayImmediately((SRTakeDataHandler.SRControlThread)sender);
                        //Action<object> action = (object obj) =>
                        //{
                        //    StopThisSRAssayImmediately((SRTakeDataHandler.SRControlThread)obj);
                        //};
                        //Task signifyingnothing = Task.Factory.StartNew(action, sender);
                    }
                    else
                    {
                        SRTakeDataHandler.SRControlThread srct = (SRTakeDataHandler.SRControlThread)sender;
                        sr.Log.TraceEvent(LogLevels.Verbose, 87225, "Transform the results, or get the transformed results");
                        srct.sri.PendingComplete();                            // when we get here, the raw results are already available on the SR thread structure
                        if (srct.sri.DAQState == DAQInstrState.HVCalib)
                        {
                        }
                        else
                        {
                            srct.SRCtrl.TransformResults(srct.SRCtrl.Det.Id, srct.sri.RDT.Cycle);     // convert to enhanced results
                        }
                        HandleEndOfCycleProcessing(srct.sri);
                    }
                    break;

                case SRTakeDataHandler.SROp.CloseSR:
                    break;
                }
            }
            catch (AnalysisDefs.CancellationRequestedException)  // thrown from this method
            {
                StopActiveAssayImmediately();
            }
            catch (Exception oddex)
            {
                sr.Log.TraceEvent(LogLevels.Error, 643, "Internal error, stopping active processing, {0}", oddex.Message);
                if (sender != null)
                {
                    SRTakeDataHandler.SRControlThread srct = (SRTakeDataHandler.SRControlThread)sender;
                    HandleFatalGeneralError(srct.sri, oddex);
                }
                else
                {
                    // will blow if not really an Assay subclass, e.g. not running in the context of the full DAQCOntrol class
                    CurState.State = DAQInstrState.Offline;         // remaining buffers should now bypass DAQ section
                    gControl.StopLMCAssay(removeCurNCDFile: false); // stop the instruments
                    gControl.netlog.TraceException(oddex, false);
                    gControl.netlog.TraceEvent(LogLevels.Info, 429, "DAQ processing incomplete: {0}, processing stopped", oddex.Message);
                    //activeInstr.RDT.EndOfCycleProcessing(CurState.Measurement);
                    gControl.MajorOperationCompleted();  // signal the controlling loop we are done
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Create SR state controller and initialize the SR
        /// </summary>
        /// <param name="meas"></param>
        /// <returns>SR codes, e.g. SR_SUCCESS/SR_INVPORT/SR_IOERR/SR_TIMEOUT/ZERO_COUNT_TIME</returns>
        public int InitializeSR(CancellationTokenSource controllingThreadCTS)
        {
            // dev note: add-a-source <snip>
            if (sr == null)
            {
                sr = new SR(detector.SRParams, detector.Id, meas.AcquireState, meas.Tests, log);
                sr.LinkedCancelSource = NC.App.Opstate.CancelStopAbort.NewLinkedCancelStopAbortAndClientTokenSources(controllingThreadCTS.Token);
                if (runtime == -1.0) // not set for HVP so use the expected values
                {
                    runtime = meas.AcquireState.run_count_time;
                    hvsetpt = detector.SRParams.highVoltage;
                }
            }

            /* open, set parameters and initialize shift register */
            int init_status = sr.sr_init(runtime, hvsetpt);
            if (init_status != sr_h.SR_SUCCESS)
            {
                //LastSRStatus= sr.sr_stop();  // init retries to stop twice
                LastMeasStatus = SR.SR_FAIL;
            }
            else
                LastMeasStatus = SR.SUCCESS;
            LastSRStatus = init_status;
            return init_status;
        }