Ejemplo n.º 1
0
        private void frmDataDisplay_Load(object sender, EventArgs e)
        {
            MccDaq.TriggerType DefaultTrig;

            InitUL();

            // determine the number of analog channels and their capabilities
            int ChannelType = clsAnalogIO.ANALOGINPUT;

            NumAIChans = AIOProps.FindAnalogChansOfType(DaqBoard, ChannelType,
                                                        out ADResolution, out Range, out LowChan, out DefaultTrig);

            if (NumAIChans == 0)
            {
                lblInstruction.Text = "Board " + DaqBoard.BoardNum.ToString() +
                                      " does not have analog input channels.";
                cmdStartConvert.Enabled = false;
                txtHighChan.Enabled     = false;
            }
            else if (ADResolution > 12)
            {
                lblInstruction.Text = "Board " + DaqBoard.BoardNum.ToString() +
                                      " resolution is greater than 12-bits. This sample applies " +
                                      "only to 12-bit devices that contain composite data.";
                cmdStartConvert.Enabled = false;
                txtHighChan.Enabled     = false;
            }
            else
            {
                // set aside memory to hold 16-bit data
                ADData    = new ushort[NumPoints];
                ConvData  = new ushort[NumPoints];
                MemHandle = MccDaq.MccService.WinBufAllocEx(NumPoints);
                if (MemHandle == IntPtr.Zero)
                {
                    cmdStartConvert.Enabled = false;
                    NumAIChans = 0;
                }
                if (NumAIChans > 5)
                {
                    NumAIChans = 5;
                }
                MaxChan             = LowChan + NumAIChans - 1;
                lblInstruction.Text = "Board " + DaqBoard.BoardNum.ToString() +
                                      " collecting analog data on up to " + NumAIChans.ToString() +
                                      " channels using AInScan with Range set to " + Range.ToString() +
                                      ". For devices that store composite data, this sample separates " +
                                      "channel tags from data manually. Most new designs do not support this.";
            }
        }
Ejemplo n.º 2
0
        private void frmStatusDisplay_Load(object sender, EventArgs e)
        {
            MccDaq.TriggerType DefaultTrig;

            InitUL();

            // determine the number of analog channels and their capabilities
            int ChannelType = clsAnalogIO.ANALOGINPUT;

            NumAIChans = AIOProps.FindAnalogChansOfType(DaqBoard, ChannelType,
                                                        out ADResolution, out Range, out LowChan, out DefaultTrig);

            if (NumAIChans == 0)
            {
                lblInstruction.Text = "Board " + DaqBoard.BoardNum.ToString() +
                                      " does not have analog input channels.";
                cmdStartBgnd.Enabled = false;
                txtHighChan.Enabled  = false;
            }
            else
            {
                // Check the resolution of the A/D data and allocate memory accordingly
                if (ADResolution > 16)
                {
                    // set aside memory to hold high resolution data
                    ADData32  = new uint[NumPoints];
                    MemHandle = MccDaq.MccService.WinBufAlloc32Ex(NumPoints);
                }
                else
                {
                    // set aside memory to hold 16-bit data
                    ADData    = new ushort[NumPoints];
                    MemHandle = MccDaq.MccService.WinBufAllocEx(NumPoints);
                }
                if (MemHandle == IntPtr.Zero)
                {
                    cmdStartBgnd.Enabled = false;
                    NumAIChans           = 0;
                }
                if (NumAIChans > 8)
                {
                    NumAIChans = 8;
                }
                MaxChan             = LowChan + NumAIChans - 1;
                lblInstruction.Text = "Board " + DaqBoard.BoardNum.ToString() +
                                      " collecting analog data on up to " + NumAIChans.ToString() +
                                      " channels using AInScan with Range set to " + Range.ToString() + ".";
            }
        }
Ejemplo n.º 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;
        }