Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx C# Photon Counter with External Reference Clock

Hello NI-Community,

I am currently trying to count the pulses of a single photon counter module (SPCM) in a C# program with an external 100kHz clock using the NationalInstrument.DAQmx library. As the output, I want the detected counts from the SPCM in X per 10ms Therefore, I want to acquire 1000 samples at 100kHz and add up the counted pulses. The programming task should be quite similar to the LabView example Counter Count Edges (Finite Clock).vi in the example section of LabView Block Diagramm.

I have the photon counter signal on the CTR0/PFI12 connector and the external sample clock at 100kHz on the AI START TRIG/PFI0 connector of a BNC-2110 Board.
( see https://www.ni.com/pdf/manuals/372121f.pdf)

Afterwards, the signal is going to a NI-DAQmx PCI-6229 card in the PC.

( see https://www.ni.com/pdf/manuals/375204c.pdf)


The following code is influenced and therefore somehow comparable to the example from National Instruments\NI-DAQ\Examples\DotNET4.5\Counter\Count Digital Events\CountDigEventsBuffContinuous_ExtClk\CS.

I first initialze my NI-DAQmx the folllowing way:


------Code ------

// initalize NI-DAQmx

const int clockCycles = 1000;
const double frequency = 100000;

Task counterReadTask = new Task("CtrEdgesTask");

// init. counterTask and configure external clock input

CIChannel ChannelCounter = counterReadTask.CIChannels.CreateCountEdgesChannel("/Dev2/ctr0", "myCIChannel", CICountEdgesActiveEdge.Rising, 0, CICountEdgesCountDirection.Up);

 

ChannelCounter.CountEdgesTerminal = "/Dev2/PFI12";

 

counterReadTask.Timing.ConfigureSampleClock("/Dev2/PFI0", frequency, SampleClockActiveEdge.Rising, SampleQuantityMode

 

counterReadTask.Stream.Timeout = 5000;

counterReadTask.Control(TaskAction.Verify);

-----------------

 

Later I want to use my counter to read in the data. I don't have callbacks, so I just want to use the "normal" MemoryOptimizedReadMultiSampleInt32-Function.

------Code ------

// define buffer of counts 

var data = new int[clockCycles];
int totalcounts = 0;
int readOutSamples = 0;

 

// start data aquisition
try
{   

counterReadTask.Start();

var myCounterReader = new                   CounterSingleChannelReader(counterReadTask.Stream);
myCounterReader.MemoryOptimizedReadMultiSampleInt32(clockCycles, ref data, out readOutSamples);

}
catch (DaqException _read_ex)
{
Console.WriteLine("Failed to read spcm data: " + _read_ex.Message);
Console.WriteLine("Press any key to end programm");
Console.ReadKey();
return;
}
finally
{
counterReadTask.Stop();
}

for (int i = 0; i < data.Length; i++)
{
totalcounts = data[i] + totalcounts;

}


Console.WriteLine("{0}", totalcounts);


}
//later don't forget

counterReadTask.Dispose();

-----------------

The programm compiles fine, but when I try to read the counts I get the following error:

"Failed to read spcm data: Some or all of the samples requested have not yet been acquired.


To wait for the samples to become available use a longer read timeout or read later in your program. To make the samples available sooner, increase the sample rate. If your task uses a start trigger, make sure that your start trigger is configured correctly. It is also possible that you configured the task for external timing, and no clock was supplied. If this is the case, supply an external clock.

 

Property: NationalInstruments.DAQmx.DaqStream.ReadRelativeTo
Corresponding Value: NationalInstruments.DAQmx.ReadRelativeTo.CurrentReadPosition
Property: NationalInstruments.DAQmx.DaqStream.ReadOffset
Corresponding Value: 0

Task Name: CtrEdgesTask

Status Code: -200284


Press any key to end programm"


It seems like, that the counter doesn't get the trigger signal. My question is, do I have to arm or configure the trigger more? Or do I miss some needed function or so?

I would be very happy, if someone has an idea about what went wrong.

Cheers
LucBer
 

0 Kudos
Message 1 of 1
(286 Views)