08-22-2016 10:04 AM
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
08-23-2016 08:56 AM
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
08-24-2016 09:58 AM
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
08-29-2016 04:48 AM
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
08-29-2016 09:43 AM
Can you please share the c code with me, so I can take a look at it?
Thanks,
Rob
09-01-2016 03:35 AM
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.