Пример #1
0
 protected void LogConfig()
 {
     string[] x = NCCConfig.Config.ShowCfgLines(NC.App.Config, NC.App.AppContext.Verbose() == System.Diagnostics.TraceEventType.Verbose, false);
     for (int i = 0; i < x.Length; i++)
     {
         applog.TraceInformation(x[i]);
     }
 }
Пример #2
0
        // this starts the first iteration of the assay loop,
        // subsequent iterations are driven by the SR thread termination, PTR-32 thread termination, or LMMM socket callback
        // at the end of each cycle
        protected bool StartAssay()
        {
            ResetForMeasurement(); // timer started in here
            bool some = (0 < StartLM_SRAssay());

            if (!some) // each active Active Instrument has its own wait handle, and it was set earlier, waiting point is in the caller
            {
                collog.TraceInformation("No active instruments found, finished");
            }
            return(some);
        }
Пример #3
0
 //
 // "Send" wrapper hiding socket and the looping over list of LMMMs
 //
 private void SendToLMMM(string cmd, Int32 specificLMIndex = -1)
 {
     if (!Instruments.Active.HasLMMM())
     {
         commlog.TraceEvent(LogLevels.Warning, 325, "No LMMM instruments available to receive '" + cmd + "'");
         return;
     }
     try
     {
         if (CurrentLM == -1 && specificLMIndex == -1)  // all of them
         {
             commlog.TraceInformation("Send " + LMLoggers.LognLM.FlattenChars(cmd) + LMMMLingo.eolprintrep + " to all the LMMM instruments on the subnet");
             IEnumerator iter = Instruments.Active.GetLMEnumerator();
             while (iter.MoveNext())
             {
                 LMInstrument lmi = (LMInstrument)iter.Current;
                 commlog.TraceEvent(LogLevels.Verbose, 360, "Send '" + LMLoggers.LognLM.FlattenChars(cmd) + LMMMLingo.eolprintrep + "' to " + Instruments.Active.RankPositionInList(lmi) + " " + lmi.port + ", ");
                 LMServer.SendData(cmd + LMMMLingo.eol, lmi.instrSocketEvent);
             }
         }
         else
         {
             int index = specificLMIndex > -1 ? specificLMIndex : CurrentLM;  // index override from live call in main code, not from command line
             // make sure the element is actually there
             commlog.TraceInformation("Send '" + LMLoggers.LognLM.FlattenChars(cmd) + LMMMLingo.eolprintrep + "' to LMMM instrument {0} on the subnet", index);
             LMInstrument lmi = Instruments.Active.FindByIndexer(index);
             if (lmi == null) // index must always be less than Count, the list is 0 based
             {
                 commlog.TraceEvent(LogLevels.Warning, 325, "No LMMM instrument {0} available", index);
             }
             else
             {
                 LMServer.SendData(cmd + LMMMLingo.eol, lmi.instrSocketEvent);
             }
         }
     }
     catch (ObjectDisposedException ex)
     {
         commlog.TraceEvent(LogLevels.Error, 354, "LOST an instrument: " + ex.Message);
     }
     catch (SocketException se)
     {
         commlog.TraceEvent(LogLevels.Error, 355, "TCP/IP send socket error: " + se.Message);
     }
     catch (Exception e)
     {
         commlog.TraceEvent(LogLevels.Error, 356, "TCP/IP send failed: " + e.Message);
     }
 }
Пример #4
0
 public void Close()
 {
     NC.App.Opstate.SOH = NCC.OperatingState.Stopped;
     NC.App.Config.RetainChanges();
     LMLoggers.LognLM applog = NC.App.Logger(LMLoggers.AppSection.App);
     applog.TraceInformation("==== Exiting " + DateTimeOffset.Now.ToString("MMM dd yyy HH:mm:ss.ff K") + " " + NC.App.Name + " . . .");
     NC.App.Loggers.Flush();
     //DisconnectUILogger = true;
 }
Пример #5
0
        void WriteSummary()
        {
            SummarySelections.ResetSummaryRows();
            foreach (ListViewItem lvi in listView1.Items)
            {
                if (!lvi.Selected)
                {
                    continue;
                }
                int lvIndex = 0;
                int.TryParse(lvi.SubItems[9].Text, out lvIndex);                 // 9 has the original mlist index of this sorted row element
                SummarySelections.Apply(mlist[lvIndex]);
            }
            if (SummarySelections.HasAny)
            {
                SaveFileDialog dlg = new SaveFileDialog();
                dlg.Filter           = "CSV files (*.csv)|*.csv|All files (*.*)|*.*";
                dlg.DefaultExt       = ".csv";
                dlg.FileName         = "summary.csv";
                dlg.InitialDirectory = N.App.AppContext.ResultsFilePath;

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    string lw = SummarySelections.HeaderRow;
                    try
                    {
                        StreamWriter tx = File.CreateText(dlg.FileName);
                        tx.WriteLine(lw);
                        System.Collections.IEnumerator iter = SummarySelections.GetEntryEnumerator();
                        while (iter.MoveNext())
                        {
                            string entry = (string)iter.Current;
                            tx.WriteLine(entry);
                        }
                        tx.Close();
                        ctrllog.TraceInformation("Summary written to " + dlg.FileName);
                    } catch (IOException ex)
                    {
                        MessageBox.Show(ex.Message, "Error on " + dlg.FileName);
                    }
                }
            }
        }
Пример #6
0
        static void Main(string[] args)
        {
            new NC("INCC6 Console");

            NCCConfig.Config c = new NCCConfig.Config(); // gets DB params
            NC.App.LoadPersistenceConfig(c.DB);          // loads up DB, sets global AppContext
            c.AfterDBSetup(NC.App.AppContext, args);     // apply the cmd line
            bool initialized = NC.App.Initialize(c);

            // check return bool and exit here on error
            if (!initialized)
            {
                return;
            }

            if (NC.App.Config.Cmd.ShowVersion && !NC.App.Config.Cmd.Showcfg)
            {
                NC.App.Config.Cmd.ShowVersionOnConsole(NC.App.Config, NC.App.Config.App.Verbose() == TraceEventType.Verbose);
                return;
            }
            else if (NC.App.Config.Cmd.Showhelp)
            {
                NC.App.Config.ShowHelp();
                return;
            }
            else if (NC.App.Config.Cmd.Showcfg)
            {
                NCCConfig.Config.ShowCfg(NC.App.Config, NC.App.Config.App.Verbose() == TraceEventType.Verbose);
                return;
            }

            LMLoggers.LognLM applog = NC.App.Logger(LMLoggers.AppSection.App);

            applog.TraceInformation("==== Starting " + DateTime.Now.ToString("MMM dd yyy HH:mm:ss.ff K") + " [Cmd] " + NC.App.Name + " " + NC.App.Config.VersionString);
            // TODO: log DB details at startup too
            try
            {
                BuildMeasurement();
                if (NC.App.Config.App.UsingFileInput)
                {
                    if (NC.App.AppContext.AssayFromFiles)
                    {
                        NC.App.Opstate.Action = NCC.NCCAction.Assay;
                    }
                    else
                    {
                        NC.App.Opstate.Action = NCC.NCCAction.File;
                    }

                    // file processing for analysis and more
                    FileControlBind filecontrol = new FileControlBind();

                    filecontrol.SetupEventHandlers();

                    filecontrol.StartAction();  // step into the code and Run run run!

                    NC.App.Opstate.SOH = NCC.OperatingState.Stopped;
                }
                else
                {
                    // NEXT: one of Assay, HV or Discover NC.App.Opstate.Action = NCC.NCCAction.;
                    // DAQ + prompt
                    DAQControlBind daqcontrol = new DAQControlBind((MLMEmulation.IEmulatorDiversion)(new LMProcessor.NullEmulation())); //<- here

                    daqcontrol.SetupTimerCallBacks();
                    daqcontrol.SetupEventHandlers();

                    DAQControlBind.ActivateDetector(NC.App.Opstate.Measurement.Detectors[0]);

                    daqcontrol.StartAction(); // step into the code and Run run run!

                    NC.App.Opstate.SOH = NCC.OperatingState.Stopped;
                }
            }
            catch (Exception e)
            {
                NC.App.Opstate.SOH = NCC.OperatingState.Trouble;
                applog.TraceException(e, true);
                applog.EmitFatalErrorMsg();
            }
            finally
            {
                NC.App.Opstate.SOH = NCC.OperatingState.Stopped;
                NC.App.Config.RetainChanges();
                applog.TraceInformation("==== Exiting " + DateTime.Now.ToString("MMM dd yyy HH:mm:ss.ff K") + " [Cmd] " + NC.App.Name + " . . .");
                NC.App.Loggers.Flush();
            }
        }
Пример #7
0
        static void Main(string[] args)
        {
            new N("INCC6 Console");
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            NCCConfig.Config c = new NCCConfig.Config();        // gets DB params
            if (!N.App.LoadPersistenceConfig(c.DB))             // loads up DB, sets global AppContext
            {
                return;
            }
            c.AfterDBSetup(N.App.AppContext, args);                                                                    // apply the cmd line
            string[] possiblepaths = NCCFile.FileCtrl.ProcessINCC5IniFile(N.App.Logger(LMLoggers.AppSection.Control)); // iRap: optional use of INCC5 ini file to find results and output paths
            if (possiblepaths.Length > 2)                                                                              // use the iRAP defined input, results and log file paths
            {
                N.App.AppContext.FileInput = possiblepaths[0];
                if (System.IO.Directory.Exists(possiblepaths[1]))
                {
                    N.App.AppContext.ResultsFilePath = possiblepaths[1];
                }
                if (System.IO.Directory.Exists(possiblepaths[2]))
                {
                    N.App.AppContext.LogFilePath = possiblepaths[2];
                }
            }
            // check return bool and exit here on error
            bool initialized = N.App.Initialize(c);

            if (!initialized)
            {
                return;
            }

            if (N.App.Config.Cmd.ShowVersion && !N.App.Config.Cmd.Showcfg)
            {
                N.App.Config.Cmd.ShowVersionOnConsole(N.App.Config, N.App.Config.App.Verbose() == TraceEventType.Verbose);
                return;
            }
            else if (N.App.Config.Cmd.Showhelp)
            {
                N.App.Config.ShowHelp();
                return;
            }
            else if (N.App.Config.Cmd.Showcfg)
            {
                NCCConfig.Config.ShowCfg(N.App.Config, N.App.Config.App.Verbose() == TraceEventType.Verbose);
                return;
            }

            LMLoggers.LognLM applog      = N.App.Logger(LMLoggers.AppSection.App);
            bool             OpenResults = N.App.AppContext.OpenResults;

            try
            {
                applog.TraceInformation("==== Starting " + DateTime.Now.ToString("MMM dd yyy HH:mm:ss.ff K") + " [Cmd] " + N.App.Name + " " + N.App.Config.VersionString);
                applog.TraceInformation("==== DB " + N.App.Pest.DBDescStr);
                // These affect the current acquire state, so they occur here and not earlier in the initial processing sequence
                if (!string.IsNullOrEmpty(c.Cur.Detector) && !c.Cur.Detector.Equals("Default"))                 // command line set the value
                {
                    initialized = Integ.SetNewCurrentDetector(c.Cur.Detector, true);
                }
                if (!initialized)
                {
                    goto end;
                }

                if (!string.IsNullOrEmpty(c.Cur.Material) && !c.Cur.Material.Equals("Pu")) // command line set the value
                {
                    initialized = Integ.SetNewCurrentMaterial(c.Cur.Material, true);
                }
                if (!initialized)
                {
                    goto end;
                }

                if (!string.IsNullOrEmpty(c.Cur.ItemId)) // command line set the item value, use it to override the material and other acquire params
                {
                    initialized = Integ.SetNewCurrentMaterial(c.Cur.Material, true);
                }
                if (!initialized)
                {
                    goto end;
                }

                if (!N.App.AppContext.ReportSectional.Equals(NCCConfig.Config.DefaultReportSectional))                 // command line set the value
                {
                    AcquireParameters acq = null;
                    Detector          det = null;
                    Integ.GetCurrentAcquireDetectorPair(ref acq, ref det);
                    acq.review.Scan(N.App.AppContext.ReportSectional);
                    acq.MeasDateTime = DateTime.Now;
                    N.App.DB.UpdateAcquireParams(acq, det.ListMode);
                    N.App.Logger(LMLoggers.AppSection.Control).TraceEvent(LogLevels.Info, 32444, "The current report sections are now " + N.App.AppContext.ReportSectional);
                }
                if (N.App.Config.App.UsingFileInput || N.App.Opstate.Action == NCC.NCCAction.File)
                {
                    if (N.App.AppContext.AssayFromFiles)
                    {
                        N.App.Opstate.Action = NCC.NCCAction.Assay;
                    }
                    else if (N.App.AppContext.HasFileAction)
                    {
                        N.App.Opstate.Action = NCC.NCCAction.File;
                    }
                }

                if (N.App.Config.Cmd.Query != null)
                {
                    AcquireParameters acq = Integ.GetCurrentAcquireParams();
                    System.Collections.Generic.List <string> ls = acq.ToDBElementList(generate: true).AlignedNameValueList;
                    foreach (string s in ls)
                    {
                        Console.WriteLine(s);
                    }
                    OpenResults = false;
                    if (N.App.Opstate.Action == NCC.NCCAction.Nothing)
                    {
                        return;
                    }
                }


                if (N.App.Config.App.UsingFileInput || N.App.Opstate.Action == NCC.NCCAction.File)
                {
                    BuildMeasurement();
                    if (N.App.AppContext.AssayFromFiles)
                    {
                        N.App.Opstate.Action = NCC.NCCAction.Assay;
                    }
                    else if (N.App.AppContext.HasFileAction)
                    {
                        N.App.Opstate.Action = NCC.NCCAction.File;
                    }

                    // file processing for analysis and more
                    FileControlBind filecontrol = new FileControlBind();
                    filecontrol.SetupEventHandlers();
                    filecontrol.StartAction();                      // step into the code and run
                    N.App.Opstate.SOH = NCC.OperatingState.Stopped;
                }
                else
                {
                    BuildMeasurement();
                    DAQControlBind control = new DAQControlBind();
                    DAQ.DAQControl.ActivateDetector(N.App.Opstate.Measurement.Detector);
                    control.SetupEventHandlers();
                    control.StartAction();
                    N.App.Opstate.SOH = NCC.OperatingState.Stopped;
                }
end:
                ;
            } catch (Exception e)
            {
                N.App.Opstate.SOH = NCC.OperatingState.Trouble;
                applog.TraceException(e, true);
                applog.EmitFatalErrorMsg();
            } finally
            {
                N.App.Opstate.SOH = NCC.OperatingState.Stopped;
                N.App.Config.RetainChanges();
                applog.TraceInformation("==== Exiting " + DateTime.Now.ToString("MMM dd yyy HH:mm:ss.ff K") + " [Cmd] " + N.App.Name + " . . .");
                N.App.Loggers.Flush();
                if (OpenResults)
                {
                    Process.Start(System.IO.Path.Combine(Environment.SystemDirectory, "notepad.exe"), LMLoggers.LognLM.CurrentLogFilePath);
                }
            }
        }
Пример #8
0
 public bool DivertToEmulation(object op, int arg, int LMIndex)
 {
     LMMMLingo.OpDesc opd = (LMMMLingo.OpDesc)op;
     commlog.TraceInformation(opd.ToString() + "(" + arg + ":" + LMIndex + ")");
     return(true);
 }
Пример #9
0
 // controller has active control of processing through these three entry points
 public void CancelCurrentAction()
 {
     ctrllog.TraceInformation("Cancelling the {0} action ({1} instrument{2})", NC.App.Opstate.Action, Instruments.Active.Count, (Instruments.Active.Count == 1 ? String.Empty : "s"));
     NC.App.Opstate.SOH = NCC.OperatingState.Cancelling;
     CurState.Cancel();
 }