Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read the output from a digital counter using python?

I am able to read the counter output from labview but when I tried to implement the following code in python I am unable to read the counter. I am in urgent need to solve this problem could someone please help out?  

 

Python code: 

import nidaqmx

from nidaqmx.constants import AcquisitionType, TaskMode, CountDirection, Edge
from nidaqmx._task_modules.channels.ci_channel import CIChannel
from nidaqmx._task_modules.channel_collection import ChannelCollection

 

with nidaqmx.Task() as task:
#create virtual channel
task.ci_channels.add_ci_count_edges_chan('Dev1/ctr1', initial_count=0, edge=Edge.RISING, count_direction=CountDirection.COUNT_UP)
task.read()

 

I get the following error

 

Traceback (most recent call last):
File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nidaqmx\_lib.py", line 139, in __getattr__
cfunc = getattr(self._library, function)
File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\ctypes\__init__.py", line 361, in __getattr__
func = self.__getitem__(name)
File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\ctypes\__init__.py", line 366, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'DAQmxReadCounterU32Ex' not found

 

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\....\TrialRead_DigSensor.py", line 33, in <module>
a= task.read()
File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nidaqmx\task.py", line 686, in read
self._handle, data, number_of_samples_per_channel, timeout)
File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nidaqmx\_task_modules\read_functions.py", line 359, in _read_counter_u_32_ex
cfunc = lib_importer.windll.DAQmxReadCounterU32Ex


File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nidaqmx\_lib.py", line 149, in __getattr__
'version of NI-DAQmx.'.format(function))
nidaqmx._lib.DaqFunctionNotSupportedError: The NI-DAQmx function "DAQmxReadCounterU32Ex" is not supported in this version of NI-DAQmx. Visit ni.com/downloads to upgrade your version of NI-DAQmx.

 

 

0 Kudos
Message 1 of 3
(4,322 Views)

Which version of NI-DAQmx are you using?

 

The "DAQmxReadCounterU32Ex" C API function, which the Python bindings use under the hood, was added in DAQmx 14.5, so you'll need that version of DAQmx or later to use that functionality.

——
Brandon Streiff
ni.com/compactdaq · ni.com/daq
0 Kudos
Message 2 of 3
(4,302 Views)

 

Thanks a lot for your help !! I updated my DAQmx to 14.5 and it works now. 

0 Kudos
Message 3 of 3
(4,282 Views)