I'm toggling inputs on an NI-USB6525 and trying to detect the change with a Python script.
I'm able to write the lines and read them successfully after the write, but I am not detecting the changes. I can set an input to True or False and then use another script to manually read the input and get the correct result. I need this script to automatically detect the change.
import sysimport timeimport nidaqmxdef readControlSimulator(niDaqDevice ="Dev1"):# On NI-USB6501 all IOs are configurable.# On NI-USB6525 port0 are outputs, port1 are inputs.
INPUT_PORT ='port1'# read command line argumentsfor arg in sys.argv[1:]:
niDaqDevice = arg# Set up NIDAQ line detection for all lineswith nidaqmx.Task()as task:# Will only work if using a compatible device.try:print("SET UP CHANGE DETECTION")
task.di_channels.add_di_chan(niDaqDevice +'/'+ INPUT_PORT +'/line0:7')
task.timing.cfg_change_detection_timing(rising_edge_chan = niDaqDevice +'/'+ INPUT_PORT +'/line0:7',
falling_edge_chan = niDaqDevice +'/'+ INPUT_PORT +'/line0:7',
sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS)def callback(task_handle, signal_type, callback_data):print("CHANGE LINE")return0
task.register_signal_event(nidaqmx.constants.Signal.CHANGE_DETECTION_EVENT, callback)
task.start()except nidaqmx.DaqErroras e:print(str(e))
time.sleep(10)if __name__ =='__main__':
readControlSimulator()
The code should print "CHANGE LINE" if a line changes, but it doesn't.
Thanks for any and all help.