示例#1
0
        private void cmdStartBgnd_Click(object eventSender, System.EventArgs eventArgs)
        {
            int   CurIndex;
            int   CurCount;
            short Status;

            MccDaq.ErrorInfo   ULStat;
            MccDaq.ScanOptions Options;
            int  Rate;
            int  Count;
            bool ValidChan;

            cmdStartBgnd.Enabled   = false;
            cmdStartBgnd.Visible   = false;
            cmdStopConvert.Enabled = true;
            cmdStopConvert.Visible = true;
            cmdQuit.Enabled        = false;

            //  Collect the values by calling 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();
            }

            Count = NumPoints;     //  total number of data points to collect

            //  per channel sampling rate ((samples per second) per channel)
            Rate    = 1000 / ((HighChan - LowChan) + 1);
            Options = MccDaq.ScanOptions.Background
                      | MccDaq.ScanOptions.Continuous;

            //  collect data in background continuously
            ULStat = DaqBoard.AInScan(LowChan, HighChan, Count, ref Rate, Range, MemHandle, Options);

            ULStat = DaqBoard.GetStatus(out Status, out CurCount, out CurIndex, MccDaq.FunctionType.AiFunction);

            if (Status == MccDaq.MccBoard.Running)
            {
                lblShowStat.Text  = "Running";
                lblShowCount.Text = CurCount.ToString("D");
                lblShowIndex.Text = CurIndex.ToString("D");
            }

            tmrCheckStatus.Enabled = true;
        }
示例#2
0
        private void tmrConvert_Tick(object eventSender, System.EventArgs eventArgs)         /* Handles tmrConvert.Tick */
        {
            tmrConvert.Stop();

            //  Collect the values by calling MccDaq.MccBoard.AInScan function
            //  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  = 100;                                     //  sampling rate is ignored

            MccDaq.Range       Range   = MccDaq.Range.Bip5Volts; // set the range
            MccDaq.ScanOptions Options = MccDaq.ScanOptions.ConvertData
                                         | MccDaq.ScanOptions.ExtClock;
            MccDaq.ErrorInfo ULStat = DaqBoard.AInScan(LowChan, HighChan, Count, ref Rate, Range, MemHandle, Options);


            //  Transfer the data from the memory buffer set up by Windows to an array

            if (HighResAD)
            {
                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 = ("");
            }

            tmrConvert.Start();
        }
示例#3
0
        private void tmrConvert_Tick(object eventSender, System.EventArgs eventArgs)         /* Handles tmrConvert.Tick */
        {
            tmrConvert.Stop();

            //  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 (determined by
            //                  Set Mode option buttons in this program)
            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  = 290;                                  //  per channel sampling rate ((samples per second) per channel)

            MccDaq.Range     Range  = MccDaq.Range.Bip5Volts; // set the range
            MccDaq.ErrorInfo ULStat = DaqBoard.AInScan(LowChan, HighChan, Count, ref Rate, Range, MemHandle, Options);

            if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.FreeRunning)
            {                   // Turn off library error handling for subsequent calls
                ULStat = MccDaq.MccService.ErrHandling(MccDaq.ErrorReporting.DontPrint, MccDaq.ErrorHandling.StopAll);
            }

            //  Transfer the data from the memory buffer set up by Windows to an array
            if (HighResAD)
            {
                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");
                }
            }

            tmrConvert.Start();
        }
示例#4
0
        public double[] ReadDyno()
        {
            //establish all the varables for the data
            double[] reading = new double[7];
            double   XForce, YForce, ZForceDyno, TForce, VAngle, XYForce, XYForceAverage;

            //sampleing from all 8 channels, DAQ has a max sampling rate of 10,000Hz so for sampleing 8 channels the rate=10,000/8=1,250
            int LowChan = 0, HighChan = 7, Rate = 1250, Count = 8;//JNEW

            //IntPtr MemHandle = IntPtr.Zero;//JNEW //dont think this is needed here
            int NumPoints  = 8;                                                  //  Number of data points to collect //JNEW
            int FirstPoint = 0;                                                  //  set first element in buffer to transfer to array //JNEW

            short[] ADData = new short[NumPoints];                               //JNEW

            IntPtr MemHandle = MccDaq.MccService.ScaledWinBufAllocEx(NumPoints); //JNEW

            //  return scaled data (dont know exactly what this means)
            Options = MccDaq.ScanOptions.ConvertData | MccDaq.ScanOptions.SingleIo;

            //Options = MccDaq.ScanOptions.ScaleData;
            //Range = MccDaq.Range.Bip5Volts; // set the range
            //Range = MccDaq.Range.Bip10Volts; // set the range

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

            if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.BadRange)
            {
                Console.WriteLine("Change the Range argument to one supported by this board.");
            }
            //  Transfer the data from the memory buffer set up by Windows to an array
            ULStat = MccDaq.MccService.WinBufToArray(MemHandle, ADData, FirstPoint, Count);

            //calibration variables (probably from kistler)
            //Copy into local variables
            XForce         = 487.33 * Count2Volt(ADData[0]);
            YForce         = 479.85 * Count2Volt(ADData[1]);
            ZForceDyno     = 2032.52 * Count2Volt(ADData[2]);
            TForce         = 18.91 * Count2Volt(ADData[3]);
            VAngle         = Count2Volt(ADData[7]);
            XYForce        = Math.Sqrt(XForce * XForce + YForce * YForce);
            XYForceAverage = averager.calculateAverage(XYForce);

            reading[0] = XForce;
            reading[1] = YForce;
            reading[2] = ZForceDyno;
            reading[3] = TForce;
            reading[4] = VAngle;
            reading[5] = XYForce;
            reading[6] = XYForceAverage;

            return(reading);
        }
示例#5
0
        private void cmdStart_Click(object sender, System.EventArgs e)
        {
            //Start input scan with  MccBoard.AInScan
            int rate = DesiredRate;

            MccDaq.ErrorInfo ULStat = DaqBoard.AInScan(0, 0,
                                                       TotalCount, ref rate, Range, MemHandle, Options);
            if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                cmdStart.Enabled = false;
                lblStatus.Text   = "RUNNING";
            }
        }
示例#6
0
        private void cmdStartConvert_Click(object eventSender, System.EventArgs eventArgs)
        {
            MccDaq.ErrorInfo   ULStat;
            MccDaq.ScanOptions Options;
            int  Rate;
            int  Count;
            bool ValidChan;

            cmdStartConvert.Enabled   = false;
            cmdQuit.Enabled           = false;
            cmdStopBackground.Enabled = true;

            // Collect the values by calling MccDaq.MccBoard.AInScan function in background mode
            //   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 in samples per second
            //      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();
            }
            else
            {
                HighChan = 0;
            }

            Count = NumPoints;                                          //  total number of data points to collect

            //  per channel sampling rate ((samples per second) per channel)
            Rate    = 1000 / ((HighChan - LowChan) + 1);
            Options = MccDaq.ScanOptions.Background;    //  collect data in BACKGROUND mode
                                                        // as 16-bit values (no conversion)

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

            // during the background operation, check the status using a timer, then print the values
            tmrCheckStatus.Enabled = true;
        }
示例#7
0
        private void cmdStartAcq_Click(object eventSender, System.EventArgs eventArgs)         /* Handles cmdStartAcq.Click */
        {
            MccDaq.ErrorInfo   ULStat;
            MccDaq.Range       Range;
            MccDaq.ScanOptions Options;
            int   Rate;
            int   Count;
            int   LowChan;
            short i;

            foreach (Label l in lblShowTag)
            {
                l.Text = "";
            }


            //  Collect the values by calling MccDaq.MccBoard.AInScan function
            //   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
            LowChan  = 0;                           //  first channel to acquire
            HighChan = int.Parse(txtHighChan.Text); //  last channel to acquire
            if (HighChan > 7)
            {
                HighChan = 7;
            }
            txtHighChan.Text = HighChan.ToString();

            Count   = NumPoints;                     //  total number of data points to collect
            Rate    = 390;                           //  per channel sampling rate ((samples per second) per channel)
            Options = MccDaq.ScanOptions.Background; //  collect data in background mode
            //  as 16-bit values (no conversion)
            Range = MccDaq.Range.Bip5Volts;          //  set the range

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


            tmrCheckStatus.Enabled = true;
        }
示例#8
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;
        }
示例#9
0
        private void cmdStart_Click(object eventSender, System.EventArgs eventArgs)
        {
            int j;
            int i;

            MccDaq.ErrorInfo   ULStat;
            MccDaq.Range       Range;
            MccDaq.ScanOptions Options;
            int Rate;
            int Count;
            int LowChan;

            cmdStart.Enabled = false;

            //  Collect the values by calling MccDaq.MccBoard.AInScan function
            //  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
            LowChan  = 0;                           //  first channel to acquire
            HighChan = int.Parse(txtHighChan.Text); //  last channel to acquire
            if ((HighChan > 7))
            {
                HighChan = 7;
            }
            txtHighChan.Text = HighChan.ToString();

            Count = NumPoints;  //  total number of data points to collect
            Rate  = 390;        //  per channel sampling rate ((samples per second) per channel)

            //  return scaled data
            Options = MccDaq.ScanOptions.ScaleData;
            Range   = MccDaq.Range.Bip5Volts; // set the range


            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.ScaledWinBufToArray(MemHandle, ADData, FirstPoint, Count);


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

            for (j = HighChan + 1; j <= 7; ++j)
            {
                lblADData[j].Text = "0";
            }

            cmdStart.Enabled = true;
        }
示例#10
0
        private void cmdStart_Click(object eventSender, System.EventArgs eventArgs)
        {
            int j;
            int i;

            MccDaq.ErrorInfo   ULStat;
            MccDaq.ScanOptions Options;
            int  Rate;
            int  Count;
            bool ValidChan;

            cmdStart.Enabled = false;

            //  Collect the values by calling MccDaq.MccBoard.AInScan function
            //  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();
            }
            else
            {
                HighChan = 0;
            }

            Count = NumPoints;  //  total number of data points to collect

            //  per channel sampling rate ((samples per second) per channel)
            Rate = 1000 / ((HighChan - LowChan) + 1);

            //  return data as 12-bit values (ignored for 16-bit boards)
            Options = MccDaq.ScanOptions.ConvertData;

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

            //  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 (i = 0; i <= HighChan; ++i)
                {
                    lblADData[i].Text = ADData32[i].ToString("D");
                }
            }
            else
            {
                ULStat = MccDaq.MccService.WinBufToArray(MemHandle, ADData, FirstPoint, Count);

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

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

            cmdStart.Enabled = true;
        }
示例#11
0
        private void cmdStart_Click(object eventSender, System.EventArgs eventArgs)
        {
            int i;

            MccDaq.ErrorInfo   ULStat;
            MccDaq.Range       Range;
            MccDaq.ScanOptions Options;
            int Rate;
            int Count;
            int Chan;

            StrainConfig StrainConfiguration = StrainConfig.QuarterBridgeI;

            double InitialVoltage         = 0.0; //Bridge output voltage in the unloaded condition. This value is subtracted from any measurements before scaling equations are applied.
            double VInitial               = 0.0;
            double OffsetAdjustmentFactor = 0.0;
            double GainAdjustmentFactor   = 0.0;
            double Total        = 0.0;
            double VOffset      = 0.0;
            double RShunt       = 100000;               // Resistance of Shunt Resistor
            double RGage        = 350;                  // Gage Resistance
            double VExcitation  = 2.5;                  // Excitation voltage
            double GageFactor   = 2;
            double PoissonRatio = 0;
            double VActualBridge;                       // Actual bridge voltage
            double REffective;                          // Effective resistance
            double VSimulatedBridge;                    // Simulated bridge voltage
            double MeasuredStrain;
            double SimulatedStrain;

            cmdStart.Enabled = false;

            // Calculate the offset adjusment factor on a resting gage in software

            //  Collect the values by calling MccDaq.MccBoard.AInScan function
            //  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

            Chan = int.Parse(txtChan.Text); // channel to acquire
            if ((Chan > 3))
            {
                Chan = 3;
            }
            txtChan.Text = Chan.ToString();

            VInitial = InitialVoltage / VExcitation;

            Count = NumPoints;  //  total number of data points to collect
            Rate  = 1000;       //  per channel sampling rate ((samples per second) per channel)

            //  return scaled data
            Options = MccDaq.ScanOptions.ScaleData;
            Range   = MccDaq.Range.NotUsed;   // set the range

            ULStat = DaqBoard.AInScan(Chan, Chan, Count, ref Rate, Range, MemHandle, Options);

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

            for (i = 0; i < NumPoints; i++)
            {
                Total = Total + ADData [i];
            }

            VOffset = Total / Count;

            VOffset = VOffset - VInitial;

            OffsetAdjustmentFactor = CalculateStrain(StrainConfiguration, VOffset, GageFactor, PoissonRatio);

            lblOffsetMeasStrain.Text = OffsetAdjustmentFactor.ToString("F9");

            //	Enable Shunt Calibration Circuit and Collect the values and
            //  Calculate the Actual Bridge Voltage

            Options = MccDaq.ScanOptions.ScaleData | MccDaq.ScanOptions.ShuntCal;
            ULStat  = DaqBoard.AInScan(Chan, Chan, Count, ref Rate, Range, MemHandle, Options);

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

            Total = 0.0;

            for (i = 0; i < Count; i++)
            {
                Total = Total + ADData [i];
            }

            VActualBridge = Total / Count;

            VActualBridge = VActualBridge - VInitial;

            MeasuredStrain = CalculateStrain(StrainConfiguration, VActualBridge, GageFactor, PoissonRatio);

            lblGainMeasStrain.Text = MeasuredStrain.ToString("F9");

            // Calculate the Simulated Bridge Strain with a shunt resistor

            REffective = (RGage * RShunt) / (RGage + RShunt);

            VSimulatedBridge = (REffective / (REffective + RGage) - 0.5);

            SimulatedStrain = CalculateStrain(StrainConfiguration, VSimulatedBridge, GageFactor, PoissonRatio);

            lblGainSimStrain.Text = SimulatedStrain.ToString("F9");

            GainAdjustmentFactor = SimulatedStrain / (MeasuredStrain - OffsetAdjustmentFactor);

            lblGainAdjustmentFactor.Text = GainAdjustmentFactor.ToString("F9");

            cmdStart.Enabled = true;
        }
示例#12
0
        static void Main(string[] args)
        {
            System.ConsoleKeyInfo cki = new System.ConsoleKeyInfo();
            MccDaq.ErrorInfo      RetVal;

            int  BoardNum       = 0;
            int  DeviceChannels = 0;
            int  Rate           = FREQ;
            bool ReadLower      = true;

            BoardNum = GetBoardNum(DEVICE);

            if (BoardNum == -1)
            {
                Console.WriteLine("No USB-{0} detected!", DEVICE);
                cki = Console.ReadKey();
            }
            else
            {
                MccBoard daq = new MccDaq.MccBoard(BoardNum);

                daq.BoardConfig.GetNumAdChans(out DeviceChannels);

                if (DeviceChannels > 8)
                {
                    Console.WriteLine("Single-Ended Channels");
                }
                else
                {
                    Console.WriteLine("Differentially-Ended Channels");
                }


                IntPtr buffer = MccService.ScaledWinBufAllocEx(BUFFERSIZE);

                if (buffer == IntPtr.Zero)
                {
                    Console.WriteLine("Bad Handle");
                    return;
                }

                short[] chArray = new short[CHANCOUNT]; //configuration array for channel numbers
                Range[] chRange = new Range[CHANCOUNT]; //configuration array for input ranges

                chArray[0] = 0;
                chArray[1] = 1;
                chArray[2] = 2;
                chArray[3] = 3;

                chRange[0] = Range.Bip10Volts;
                chRange[1] = Range.Bip10Volts;
                chRange[2] = Range.Bip10Volts;
                chRange[3] = Range.Bip10Volts;

                RetVal = daq.ALoadQueue(chArray, chRange, CHANCOUNT);
                IsError(RetVal);

                //setup the acquisiton
                RetVal = daq.AInScan(FIRSTCHANNEL,
                                     LASTCHANNEL,
                                     BUFFERSIZE,
                                     ref Rate,
                                     Range.Bip10Volts,
                                     buffer,
                                     ScanOptions.Background | ScanOptions.ScaleData | ScanOptions.Continuous
                                     );
                IsError(RetVal);

                fStream = new StreamWriter(@"C:\Users\Public\Documents\DataFile1608G.asc");
                CreateFileHeaders(chArray); //writes basic info to the beginning of the file

                int   Count = 0;
                int   Index = 0;
                short daqStatus;

                double[] theArray = new double[BUFFERSIZE];



                //Loop until key press
                do
                {
                    RetVal = daq.GetStatus(out daqStatus, out Count, out Index, FunctionType.AiFunction);
                    if ((Index >= HALFBUFFSIZE) & ReadLower) //check for 50% more data
                    {
                        //get lower half of buffer - ScaledWinBufToArray returns engineering units
                        RetVal = MccService.ScaledWinBufToArray(buffer, theArray, 0, HALFBUFFSIZE);
                        IsError(RetVal);

                        DisplayData(theArray, HALFBUFFSIZE / CHANCOUNT);
                        ReadLower = false; //flag that controls the next read
                    }
                    else if ((Index < HALFBUFFSIZE) & !ReadLower)
                    {
                        //get the upper half  - ScaledWinBufToArray returns engineering units
                        RetVal = MccService.ScaledWinBufToArray(buffer, theArray, HALFBUFFSIZE, HALFBUFFSIZE);
                        IsError(RetVal);

                        DisplayData(theArray, HALFBUFFSIZE / CHANCOUNT);
                        ReadLower = true;//flag that controls the next read
                    }
                } while (!Console.KeyAvailable);

                cki = Console.ReadKey();

                //flush any buffered data out to disk
                fStream.Close();

                //stop the  acquisition
                RetVal = daq.StopBackground(FunctionType.AiFunction);

                //free up memory
                MccService.WinBufFreeEx(buffer);

                WaitForKey();
            }
        }
示例#13
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;
        }
示例#14
0
        private void cmdStartBgnd_Click(object eventSender, System.EventArgs eventArgs) /* Handles cmdStartBgnd.Click */
        {
            int   CurIndex;
            int   CurCount;
            short Status;

            MccDaq.ErrorInfo   ULStat;
            MccDaq.Range       Range;
            MccDaq.ScanOptions Options;
            int Rate;
            int Count;
            int LowChan;

            cmdStartBgnd.Enabled   = false;
            cmdStartBgnd.Visible   = false;
            cmdStopConvert.Enabled = true;
            cmdStopConvert.Visible = true;
            cmdQuit.Enabled        = false;
            UserTerm = 0; //  initialize user terminate flag

            //  Collect the values by calling MccDaq.MccBoard.AInScan function
            //   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
            LowChan  = 0;                           //  first channel to acquire
            HighChan = int.Parse(txtHighChan.Text); //  last channel to acquire
            if ((HighChan > 7))
            {
                HighChan = 7;
            }
            txtHighChan.Text = HighChan.ToString();

            Count = NumPoints; //  total number of data points to collect
            Rate  = 390;       //  per channel sampling rate ((samples per second) per channel)

            Options = MccDaq.ScanOptions.ConvertData | MccDaq.ScanOptions.Background | MccDaq.ScanOptions.SingleIo;

            Range = MccDaq.Range.Bip5Volts; //  set the range


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



            ULStat = DaqBoard.GetStatus(out Status, out CurCount, out CurIndex, MccDaq.FunctionType.AiFunction);



            if (Status == MccDaq.MccBoard.Running)
            {
                lblShowStat.Text  = "Running";
                lblShowCount.Text = CurCount.ToString("D");
                lblShowIndex.Text = CurIndex.ToString("D");
            }

            tmrCheckStatus.Enabled = true;
        }