03-15-2021 05:34 AM
I'm attempting to build a graphical user interface in python to easily configure and control measurements using a PCIe-6351 on a Windows machine (and eventually also compatible on Linux systems). The measurements performed will be long-duration, multi-channel time series' of voltages with optional real-time demodulation. I can successfully communicate with the card when the read_one_sample() function is used; the problems arise when trying to use the read_many_sample() function, as shown in my testing function below.
def RunMeasurement(self):
task = nidaqmx.Task("NItask")
for i in range(self.params[4]):
task.ai_channels.add_ai_voltage_chan(self.params[6].split(",")[i])
timingcfg = Timing(task)
timingcfg.cfg_samp_clk_timing(
rate=5.0,
source="",
active_edge=nidaqmx.constants.Edge.RISING,
sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS,
samps_per_chan=32)
task.start()
datainput = in_stream.InStream(task)
reader = nidaqmx.stream_readers.AnalogMultiChannelReader(datainput)
data = np.zeros((self.params[4], 5))
points_read = 0
points_read = points_read + reader.read_many_sample(data, nidaqmx.constants.READ_ALL_AVAILABLE)
print(data)
print(points_read)
task.close()
The problem comes from the timing.py module:
I tried printing the expected argtype (set by cfunc.argtypes = [lib_importer.task_handle ... ]), which returns <class 'ctypes.c_void_p'>. Ok, so it's a void pointer to the memory block where the task handle is stored.
However, the source code checks for self._handle, which is of type <class 'nidaqmx.task.Task'>. I'm guessing this is the meat of the problem.
My question is, then, what can I do to fix this? Is there something I'm doing incorrectly here?
Solved! Go to Solution.
03-15-2021 05:46 AM
I really don't know Python, but from prior threads I'm muddled through it seems like the syntax for navigating task configuration usually has a form like "task.qualifier.func()".
To my eye, it looks like you may have created a "disembodied" timing object as a *copy* of the not-yet-configured timing part of the task, then you configure timing on this copy which does not reference the task. It's just hanging out there as a generic timing object. Hence the null task pointer.
Very much just a guess, but trying to help.
-Kevin P