Hi,
I am trying to generate two analog output signals using the write function of the NiDaqmx package for python. However when passing a 2D array as output array I get the following error:
"
nidaqmx.errors.DaqError: Write cannot be performed because the NumPy array passed into this function is not shaped correctly. You must pass in a NumPy array of the correct number of dimensions based on the write method you use.
No. of dimensions of NumPy Array provided: 2
No. of dimensions of NumPy Array required: 1
"
In the example below outputX and outputY are two equally sized 1 dimensional arrays. I tried multiple ways of generating a 2D array but none of them seems to solve the error. If I compare the data type of this array it is the same as the one they use in the
I already looked at the documentation but still haven't found a solution yet.
Help is much appreciated,
With kind regards,
Lex
outputData = np.append(outputX, outputY) outputData = outputData.reshape((2,outputX.size)) outputData = np.transpose(outputData) print(outputData.shape) outputChannels = ao_chan_x + ", " + ao_chan_y with nidaqmx.Task() as writeTask, nidaqmx.Task() as readTask: writeTask.ao_channels.add_ao_voltage_chan(outputChannels) readTask.ai_channels.add_ai_voltage_chan(ai_chan) writeTask.timing.cfg_samp_clk_timing(rate = writingRate, sample_mode = nidaqmx.constants.AcquisitionType.FINITE, samps_per_chan = outputX.size) readTask.timing.cfg_samp_clk_timing(rate = readingRate, sample_mode = nidaqmx.constants.AcquisitionType.FINITE, samps_per_chan = inputData.size) writeTask.triggers.start_trigger.cfg_dig_edge_start_trig(trigger_source = '/Dev2/ai/StartTrigger') #Setting the trigger on the analog input reader = AnalogSingleChannelReader(readTask.in_stream) writer = AnalogSingleChannelWriter(writeTask.out_stream) print("The channels linked to WriteTask are: ") for i in writeTask.ao_channels: print(i) print("Starting writing and reading using", outputX.size, "and", inputData.size) estT = outputX.size/writingRate print("Estimated time: ", estT) writer.write_many_sample(outputData) writeTask.start() print("Start reading/writing") reader.read_many_sample(inputData, timeout = estT+5) writeTask.wait_until_done(timeout = estT+5) readTask.wait_until_done(timeout = estT+5) print("Done with data")