Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

USB 6501 python pulse detection

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)

0 Kudos
Message 1 of 5
(1,121 Views)

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.

santo_13_0-1643863728680.png

Since you've only one HW counter, you can count pulses only on one signal.

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 2 of 5
(1,101 Views)

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.

0 Kudos
Message 3 of 5
(1,090 Views)

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.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 4 of 5
(1,085 Views)

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:

 

with nidaqmx.Task() as task:
 task.di_channels.add_di_chan('Dev2/port0/line0:1) #reads form both digital inputs (0 and 1)
 task.start()
 data=task.read(number_of_samples_per_channel= 256)
 
This result in a 256 list of numbers containing 0, 1, 2 or 3, which corresponds with the state of the digital inputs (0=00000000, 1=00000001, 2=00000010, 3=00000011), where I can deduce which digital input has been switched on or off.
 
The code is repeated each 100 milliseconds with the windows.after(100, ReadPulses) command of tkinter, were ReadPulses is the module (def ReadPulses():) containing the code above.
 
Thank you for your help.
0 Kudos
Message 5 of 5
(1,068 Views)