示例#1
0
文件: Control.cs 项目: radtek/INCC6
        // 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;
                bool         found = false;
                try                                                    // Fix case where crashes because COM port doesn't exist any more..... hn 5.15.2015
                {
                    if (sri.id.SRType.IsCOMPortBasedSR())              // always true if code gets you here
                    {
                        if (!CheckCOMPortExistence(sri.id.SerialPort)) // if not found then emit error
                        {
                            collog.TraceInformation("The COM port {0} is no longer available. Instrument {1} cannot be connected. Please set a valid COM port.", sri.id.SerialPort.ToString(), sri.id.DetectorId);
                            string[] ports = System.IO.Ports.SerialPort.GetPortNames();                             // "COMnnn"
                            string   ps    = string.Empty;
                            if (ports.Length == 0)
                            {
                                ps = "No COM ports found";
                            }
                            else
                            {
                                ps = "These COM ports are available:";
                                foreach (string p in ports)
                                {
                                    ps += (" " + p + ",");
                                }
                            }
                            collog.TraceInformation(ps);
                            sri.selected = false;
                        }
                        else
                        {
                            found = true;
                        }
                    }
                } catch (Exception ex)
                {
                    collog.TraceException(ex);
                }
                if (!found)
                {
                    Instruments.Active.RemoveAll(i => i.selected == false);
                    return;
                }

                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
        }
示例#2
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(removeCurLMDataFile: false); // stop the instruments
                    gControl.collog.TraceException(oddex, false);
                    gControl.collog.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
                }
            }
        }