Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Configure a buffered counter in python

Hi, 

I'm trying to build an application in python that's very simple. The only thing he has to do is start counting the rising edges on a digital input channel. In the attached python script the counting works, but not in the way I want.

The counting of the edges should be independent of what the python script is doing. In the manual I read something about the buffered edge counting, but I don't understand how to build that.

 

I'm using the python PyDAQmx library

 

 

so please give me a hint how to do it.

Thanks in advance,

R de Vries

 

0 Kudos
Message 1 of 6
(5,541 Views)

Hi,

 

Where can I find the manual (PyDAQmx manual) about buffered edge counting?

What's the behavious you have using the code provided?

What hardware are you using?

 

Dieter

0 Kudos
Message 2 of 6
(5,502 Views)

Thanks for your reaction.

I'm using the NI cDAQ 9178 chassis with module NI 9421

 

PyDAQmx manual can be found at http://pythonhosted.org/PyDAQmx/

 

The code did count, but only when the function ReadCounterScalarU32 was active. I expected that the counting was independend of the execution of the python code. So that it was also counting during the sleep.

In the screendump was an error. I'm using the following code: 

Counter.CreateCICountEdgesChan("cDAQ1Mod1/ctr0", ""    , DAQmx_Val_Rising, 5,                   DAQmx_Val_CountUp)

THanks,

Rob

0 Kudos
Message 3 of 6
(5,489 Views)

Hi,

 

Counter should be independent of the code. The ReadCounterScalarU32 function reads out the current value of the counter. Counters have a gate, so you might be 'gating' the counter, when running the sleep, maybe the gate is not 1 and the counter is paused as well.

 

If I get to it, I'll compare with the example of a digital counter in C (which is the basis of the PyDAQmx code, if I understood well).

 

Dieter

 

0 Kudos
Message 4 of 6
(5,441 Views)

Can you please share the c code with me, so I can take a look at it?

Thanks,

Rob

0 Kudos
Message 5 of 6
(5,436 Views)

The examples are part of LabWINDOWS/CVI, I will only share relevant code, of course it's a good idea considering CVI if you're making these kind of applications regularly.

 

Part of the start function in C:

int error=0;
char chan[256];
char clockSource[256];
uInt32 initialCount;
uInt32 countDirection,edge;
float64 rate;
char errBuff[2048]={'\0'};

/*********************************************/ // DAQmx Configure Code /*********************************************/ SetWaitCursor(1); DAQmxErrChk (DAQmxCreateTask("",&gTaskHandle)); DAQmxErrChk (DAQmxCreateCICountEdgesChan(gTaskHandle,chan,"",edge,initialCount,countDirection)); DAQmxErrChk (DAQmxCfgSampClkTiming(gTaskHandle,clockSource,rate,DAQmx_Val_Rising,DAQmx_Val_ContSamps,gSamplesToRead)); DAQmxErrChk (DAQmxRegisterDoneEvent(gTaskHandle,0,DoneCallback,NULL)); /*********************************************/ // DAQmx Start Code /*********************************************/ DAQmxErrChk (DAQmxStartTask(gTaskHandle));

Fetching the counters value:

int32 error=0;
int32 numRead;

/*********************************************/
// DAQmx Read Code
/*********************************************/
DAQmxErrChk(DAQmxReadCounterU32(gTaskHandle,gSamplesToRead,10.0,gData,gSamplesToRead,&numRead,0));

With this code and the way of transforming this to PyDAQmx as explained on https://pythonhosted.org/PyDAQmx/usage.html you should be able to get a working program.

 

Please inform me if you get something working. Maybe it's also a good idea to contact de developers of PyDAQmx.

 

0 Kudos
Message 6 of 6
(5,383 Views)