Пример #1
0
        public double ReadDigitalPulseWidth(string counter, CIPulseWidthStartingEdge StartingEdge, double minPW_InSeconds, double maxPW_InSeconds)
        {
            // This example uses the default source (or gate) terminal for
            // the counter of your device.  To determine what the default
            // counter pins for your device are or to set a different source
            // (or gate) pin, refer to the Connecting Counter Signals topic
            // in the NI-DAQmx Help (search for "Connecting Counter Signals").
            // Uses default PFI 9/P2.1 as the pulse input.
            // Returns PW in seconds.

            double pulseWidth = 0;
            Task   myTask     = null;

            NationalInstruments.DAQmx.CounterReader myCounterReader;

            try
            {
                myTask = new Task();
                myTask.CIChannels.CreatePulseWidthChannel(counter,
                                                          "Meas Pulse Width", minPW_InSeconds,
                                                          maxPW_InSeconds, StartingEdge,
                                                          CIPulseWidthUnits.Seconds);
                //RLC Wait up to 5 sec default was 10 sec
                myTask.Stream.Timeout = 5000;
                myCounterReader       = new CounterReader(myTask.Stream);

                // For .NET Framework 2.0 or later, use SynchronizeCallbacks to specify that the object
                // marshals callbacks across threads appropriately.
                myCounterReader.SynchronizeCallbacks = true;
                // For .NET Framework 1.1, set SynchronizingObject to the Windows Form to specify
                // that the object marshals callbacks across threads appropriately.
                //myCounterReader.SynchronizingObject = this;


                //rlc AsyncCallback myCallback = new AsyncCallback(MeasurementCallback);
                //myCounterReader.BeginReadSingleSampleDouble(myCallback, null);
                IAsyncResult ar = null;
                ar = myCounterReader.BeginReadSingleSampleDouble(null, null);

                pulseWidth = myCounterReader.EndReadSingleSampleDouble(ar);
            }
            catch (Exception exception)
            {
                mstr_Error = exception.Message;
                pulseWidth = -1;
            }
            finally
            {
                if (myTask != null)
                {
                    myTask.Dispose();
                }
            }

            return(pulseWidth);
        }
Пример #2
0
        public bool ReadDigitalLowFrequency(string lines, string name, double min, double max, double time)
        {
            // This example uses the default source (or gate) terminal for
            // the counter of your device.  To determine what the default
            // counter pins for your device are or to set a different source
            // (or gate) pin, refer to the Connecting Counter Signals topic
            // in the NI-DAQmx Help (search for "Connecting Counter Signals").
            // Uses default PFI 9/P2.1 as the pulse input.
            try
            {
                m_d_MeasuredFrequency = 0;

                Task_MeasureLowFreq = new Task();

                Task_MeasureLowFreq.CIChannels.CreateFrequencyChannel(lines, name, min, max, CIFrequencyStartingEdge.Rising,
                                                                      CIFrequencyMeasurementMethod.LowFrequencyOneCounter, time, 4, CIFrequencyUnits.Hertz);

                myCounterReader = new CounterReader(Task_MeasureLowFreq.Stream);

                // For .NET Framework 2.0 or later, use SynchronizeCallbacks to specify that the object
                // marshals callbacks across threads appropriately.
                myCounterReader.SynchronizeCallbacks = true;

                myCallBack = new AsyncCallback(CounterInCallback);
                myCounterReader.BeginReadSingleSampleDouble(myCallBack, null);
            }
            catch (Exception exception)
            {
                mstr_Error = exception.Message;
                Task_MeasureLowFreq.Dispose();

                return(false);
            }

            return(true);
        }