Hi,
We are currently facing a problem with the nidaqmx library for Python. We try to get a trigger if a digital input changes, but if we configure the digital input as follows, we cannot read from it and get timeouts. The error message is below the code snippets.
Configuration of the digital input with timing and register of the change event:
channel = "Dev1/port0/line0:7"
task.di_channels.add_di_chan(
channel,
line_grouping=constants.LineGrouping.CHAN_PER_LINE,
)
task.timing.cfg_change_detection_timing(
rising_edge_chan=channel,
falling_edge_chan=channel,
sample_mode=constants.AcquisitionType.CONTINUOUS,
)
task.register_signal_event(nidaqmx.constants.Signal.CHANGE_DETECTION_EVENT, callback)
The callback method is defined as follows, but it is never called.
def callback(self, task_handle, signal_type, callback_data):
print("Input event callback")
val = task.read()
print(val)
When we try to start the task and read from it like this, the error below occurs (timeout).
task.start()
test_values = task.read()
print(test_values)
Error message:
nidaqmx.errors.DaqReadError: Some or all of the samples requested have not yet been acquired.
To wait for the samples to become available use a longer read timeout or read later in your program. To make the samples available sooner, increase the sample rate. If your task uses a start trigger, make sure that your start trigger is configured correctly. It is also possible that you configured the task for external timing, and no clock was supplied. If this is the case, supply an external clock.
Property: DAQmx_Read_RelativeTo
Requested Value: DAQmx_Val_CurrReadPos
Property: DAQmx_Read_Offset
Requested Value: 0
Task Name: _unnamedTask<0>
Status Code: -200284
The compete example code is attached.
I don't think that a real timeout is the problem, I rather think that with the configuration we cannot read from a digital input anymore, but why?
There are some further question that we have regarding the callback. There are three parameters in the callback method stub, but neither of them is really usable. I expected, that one of the arguments represents the current value of the digital inputs but there is a task handle which cannot be used, the signal type which in our case is always the same, and the callback data which cannot be set in Python.
What is the correct way to acquire the sample data in the callback?
Thank you very much!