示例#1
0
文件: Analog.cs 项目: minosniu/nersa
        public int FindAnalogChansOfType(MccDaq.MccBoard DaqBoard,
                                         int AnalogType, out int Resolution, out MccDaq.Range DefaultRange,
                                         out int DefaultChan, out MccDaq.TriggerType DefaultTrig)
        {
            int ChansFound, IOType;

            MccDaq.ErrorInfo ULStat;
            bool             CheckPretrig, CheckATrig = false;

            MccDaq.Range TestRange;
            bool         RangeFound;

            // check supported features by trial
            // and error with error handling disabled
            ULStat = MccDaq.MccService.ErrHandling
                         (MccDaq.ErrorReporting.DontPrint, MccDaq.ErrorHandling.DontStop);

            TestBoard    = DaqBoard;
            ATrigRes     = 0;
            DefaultChan  = 0;
            DefaultTrig  = TriggerType.TrigPosEdge;
            DefaultRange = Range.NotUsed;
            Resolution   = 0;
            IOType       = (AnalogType & 3);
            switch (IOType)
            {
            case ANALOGINPUT:
                // Get the number of A/D channels
                ULStat = DaqBoard.BoardConfig.GetNumAdChans(out ChansFound);
                if (!(ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors))
                {
                    clsErrorDefs.DisplayError(ULStat);
                    return(ChansFound);
                }
                if (ChansFound > 0)
                {
                    // Get the resolution of A/D
                    ULStat = DaqBoard.BoardConfig.GetAdResolution(out ADRes);
                    if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                    {
                        Resolution = ADRes;
                    }
                    // check ranges for a valid default
                    RangeFound = TestInputRanges(out TestRange);
                    if (RangeFound)
                    {
                        DefaultRange = TestRange;
                    }
                }
                break;

            default:
                // Get the number of D/A channels
                ULStat = DaqBoard.BoardConfig.GetNumDaChans(out ChansFound);
                if (!(ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors))
                {
                    clsErrorDefs.DisplayError(ULStat);
                    return(ChansFound);
                }
                if (ChansFound > 0)
                {
                    ULStat     = TestBoard.GetConfig(2, 0, 292, out DARes);
                    Resolution = DARes;
                    RangeFound = TestOutputRanges(out TestRange);
                    if (RangeFound)
                    {
                        DefaultRange = TestRange;
                    }
                }
                break;
            }

            CheckATrig = ((AnalogType & ATRIGIN) == ATRIGIN);
            if ((ChansFound > 0) & CheckATrig)
            {
                ULStat = DaqBoard.SetTrigger(MccDaq.TriggerType.TrigAbove, 0, 0);
                if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                {
                    DefaultTrig = MccDaq.TriggerType.TrigAbove;
                    GetTrigResolution();
                }
                else
                {
                    ChansFound = 0;
                }
            }

            CheckPretrig = ((AnalogType & PRETRIGIN) == PRETRIGIN);
            if ((ChansFound > 0) & CheckPretrig)
            {
                // if DaqSetTrigger supported, trigger type is analog
                ULStat = DaqBoard.DaqSetTrigger(MccDaq.TriggerSource.TrigImmediate,
                                                MccDaq.TriggerSensitivity.AboveLevel, 0, MccDaq.ChannelType.Analog,
                                                DefaultRange, 0.0F, 0.1F, MccDaq.TriggerEvent.Start);
                if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                {
                    DefaultTrig = MccDaq.TriggerType.TrigAbove;
                }
                else
                {
                    ULStat = DaqBoard.SetTrigger(MccDaq.TriggerType.TrigPosEdge, 0, 0);
                    if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                    {
                        DefaultTrig = MccDaq.TriggerType.TrigPosEdge;
                    }
                    else
                    {
                        ChansFound = 0;
                    }
                }
            }
            ULStat = MccDaq.MccService.ErrHandling
                         (clsErrorDefs.ReportError, clsErrorDefs.HandleError);
            return(ChansFound);
        }