Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

read a counter in python

hello i have created a task the read the counter

with nidaqmx.Task() as task:
      task.ci_channels.add_ci_count_edges_chan('Dev1/ctr0', initial_count=0, edge=Edge.RISING, count_direction=CountDirection.COUNT_UP)

      tsk = task.read()

      print(tsk)

every time i read the task the counter start from 0

how i can have a continuos reading in order to display it continuosly?

 

Thanks

 

0 Kudos
Message 1 of 5
(2,566 Views)

This is due to a subtle "convenience" feature of DAQmx.

 

When you call read() on a task that isn't running, it will automatically start the task, do the reading, then stop the task again.  So each time you call read(), you're getting a fresh task start (which defaults the initial count to 0) followed by an immediate read() before any edges can increment the count.

 

Instead, explicitly start the task yourself and then enter into a loop that reads repeatedly.  Then you'll start seeing cumulative counts.  (It's probably also a good idea to add some kind of brief time delay function in the loop).

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy coming to an end (finally!). Permanent license pricing remains WIP. Tread carefully.
0 Kudos
Message 2 of 5
(2,542 Views)

thanks for your reply but i can read for example in this way

task.read(1024)

In this case i have a list of value, but if i show them i'm in delay from the real value measured.

0 Kudos
Message 3 of 5
(2,527 Views)

Sorry, but I'm afraid I have no familiarity with the python API for DAQmx functions.  I'm just pretty familiar with DAQmx itself through lots of LabVIEW-based programming.

 

For example, I don't know how that read(1024) function is implemented.   Is it simply a loop that iterates 1024 times, takes 1 reading each time, and accumulates the results?  If so, then the "delay" you talk about may just be the time it takes to execute those 1024 reads.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy coming to an end (finally!). Permanent license pricing remains WIP. Tread carefully.
0 Kudos
Message 4 of 5
(2,523 Views)

I understand

I have read many post, but i'm not able to find one solution for read a counter continuously with python

0 Kudos
Message 5 of 5
(2,518 Views)