Esempio n. 1
0
 private void SetPredelayStepConstraint(InstrType t)
 {
     if (t.IsListMode() || t == InstrType.JSR15)
     {
         PredelayTextBox.Steps = -1;                 // no check
     }
     else
     {
         PredelayTextBox.Steps = 0.25;                 // traditional step increment
         if ((PredelayTextBox.Value % 0.25) != 0)
         {
             PredelayTextBox.Value = Bounce25Step(PredelayTextBox.Value);
         }
     }
 }
Esempio n. 2
0
        public DataSourceIdentifier(DataSourceIdentifier dsid)
        {
            iname    = string.Copy(dsid.iname);
            srtype   = dsid.srtype;
            version  = dsid.version;
            elecid   = string.Copy(dsid.elecid);
            filename = string.Copy(dsid.filename);
            dt       = new DateTimeOffset(dsid.dt.Ticks, dsid.dt.Offset);
            source   = dsid.source;
            desc     = string.Copy(dsid.desc);
            type     = string.Copy(dsid.type);

            Type            t  = dsid.conninfo.GetType();
            ConstructorInfo ci = t.GetConstructor(new Type[] { t });

            conninfo = (ConnectionInfo)ci.Invoke(new object[] { dsid.conninfo });
        }
Esempio n. 3
0
        private void ShiftRegisterTypeComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            InstrType t = InstrType.AMSR;

            /* JFL added, type changes within the SR/LM families are supported */
            if (det.Id.SRType.IsListMode())
            {
                System.Enum.TryParse <InstrType>((string)ShiftRegisterTypeComboBox.SelectedItem, true, out t);
            }
            else
            {
                t = InstrTypeExtensions.INCC5ComboBoxStringToType((string)ShiftRegisterTypeComboBox.SelectedItem);
            }
            if (det.Id.SRType != t)
            {
                det.Id.modified = true;
            }
            det.Id.SRType = t;

            SecondGateLengthLabel.Visible   = (t == InstrType.DGSR);
            SecondGateLengthTextBox.Visible = (t == InstrType.DGSR);
            SetBaudRateSelectorVisibility(t.IsSRWithVariableBaudRate());
        }
Esempio n. 4
0
        public static double TimeBase(this ConstructedSource src, InstrType device)
        {
            double te = 1e-7;

            switch (device)
            {
            case InstrType.PTR32:
            case InstrType.MCNPX:
            case InstrType.NILA:     // TODO: not yet defined Nov 2013 MTS
            case InstrType.N1:
                te = 1e-8;
                break;
            }

            switch (src)
            {
            case ConstructedSource.PTRFile:
            case ConstructedSource.SortedPulseTextFile:
            case ConstructedSource.NILAFile:
                te = 1e-8;
                break;
            }
            return(te);
        }
Esempio n. 5
0
        /// <summary>
        /// Create a new detector in-memory, with the related classes.
        /// Emulates the INCC relationship constructor, caller must insert new det into global list, then update to DB later for persistence
        /// </summary>
        /// <param name="model">detector to copy</param>
        /// <param name="newId">New detector name</param>
        /// <param name="elecId">Electronics id (just a string)</param>
        /// <param name="typeDesc">Type description (just a string)</param>
        /// <param name="srType">Actual instrument type</param>
        /// <returns>The newly created in-memory Detector class instance</returns>
        static public Detector CreateDetectorWithAssociations(Detector model, string newId, string elecId, string typeDesc, InstrType srType = InstrType.AMSR)
        {
            if (model != null)
            {
                Detector det = new Detector(model); // copies the SR too
                det.Id.SetIdDetails(newId, elecId, typeDesc, model.Id.SRType);

                // copy the model detector's related parameters (skips stratum)
                NormParameters          n          = CentralizedState.App.DB.NormParameters.Get(model);
                NormParameters          Norm       = new NormParameters(n);
                BackgroundParameters    b          = CentralizedState.App.DB.BackgroundParameters.Get(model);
                BackgroundParameters    Background = new BackgroundParameters(b);
                UnattendedParameters    u          = CentralizedState.App.DB.UnattendedParameters.Get(model);
                UnattendedParameters    Unatt      = new UnattendedParameters(u);
                AddASourceSetup         a          = CentralizedState.App.DB.AASSParameters.Get(model);
                AddASourceSetup         Aass       = new AddASourceSetup(a);
                HVCalibrationParameters h          = CentralizedState.App.DB.HVParameters.Get(model);
                HVCalibrationParameters Hv         = new HVCalibrationParameters(h);

                // add copied param instances to in-memory maps
                CentralizedState.App.DB.NormParameters.Map.Add(det, Norm);
                CentralizedState.App.DB.UnattendedParameters.Map.Add(det, Unatt);
                CentralizedState.App.DB.BackgroundParameters.Map.Add(det, Background);
                CentralizedState.App.DB.AASSParameters.Map.Add(det, Aass);
                CentralizedState.App.DB.HVParameters.Map.Add(det, Hv);

                CentralizedState.App.DB.Detectors.Add(det); // add detector to in-memory list

                return(det);
            }
            else
            {
                Detector det = new Detector();
                det.Id.SetIdDetails(newId, elecId, typeDesc, srType);

                if (srType.IsListMode())
                {
                    det.Id.FullConnInfo = new LMConnectionInfo();
                }

                // add fresh param instances to in-memory maps
                CentralizedState.App.DB.NormParameters.Map.Add(det, new NormParameters());
                CentralizedState.App.DB.UnattendedParameters.Map.Add(det, new UnattendedParameters());
                CentralizedState.App.DB.BackgroundParameters.Map.Add(det, new BackgroundParameters());
                CentralizedState.App.DB.AASSParameters.Map.Add(det, new AddASourceSetup());
                CentralizedState.App.DB.HVParameters.Map.Add(det, new HVCalibrationParameters());

                CentralizedState.App.DB.Detectors.Add(det); // add detector to in-memory list

                return(det);
            }

            /*  * todo: create analysis selector (or it happens automatically when first referenced?)
             * creating a stratum association
             * */
        }
Esempio n. 6
0
        /// <summary>
        /// Create a new detector in-memory, with the related classes.
        /// Emulates the INCC relationship constructor, caller must insert new det into global list, then update to DB later for persistence
        /// </summary>
        /// <param name="model">detector to copy</param>
        /// <param name="newId">New detector name</param>
        /// <param name="elecId">Electronics id (just a string)</param>
        /// <param name="typeDesc">Type description (just a string)</param>
        /// <param name="srType">Actual instrument type</param>
        /// <returns>The newly created in-memory Detector class instance</returns>
        public static Detector CreateDetectorWithAssociations(Detector model, string newId, string elecId, string typeDesc, InstrType srType = InstrType.AMSR)
        {
            if (model != null)
            {
                Detector det = new Detector(model); // copies the SR too
                det.Id.SetIdDetails(newId, elecId, typeDesc, model.Id.SRType);

                // copy the model detector's related parameters (skips stratum)
                NormParameters n = CentralizedState.App.DB.NormParameters.Get(model);
                NormParameters Norm = new NormParameters(n);
                BackgroundParameters b = CentralizedState.App.DB.BackgroundParameters.Get(model);
                BackgroundParameters Background = new BackgroundParameters(b);
                UnattendedParameters u = CentralizedState.App.DB.UnattendedParameters.Get(model);
                UnattendedParameters Unatt = new UnattendedParameters(u);
                AddASourceSetup a = CentralizedState.App.DB.AASSParameters.Get(model);
                AddASourceSetup Aass = new AddASourceSetup(a);
                HVCalibrationParameters h = CentralizedState.App.DB.HVParameters.Get(model);
                HVCalibrationParameters Hv = new HVCalibrationParameters(h);

                // add copied param instances to in-memory maps
                CentralizedState.App.DB.NormParameters.Map.Add(det, Norm);
                CentralizedState.App.DB.UnattendedParameters.Map.Add(det, Unatt);
                CentralizedState.App.DB.BackgroundParameters.Map.Add(det, Background);
                CentralizedState.App.DB.AASSParameters.Map.Add(det, Aass);
                CentralizedState.App.DB.HVParameters.Map.Add(det, Hv);

                CentralizedState.App.DB.Detectors.Add(det); // add detector to in-memory list

                return det;
            }
            else
            {
                Detector det = new Detector();
                det.Id.SetIdDetails(newId, elecId, typeDesc,srType);

                if (srType.IsListMode())
                    det.Id.FullConnInfo = new LMConnectionInfo();

                // add fresh param instances to in-memory maps
                CentralizedState.App.DB.NormParameters.Map.Add(det, new NormParameters());
                CentralizedState.App.DB.UnattendedParameters.Map.Add(det, new UnattendedParameters());
                CentralizedState.App.DB.BackgroundParameters.Map.Add(det, new BackgroundParameters());
                CentralizedState.App.DB.AASSParameters.Map.Add(det, new AddASourceSetup());
                CentralizedState.App.DB.HVParameters.Map.Add(det, new HVCalibrationParameters());

                CentralizedState.App.DB.Detectors.Add(det); // add detector to in-memory list

                return det;
            }

            /*  * todo: create analysis selector (or it happens automatically when first referenced?)
                * creating a stratum association
             * */
        }
Esempio n. 7
0
 public Instruction(InstrType type, int arg1, int arg2)
 {
     this.type = type;
     this.arg1 = arg1;
     this.arg2 = arg2;
 }
Esempio n. 8
0
 public static bool IsSocketBasedLM(this InstrType itype)
 {
     return(itype == InstrType.NPOD || itype == InstrType.LMMM || itype == InstrType.MCA527);
 }
Esempio n. 9
0
 /// <summary>
 /// These modern SRs have 512 multiplicity
 /// </summary>
 /// <param name="itype"></param>
 /// <returns></returns>
 public static bool BigLoveMultiplicity(this InstrType itype)
 {
     return(itype == InstrType.JSR15 || itype == InstrType.UNAP);
 }
Esempio n. 10
0
 public HistoryRecord(InstrType instructionType)
 {
     //NOTE: Possible bug here
     //We could possibly be missing this assignment perhaps:
     //InstructionType = instructionType;
 }
Esempio n. 11
0
 private void SetPredelayStepConstraint(InstrType t)
 {
     if (t.IsListMode() || t == InstrType.JSR15)
         PredelayTextBox.Steps = -1; // no check
     else
     {
         PredelayTextBox.Steps = 0.25; // traditional step increment
         if ((PredelayTextBox.Value % 0.25) != 0)
         {
             PredelayTextBox.Value = Bounce25Step(PredelayTextBox.Value);
         }
     }
 }
Esempio n. 12
0
        unsafe public int sr_init(double time_per_run, double sethigh_voltage)
        {
            restart_time_per_run = time_per_run; restart_sethigh_voltage = sethigh_voltage;
            const double MAX_HV_DELTA = 2.0;

            sr_h.sr_parms parms;
            double        high_voltage, previous_high_voltage;
            int           status;
            ushort        i;

            if (time_per_run <= 0.0)
            {
                return(SR.ZERO_COUNT_TIME);
            }

            /* as a diagnostic, dump all shift register data to a file */
            /* sr_set_log_fname ("sr_data.tst"); */


            // todo: add use of progress event reporting via the timer here
            //        "Please wait, opening shift register.");

            log.TraceEvent(LogLevels.Info, 0x4f32F, "Please wait, opening shift register");

            /* open shift register */
            i = 0;
            InstrType insttype = dsid.SRType;

            do
            {
                i++;
                if (dsid.SRType == InstrType.JSR11)
                {
                    dsid.BaudRate = JSR11_BAUD_RATE;
                }
                else if (dsid.SRType == InstrType.JSR12)
                {
                    dsid.BaudRate = JSR12_BAUD_RATE;
                }
                else if ((dsid.SRType == InstrType.PSR) ||
                         (dsid.SRType == InstrType.AMSR) || dsid.SRType.isVirtualAMSR())
                {
                    if (dsid.SRType == InstrType.AMSR && dsid.BaudRate != PSR_BAUD_RATE)                                      // AMSR faux override for UNAP
                    {
                        log.TraceEvent(LogLevels.Verbose, 0x4f32D, "AMSR Baud rate override at " + dsid.BaudRate.ToString()); // retain AMSR setting, probably fine
                    }
                    else if (dsid.SRType == InstrType.PSR && dsid.BaudRate != PSR_BAUD_RATE)                                  // PSR faux override for JSR15
                    {
                        log.TraceEvent(LogLevels.Verbose, 0x4f32D, "PSR Baud rate override at " + dsid.BaudRate.ToString());  //retain PSR setting, probably bad fail for JSR15
                    }
                    else if (dsid.SRType.BigLoveMultiplicity())
                    {
                        log.TraceEvent(LogLevels.Verbose, 0x4f337, dsid.SRType.ToString() + " Baud rate is " + dsid.BaudRate.ToString()); // explicitly JSR15 or UNAP
                    }
                    else
                    {
                        dsid.BaudRate = PSR_BAUD_RATE; // the original INCC5 treatment
                        insttype      = InstrType.PSR;
                    }
                }
                else if (dsid.SRType == InstrType.DGSR)
                {
                    dsid.BaudRate = DGSR_BAUD_RATE;
                }
                else if (dsid.SRType == InstrType.JSR15 || dsid.SRType == InstrType.UNAP)
                {
                    // use the user-level setting dsid.BaudRate
                    log.TraceEvent(LogLevels.Verbose, 0x4f335, "JSR15 Baud rate is " + dsid.BaudRate.ToString()); // dsid.BaudRate
                }
                else
                {
                    dsid.BaudRate = MSR4A_BAUD_RATE;
                }
                status = SRLib.Open(dsid.SerialPort, (int)insttype, dsid.BaudRate);
                if (status != sr_h.SR_SUCCESS)
                {
                    sr_stop();
                    if (i < SR.SR_NUM_TRYS)
                    {
                        log.TraceEvent(LogLevels.Warning, 0x4f335, "Retrying the shift register init process");
                    }
                }
            } while ((status != sr_h.SR_SUCCESS) && (i < SR.SR_NUM_TRYS) && !lcts.IsCancellationRequested);

            if ((status != sr_h.SR_SUCCESS))
            {
                log.TraceEvent(LogLevels.Warning, 0x4f330, "{0}; Unable to open shift register serial port {1} for the {2} at rate {3}\r\nCheck serial port # and baud rate, traditionally 9600 (300 for the JSR-11), can be higher for JSR15/HHMR and later devices",
                               sr_h.SRFunctionReturnStatusCode(status), dsid.SerialPort + 1, dsid.SRType.ToString(), dsid.BaudRate.ToString());
                //log.TraceEvent(LogLevels.Warning, 0x4f330, "{0}; Unable to open shift register serial port.\r\nMake sure that the shift register is turned on and properly connected.\r\nMake sure that the baud rate is set to 9600 (300 for the JSR-11).\r\nYou should also use the Measurement Parameters dialog box under Setup to verify that you have selected the correct shift register type and serial port", sr_h.SRFunctionReturnStatusCode(status));
                return(status);
            }
            else
            {
                log.TraceEvent(LogLevels.Verbose, 0x4f32B, "Opened shift register serial port {0} for the {1} at rate {2}", dsid.SerialPort + 1, dsid.SRType.ToString(), dsid.BaudRate);
            }

            /* set shift register parameters */
            parms.predelay = sr_parms.predelayMS;
            parms.gate     = sr_parms.gateLengthMS;
            parms.time     = time_per_run;
            parms.hv       = sethigh_voltage;
            if (dsid.SRType == InstrType.DGSR)
            {
                parms.gate2 = sr_parms.gateLengthMS; // todo: DGSR gate_length2, but no-one will ever need it
            }
            else
            {
                parms.gate2 = 0.0;
            }
            i = 0;
            do
            {
                status = SRLib.Control(dsid.SerialPort, sr_h.SR_SET_PARMS, ref parms);
                i++;
            } while ((status != sr_h.SR_SUCCESS) && (i < SR.SR_NUM_TRYS) && !lcts.IsCancellationRequested);
            if ((status != sr_h.SR_SUCCESS)) // devnote: this test can fail for JSR-15 with an open serial port, then must depend upon the timeout failure in the voltage step following
            {
                log.TraceEvent(LogLevels.Warning, 0x4f331, "{0}; Unable to set shift register parameters; HV {1}, predelay {2}, gate {3}; {4} second cycle", sr_h.SRFunctionReturnStatusCode(status), parms.hv, parms.predelay, parms.gate, parms.time);
                sr_stop();
                return(status);
            }
            else
            {
                log.TraceEvent(LogLevels.Verbose, 0x4f32A, "Set shift register parameters; HV {0}, predelay {1}, gate {2}; {3} second cycle", parms.hv, parms.predelay, parms.gate, parms.time);
            }
            bool   retry    = false;
            ushort timeouts = 0;             // allow for 100 retries with timeouts (hn), a timeout means something is wrong with communication

            /* if a PSR, JSR-12, DGSR or AMSR (or JSR15/UNAP) then wait for high voltage to stabilize. */
            if ((dsid.SRType == InstrType.PSR) ||
                dsid.SRType.isDG_AMSR_Match() ||
                (dsid.SRType == InstrType.JSR12))
            {
                i            = 0;
                high_voltage = 0.0;
                do
                {
                    previous_high_voltage = high_voltage;
                    Thread.Sleep(200);  // devnote: time needed for HV operations to settle, much more needed for HHMR
                    if (dsid.SRType == InstrType.PSR || dsid.SRType == InstrType.AMSR || dsid.SRType == InstrType.UNAP)
                    {
                        status = SRLib.Ioctl(dsid.SerialPort, sr_h.SR_PSR_GET_HV,
                                             ref high_voltage);
                    }
                    else if (dsid.SRType == InstrType.JSR12)
                    {
                        status = SRLib.Ioctl(dsid.SerialPort, sr_h.SR_JSR12_GET_HV,
                                             ref high_voltage);
                    }
                    else if (dsid.SRType == InstrType.JSR15) // HHMR
                    {
                        //log.TraceEvent(LogLevels.Warning, 0x4f334, "SR_HHMR_GET_HV aka SRIOR(SR_TYPE_HHMR, 15) times out, skipping HV stabilization step");
                        //status = sr_h.SR_SUCCESS;
                        //break;
                        if (i == 0)
                        {
                            Thread.Sleep(1000); // initially wait for HHMR to settle
                        }
                        status = SRLib.Ioctl(dsid.SerialPort, sr_h.SR_HHMR_GET_HV,
                                             ref high_voltage);
                    }
                    else
                    {
                        status = SRLib.Ioctl(dsid.SerialPort, sr_h.SR_DGSR_GET_HV,
                                             ref high_voltage);
                    }
                    if (i != 0)
                    {
                        Thread.Sleep(1000); // 1 sec
                    }
                    if (status == sr_h.SR_TIMEOUT)
                    {
                        timeouts++;
                    }

                    retry = !(((Math.Abs(high_voltage - previous_high_voltage) > MAX_HV_DELTA) && // while have not matched voltage
                               (status == sr_h.SR_SUCCESS) && (i < 100))) ||                // and the connection is good and we haven't yet tried 100 times
                            timeouts >= 100;                                                      // OR it simply timed out too many times
                    if (retry && ((i % 2) == 0) && status == sr_h.SR_TIMEOUT)
                    {
                        log.TraceEvent(LogLevels.Warning, 0x4f332, "Set voltage attempt {0} of 100, HV {1}, SR status {2}", i + 1, Math.Abs(high_voltage - previous_high_voltage), sr_h.SRFunctionReturnStatusCode(status));
                    }

                    if (lcts.IsCancellationRequested)                      // punt here
                    {
                        break;
                    }
                    i++;
                } while (retry);
                // devnote: When a timeout occurred, the original code exited. Now, check for TIMEOUT condition and try again up to 100 tries hn
                if ((status != sr_h.SR_SUCCESS) || (i >= 100) || (timeouts >= 100))
                {
                    log.TraceEvent(LogLevels.Warning, 0x4f332, "{0} {1}; Unable to set shift register high voltage", sr_h.SRFunctionReturnStatusCode(status), i);
                }
            }

            return(status);
        }
Esempio n. 13
0
 public static AnalysisDefs.FAType DefaultFAFor(this InstrType itype)
 {
     return(itype >= InstrType.AMSR ? AnalysisDefs.FAType.FAOn : AnalysisDefs.FAType.FAOff);
 }
Esempio n. 14
0
        static public List <Instrument> All       = Active;                     // the complete list active/inactive

        public static bool NativeFA(this InstrType it)
        {
            return(it.isDG_AMSR_Match());
        }
Esempio n. 15
0
 public static FAType DefaultFAFor(this InstrType itype)
 {
     return(itype >= InstrType.AMSR ? FAType.FAOn : FAType.FAOff);
 }
Esempio n. 16
0
 /// <summary>
 /// originally matched only on DGSR and AMSR, added HHMR/JSR15 and UNAP (potentially an issue if JSR15 is not using fast acc)
 /// </summary>
 /// <param name="itype"></param>
 /// <returns></returns>
 public static bool isDG_AMSR_Match(this InstrType itype)
 {
     return(itype >= InstrType.DGSR && itype <= InstrType.UNAP);
 }
Esempio n. 17
0
 public static bool IsCOMPortBasedSR(this InstrType itype)
 {
     return(itype <= InstrType.JSR15);
 }
Esempio n. 18
0
 /// <summary>
 /// AMSR selected, or faux-AMSR via UNAP/JSR15 choices
 /// </summary>
 /// <param name="itype"></param>
 /// <returns></returns>
 public static bool isVirtualAMSR(this InstrType itype)
 {
     return(itype >= InstrType.AMSR && itype <= InstrType.UNAP);
 }
Esempio n. 19
0
 public static bool IsSRWithVariableBaudRate(this InstrType itype)
 {
     return(itype < InstrType.NPOD && itype >= InstrType.JSR15);
 }
Esempio n. 20
0
 public static bool IsListMode(this InstrType itype)
 {
     return(itype >= InstrType.NPOD && itype <= InstrType.MCA527);
 }
Esempio n. 21
0
 public static bool CanDoTriples(this InstrType itype)
 {
     return(itype >= InstrType.MSR4A);
 }
Esempio n. 22
0
 public static bool IsUSBBasedLM(this InstrType itype)
 {
     return(itype == InstrType.PTR32);
 }
Esempio n. 23
0
 public static bool SRDAQ(this ConstructedSource src, InstrType device)
 {
     return((src == ConstructedSource.Live) && (device <= InstrType.UNAP));  // it is a Live SR DAQ
 }
Esempio n. 24
0
 public static bool MightHaveScalerData(this ConstructedSource src, InstrType device)
 {
     return((device <= InstrType.UNAP) &&
            (src.INCC5FileData() || src.INCCTransferData() || src == ConstructedSource.Reanalysis));
 }
Esempio n. 25
0
        public static bool LMFiles(this ConstructedSource src, InstrType device)
        {
            bool ack = (src >= ConstructedSource.NCDFile && src <= ConstructedSource.SortedPulseTextFile) && device.IsListMode();  // data from other source and the processing went through the raw counting code

            return(ack);
        }
Esempio n. 26
0
 /// <summary>
 /// Set up the meta-data needed for cycle processing.
 /// Important for cycles obtained from files and the database.
 /// </summary>
 /// <param name="data_src">Source of cycle data</param>
 /// <param name="SRType">Expected detector type</param>
 /// <param name="dto">The start DateTimeOffset timestamp of the cycle</param>
 /// <param name="path">Filename of source of cycle, if any</param>
 public void UpdateDataSourceId(ConstructedSource data_src, InstrType SRType, DateTimeOffset dto, string path)
 {
     dsid.source = data_src;
     dsid.SRType = SRType;
     if (!string.IsNullOrEmpty(path))
         dsid.FileName = path;
     dsid.dt = dto;
 }
Esempio n. 27
0
 public static bool HasFA(this InstrType itype)
 {
     return(itype >= InstrType.AMSR);
 }
Esempio n. 28
0
 private CacheInstruction(InstrType type, int instrVal)
 {
     this.type     = type;
     this.instrVal = instrVal;
 }
Esempio n. 29
0
 public Detector(Detector src, string ID, string typedescr, string elec_id, InstrType inst)
     : base(new DataSourceIdentifier(src.Item1), new Multiplicity(src.Item2), new AlphaBeta(src.Item3))
 {
     this.Item1.SetIdDetails(ID, elec_id, typedescr, inst);
 }