示例#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);
        }
示例#2
0
        private void cmdStart_Click(object eventSender, System.EventArgs eventArgs)         /* Handles cmdStart.Click */
        {
            cmdStart.Enabled = false;

            //  Select the trigger source using Mccdaq.MccBoard.SetTrigger()
            //  Parameters:
            //    TrigType       :the type of triggering based on external trigger source
            //    LowThreshold   :Low threshold when the trigger input is analog
            //    HighThreshold  :High threshold when the trigger input is analog
            float highVal = 1.0F;

            MccDaq.Range Range         = MccDaq.Range.Bip10Volts;     // analog trigger range
            ushort       HighThreshold = 0;

            MccDaq.ErrorInfo ULStat = DaqBoard.FromEngUnits(Range, highVal, out HighThreshold);

            float  lowVal       = 0.1F;
            ushort LowThreshold = 0;

            ULStat = DaqBoard.FromEngUnits(Range, lowVal, out LowThreshold);

            MccDaq.TriggerType TrigType = MccDaq.TriggerType.TrigAbove;
            ULStat = DaqBoard.SetTrigger(TrigType, LowThreshold, HighThreshold);

            if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                //  Collect the values with MccDaq.MccBoard.AInScan()
                //  Parameters:
                //    LowChan    :the first channel of the scan
                //    HighChan   :the last channel of the scan
                //    Count      :the total number of A/D samples to collect
                //    Rate       :sample rate
                //    Range      :the range for the board
                //    MemHandle  :Handle for Windows buffer to store data in
                //    Options    :data collection options
                int LowChan = 0;                        //  first channel to acquire
                HighChan = int.Parse(txtHighChan.Text); //  last channel to acquire
                if (HighChan > 7)
                {
                    HighChan = 7;
                }
                txtHighChan.Text = HighChan.ToString();

                int Count = NumPoints;                                      //  total number of data points to collect
                int Rate  = 390;                                            //  per channel sampling rate ((samples per second) per channel)
                Range = MccDaq.Range.Bip5Volts;                             // set the range
                MccDaq.ScanOptions Options = MccDaq.ScanOptions.ConvertData //  return data as 12-bit values
                                             | MccDaq.ScanOptions.ExtTrigger;
                ULStat = DaqBoard.AInScan(LowChan, HighChan, Count, ref Rate, Range, MemHandle, Options);

                if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.BadRange)
                {
                    MessageBox.Show("Change the Range argument to one supported by this board.", "Unsupported Range", 0);
                }


                //  Transfer the data from the memory buffer set up by Windows to an array
                ULStat = MccDaq.MccService.WinBufToArray(MemHandle, out ADData[0], FirstPoint, Count);


                for (int i = 0; i <= HighChan; ++i)
                {
                    lblADData[i].Text = ADData[i].ToString("0");
                }

                for (int j = HighChan + 1; j <= 7; ++j)
                {
                    lblADData[j].Text = "";
                }
            }
            cmdStart.Enabled = true;
        }
示例#3
0
        private void cmdStart_Click(object eventSender, System.EventArgs eventArgs)
        {
            string TrigSource;

            MccDaq.ErrorInfo   ULStat;
            MccDaq.TriggerType TrigType;
            float LSB, VoltageRange;
            int   FSCounts, Rate;
            bool  ValidChan;

            cmdStart.Enabled = false;

            //  Select the trigger source using Mccdaq.MccBoard.SetTrigger()
            //  Parameters:
            //    TrigType       :the type of triggering based on external trigger source
            //    LowThreshold   :Low threshold when the trigger input is analog
            //    HighThreshold  :High threshold when the trigger input is analog

            float highVal = 1.53F;
            float lowVal  = 0.1F;

            TrigType = MccDaq.TriggerType.TrigAbove;

            TrigSource = "analog trigger input";
            ushort HighThreshold = 0;
            ushort LowThreshold  = 0;

            if (AIOProps.ATrigRes == 0)
            {
                ULStat = DaqBoard.FromEngUnits(Range, highVal, out HighThreshold);
                ULStat = DaqBoard.FromEngUnits(Range, lowVal, out LowThreshold);
            }
            else
            {
                //Use the value acquired from the AnalogIO module, since the resolution
                //of the input is different from the resolution of the trigger.
                //Calculate trigger based on resolution returned and trigger range.
                VoltageRange = AIOProps.ATrigRange;
                if (AIOProps.ATrigRange == -1)
                {
                    VoltageRange = AIOProps.GetRangeVolts(Range);
                    TrigSource   = "first channel in scan";
                }
                FSCounts      = (int)Math.Pow(2, AIOProps.ATrigRes);
                LSB           = VoltageRange / FSCounts;
                LowThreshold  = (ushort)((lowVal / LSB) + (FSCounts / 2));
                HighThreshold = (ushort)((highVal / LSB) + (FSCounts / 2));
            }

            lblInstruction.Text = "Board " + DaqBoard.BoardNum.ToString() +
                                  " collecting analog data on up to " + NumAIChans.ToString() +
                                  " channels using AInScan with Range set to " + Range.ToString() + ".";

            lblResult.Text = "Waiting for a trigger at " + TrigSource + ". " +
                             "Trigger criterea: signal rising above " + highVal.ToString("0.00") +
                             "V. (Ctl-Break to abort.)";
            Application.DoEvents();

            ULStat = DaqBoard.SetTrigger(TrigType, LowThreshold, HighThreshold);

            if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                //  Collect the values with MccDaq.MccBoard.AInScan()
                //  Parameters:
                //    LowChan    :the first channel of the scan
                //    HighChan   :the last channel of the scan
                //    Count      :the total number of A/D samples to collect
                //    Rate       :sample rate
                //    Range      :the range for the board
                //    MemHandle  :Handle for Windows buffer to store data in
                //    Options    :data collection options

                ValidChan = int.TryParse(txtHighChan.Text, out HighChan);
                if (ValidChan)
                {
                    if ((HighChan > MaxChan))
                    {
                        HighChan = MaxChan;
                    }
                    txtHighChan.Text = HighChan.ToString();
                }

                int Count = NumPoints; //  total number of data points to collect
                // per channel sampling rate ((samples per second) per channel)
                Rate = 1000 / ((HighChan - LowChan) + 1);
                MccDaq.ScanOptions Options = MccDaq.ScanOptions.ConvertData  //  return data as 12-bit values
                                             | MccDaq.ScanOptions.ExtTrigger;

                ULStat         = DaqBoard.AInScan(LowChan, HighChan, Count, ref Rate, Range, MemHandle, Options);
                lblResult.Text = "";

                if (ULStat.Value == ErrorInfo.ErrorCode.Interrupted)
                {
                    lblInstruction.Text = "Scan interrupted while waiting " +
                                          "for trigger on board " + DaqBoard.BoardNum.ToString() +
                                          ". Click Start to try again.";
                    cmdStart.Enabled = true;
                    return;
                }
                else if (!(ULStat.Value == ErrorInfo.ErrorCode.NoErrors))
                {
                    lblInstruction.Text = "Error occurred on board " +
                                          DaqBoard.BoardNum.ToString() +
                                          ": " + ULStat.Message;
                    cmdStart.Enabled = false;
                    return;
                }

                //  Transfer the data from the memory buffer set up by Windows to an array
                if (ADResolution > 16)
                {
                    ULStat = MccDaq.MccService.WinBufToArray32(MemHandle, ADData32, FirstPoint, Count);

                    for (int i = 0; i <= HighChan; ++i)
                    {
                        lblADData[i].Text = ADData32[i].ToString("0");
                    }
                }
                else
                {
                    ULStat = MccDaq.MccService.WinBufToArray(MemHandle, ADData, FirstPoint, Count);

                    for (int i = 0; i <= HighChan; ++i)
                    {
                        lblADData[i].Text = ADData[i].ToString("0");
                    }
                }

                for (int j = HighChan + 1; j <= 7; ++j)
                {
                    lblADData[j].Text = "";
                }
            }
            cmdStart.Enabled = true;
        }