Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use COChannel Count property in DAQmx .NET to get the total number of pulses in a continuous pulse train?

Hi,

 

I'm studying the GenDigPulseTrain_Continuous example from the NI DOTNET3.5 examples.  I'm trying to use the COChannel Count property to get the total number of pulses generated.

 

A code snippet from the example with minor modifications for my hardware is shown below:

try
            {
                myTask = new Task();
                _startCount = 0;
                myTask.COChannels.CreatePulseChannelFrequency(counterComboBox.Text, 
                    "ContinuousPulseTrain", COPulseFrequencyUnits.Hertz, idleState, 0.0, 
                    Convert.ToDouble(frequencyTextBox.Text), 
                    Convert.ToDouble(dutyCycleTextBox.Text));
                
               COChannel d = myTask.COChannels[0];
               d.PulseTerminal = "/DAQ/PFI4";  //added this for my hardware wiring
               
                myTask.Timing.ConfigureImplicit(SampleQuantityMode.ContinuousSamples, 1000);
                                                
                myTask.Start();
                _startCount = myTask.COChannels[0].Count;

                startButton.Enabled = false;
                stopButton.Enabled = true;
                statusCheckTimer.Enabled = true;
            }

I'm setting myTask.COChannels[0].Count to _startCount, but the value does not seem to correspond to the actual number of pulses.  It produces a huge number.  The NI DAQmx help files regarding the class just says the Count "Indicates the current value of the count register". 

 

How can I use the Count property to return the total number of pulses generated once the user hits the Stop button? 

-Chuck

0 Kudos
Message 1 of 3
(5,452 Views)

Unfortunately, the short answer is, "you can't."   As you've seen, the count register is busy managing the pulse timing

characteristics and isn't available to count the # of pulses generated.  The best alternative is to program a 2nd counter

to count the pulses generated by the 1st.

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 2 of 3
(5,445 Views)

Interesting.  I wonder why DAQmx exposes the Count property of the counter if one cannot use it to check the count?  I was expecting there to be some type of tick conversion to make the value returned useful.

-Chuck

0 Kudos
Message 3 of 3
(5,437 Views)