nidaqmx-python icon indicating copy to clipboard operation
nidaqmx-python copied to clipboard

LibraryInterpreter.read_raw and write_raw do not allow switching array dtypes

Open bkeryan opened this issue 9 months ago • 0 comments

LibraryInterpreter.read_raw sets cfunc.argtypes based on the dtype of the array you pass in:

    def read_raw(self, task, num_samps_per_chan, timeout, read_array):
        samples_read = ctypes.c_int()
        number_of_bytes_per_sample = ctypes.c_int()

        cfunc = lib_importer.windll.DAQmxReadRaw
        if cfunc.argtypes is None:
            with cfunc.arglock:
                if cfunc.argtypes is None:
                    cfunc.argtypes = [
                        lib_importer.task_handle, ctypes.c_int, ctypes.c_double,
                        wrapped_ndpointer(dtype=read_array.dtype, flags=('C', 'W')),
                        ctypes.c_uint, ctypes.POINTER(ctypes.c_int),
                        ctypes.POINTER(ctypes.c_int), ctypes.POINTER(c_bool32)]
        ...

However, this is incorrect because cfunc.argtypes is only initialized once.

I haven't tested this yet, but I expect it to remember the dtype of the 1st array that you pass to task.in_stream.read_into() and reject any array with a different dtype.

I think the correct way to make ndpointer accept any array dtype is to specify dtype=None.

bkeryan avatar May 08 '24 20:05 bkeryan