NIDAQmx Counter input Edge Source change

675 Views Asked by At

I'm a little bit confused with my code. I want to read the position of a counter input (edge counter). I can get the Device and the channel but I want to change the Edge Source or the Terminal. If I add the channel the Edge Source is automatically "PFI0" which counts some different thing that I need. I want to change it to "PFI1" as seen in the picture. I tried the following, but it didn't work. Can someone please help me out!

import nidaqmx
def read_position():
    task = nidaqmx.Task()
    task.ci_channels.add_ci_count_edges_chan("Dev1/ctr0")
    task.ci_channels[0].ci_count_edges_term = "PFI1"
    task.start()
    pos = task.read()
    task.stop()
    task.close()
    return pos

Best regards, Szilárd

1

There are 1 best solutions below

0
On

You need to specify the device as well as the channel: instead of task.ci_channels[0].ci_count_edges_term = "PFI1" you should write task.ci_channels[0].ci_count_edges_term = "/Dev1/PFI1"

An easy way to check for the correct syntax is just to print the default channel: print(task.ci_channels[0].ci_count_edges_term)

Note how the / is necessary at the beginning of the string.