Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Counter between DO and DI on two different channels

Solved!
Go to solution

Hello,

sorry if this question has already been asked, but I cannot find any answer in the forum.

 

I have to program a solution with .Net that have to count the time taken by a measurement on a device.

 

My equipement is : NI cDAQ-9188 with NI 9401 device (and also 9421, 9472, 9205 devices)

 

What I have to do is :

- Send start signal to tell the device he must start de measurment (5V TTL signal)

- Wait for the measurement to finish

- Catch the TTL signal coming from the device (5v TTL signal) telling me the measurement is terminated

- Read the counter to know how many time the measurement took

 

Here is a schema describing the operations :

NI counter task

 

Thank in advance for your help !

 

0 Kudos
Message 1 of 3
(3,460 Views)
Solution
Accepted by topic author Gasser

Hello Gasser,

 

If you install the NI-DAQmx drivers they should come with some examples for .net 4.0.  Go here to download the latest DAQmx drivers if you haven't already.  Once installed, go to Start>>Programs>>National Instruments>>NI-DAQ>>Test Based Support to find documentation and examples in .net and C for our daq cards.

 

Regards,

 

David A.

0 Kudos
Message 2 of 3
(3,447 Views)

Hello David,

thank you for your answer.

 

I solved the problem with the code below :

 

1. Task creation :

// Pulse task
m_nitkPulse = new Task("CO");

double l_dUpDownTime = 0.5 / NbPulsesPerSecond;

m_nitkPulse.COChannels.CreatePulseChannelTime(PulseChannel, "COsPulse", 
  COPulseTimeUnits.Seconds, COPulseIdleState.Low, 0.0, l_dUpDownTime, l_dUpDownTime);

m_nitkPulse.Timing.ConfigureImplicit(SampleQuantityMode.FiniteSamples, NbMeasurements);

m_nitkPulse.SynchronizeCallbacks = true;

m_nitkPulse.Control(TaskAction.Verify);

// Timer task
m_nitkCounter = new Task("CI");

CIChannel l_nicicChannel = m_nitkCounter.CIChannels.CreateTwoEdgeSeparationChannel(
  CounterChannel, "DIsCounter", 1E-6, 1.0, CITwoEdgeSeparationFirstEdge.Rising, 
  CITwoEdgeSeparationSecondEdge.Rising, CITwoEdgeSeparationUnits.Seconds);

m_nitkCounter.Timing.ConfigureImplicit(SampleQuantityMode.FiniteSamples, NbMeasurements);

m_nitkCounter.Stream.ReadAllAvailableSamples = true;
m_nitkCounter.Stream.Timeout = 1500;

m_nitkCounter.Control(TaskAction.Verify);

 

2. Pulse generation and time reading :

// Pulses generation and timing 
m_nitkPulse.Control(TaskAction.Reserve);

m_nitkCounter.Start();

m_nitkPulse.Start();
m_nitkPulse.WaitUntilDone(-1);
    
m_nitkPulse.Stop();

// Timing reading
double[] l_ardTimeValues = m_nicrsCounter.ReadMultiSampleDouble(-1);

m_nitkCounter.Stop();

for(int l_nIndex = 0; l_nIndex < l_ardTimeValues.Length; l_nIndex ++)
  System.Diagnostics.Trace.WriteLine(string.Format("{0} : {1}", 
    l_nIndex, (int) (l_ardTimeValues[l_nIndex] * 1E6)));

// Unreserve the pulse task
m_nitkPulse.Control(TaskAction.Unreserve);

 

 

0 Kudos
Message 3 of 3
(3,432 Views)