02-02-2022 02:00 PM
Hi,
I am new in NI DAQ and also in python.
I am using a NI USB 6501 for detecting pulses from two Ritter MilliGascounters connected to P0.0 and P0.1. I managed to program a simple python code to detect the continuous digital input signal and when it changes. Here is the code:
import nidaqmx
with nidaqmx.Task() as task:
task.di_channels.add_di_chan('Dev1/port0/line0:1')
task.start()
while True:
print(task.read())
As a result, it prints a "3" continuously, a "2" when a pulse is detected in P0.0 and a "1" whe the pulse come from P0.1.
The problem is that in this way the program must be always "listening" and thus, no other tasks can be made. This piece of code is part of a program that must read data from other devices (pH, ORP, Temperature...), but as it is stuck in this piece of code everything freezes.
Is there any other way of programing the pulse detection or a buffering method to store the number of pulses in the USB6501 and retrieve this number on demand?
Thanks to all.
(Using Python 3.10.2, DAQmx 21.3 and Windows 10)
02-02-2022 10:49 PM - edited 02-02-2022 10:50 PM
6501 is a simple DIO card and it supports a maximum of 1 DI task and 1 DO task (Edit) you can have N tasks but only one task active at a time that can run at the same time. If you need to use more than one line then all those lines should be part of the same task.
You could use P2.7 to use the internal counter to count the pulses, you've to create a separate counter task for this.
Since you've only one HW counter, you can count pulses only on one signal.
02-03-2022 06:07 AM
Thank you very much for your answer.
I know this can be done, as I saw a comercial software working with this hardware configuration. At least a software which registers only these pulses form digital inputs (without doing other tasks than plotting and saving data in a file).
I have found some examples in NIDAQmx-python GitHub webpage (https://github.com/ni/nidaqmx-python/tree/master/nidaqmx_examples) and I am testing based on them.
I hope to find a solution, but any help is welcome.
Thank you again.
02-03-2022 09:20 AM
Yes, it is possible but the only way would be for you to continuously poll the device to get the data. You've to switch between polling and updating any DO state.
02-10-2022 04:42 AM - edited 02-10-2022 04:43 AM
Hi,
Finally I managed to write a separate code that reads from the USB 6501 (almost) continuosly and write the reads to a csv. The main program reads not only the external probes (pH, ORP...) but also the poulses from the csv. Here is the important part of the code to read from the USB 6501: