Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

period measurement .NET

Hi Kenn
 
  Thanks for the explanation.
 
   I could find that for the counters connected to the Device 2 the available number of samples is always zero. Can you explain the reason for this. But in the EndRead API I'm able to read the data from counters connected to the Device 2.I have copied my code here.
 
 

for (int i = 0; i < _measurementTasks.GetLength(0); i++)

{

//available number of samples for ctr3 and ctr4 connected to Dev2 is always 0

_availableSamples = (

int)_measurementTasks[i].Stream.AvailableSamplesPerChannel;

_availableSamples =

Math.Min(_numOfSamples, _availableSamples); //numOfSample is 14500

_dataReader[i].BeginReadMultiSampleInt32(_availableSamples,_myCallBack,

null);

if (i != _measurementTasks.GetLength(0) - 1)

_bTaskRunning =

false;

else

_bTaskRunning =

true;

Thread.Sleep(1);

}

But in the EndRead API it reads the data for Ctr3 and Ctr 4 of device 2

private void CounterReadCallback(IAsyncResult ar)

{

try

{

lock

(_measurementTasks.SyncRoot)

{

   if (_bTaskRunning)

  {

         string strErrMsg = string.Empty;

        for (int k = 0; k < _measurementTasks.GetLength(0); k++)

         {

            int[] data;// = new int[_availableSamples];

           lock (_dataReader[k])

          {//Here while calling this API I get the data for Ctr3 and Ctr4 connected to Device 2

                data = _dataReader[k].EndReadMultiSampleInt32(ar);

           }

       

      }

 

}

if (!_bStop)

{

_acqStartWriteThreadEvent.Set();

}

}

 

  Because of this I'm concerned about the data I get from the Ctr4 and Ctr 5 .

 Please respond quickly. I have only one day to get this working.

Thank you

Murugan

0 Kudos
Message 51 of 53
(964 Views)

Hi Kenn

 I have also checked all my connections.

1) 5 counters are array of 5 tasks.

2) Dev1/Ctr0 is the source . Dev1/Ctr6 is the gate.

3) Period measurement is created for Dev1/Ctr0,Dev1/Ctr1,Dev1/Ctr2  and Dev2/Ctr3,Dev2/Ctr4

4) For all the counters the same source is used (signal generator ) so the counterTimebaseSource for all the task is

CounterTimebaseSource = "/Dev1/PFI39"; (Dev1/Ctr0 source)

PeriodTerminal = "/Dev1/PFI12"; (gate output of Dev1/Ctr6 )

5) ArmsStartTrigger for the first 3 counters

ConfigureDigitalEdgeTrigger("/Dev1/PFI0", DigitalEdgeArmStartTriggerEdge.Rising)

 and for the last 2 counters

ConfigureDigitalEdgeTrigger("/Dev2/PFI0", DigitalEdgeArmStartTriggerEdge.Rising)

I have also tried using the same Device

6) Digital trigger is set using

_firstTask.DOChannels.CreateChannel(

"/Dev1/port0/line0", "DigitalTrigger",ChannelLineGrouping.OneChannelForAllLines);

_firstTask.Control(

TaskAction.Verify);

int numLines = (int)_firstTask.DOChannels["DigitalTrigger"].NumberOfLines;

bool[] dataArray = new bool[numLines];

DigitalSingleChannelWriter writer = new DigitalSingleChannelWriter(_firstTask.Stream);

dataArray[0] =

true;

writer.WriteSingleSampleMultiLine(

true, dataArray);

dataArray[0] =

false;

writer.WriteSingleSampleMultiLine(

true, dataArray);

 But the available samples per channel for the counter in the device 2 is always zero.

 I'm missing something?

Thanks

Murugan

 

0 Kudos
Message 52 of 53
(961 Views)
Murugan,

There is a lot going on here.  In situations like these you need to simplify and then add complexity bit by bit.  It's obviously a bit more time consuming, but in this case I think it need to happen.  Start by verifying that you can get anything to work with Dev2, then get Dev2 to run your tasks by itself.  Verify that tinkgs like the trigger are actually triggering each device seperately and together.  Be sure to specify the source for each device as an external source and not the internal timebase.  You could also try to run the boards more independently to see that things are working correctly.  Hope this helps.  I don't have a quick solution for this one. 

Regards,
Kenn North
Principal Product Manager - Search, Digital Analytics
http://ni.com/search
0 Kudos
Message 53 of 53
(955 Views)