06-07-2023 04:51 AM
Hi all,
I'm programming the NI9269 AO board, using python, in order to send a sinusoidal signal from AO:0 output and a square wave from AO:1 output, using a single task.
Reading multiple topics about "how to use multiple channels of the same board at the same time", I understood two main things:
- I have to use only one task at time because I have only one DAQ in the board.
- I have to use the function write_many_sample(vector), where vector is a 2D array.
Following these tips I still get these two errors below that doesn't make sense for me because I'm using only one task.
ERRORS:
/usr/local/lib/python3.9/dist-packages/nidaq
mx/task.py:97: ResourceWarning: Task of name "_unnamedTask<0>" was not explicitly closed before it was destructed. Resources on the task device may still be reserved.
/usr/local/lib/python3.9/dist-packages/nidaqmx/task.py:97: ResourceWarning: Task of name "_unnamedTask<1>" was not explicitly closed before it was destructed. Resources on the task device may still be reserved.
I think that I'm missing some dumb things. Have you any suggestion about the origin of these errors?
Thanks in advance!
Here the code that I'm using:
# DEFINITION OF THE SIGNALS -----------------------------------
t = np.linspace(0, 1, 10000, endpoint=False)
Signal2 = signal.square(2 * np.pi * 5 * t)
Frequency=1000
Amplitude=7
fs = 100000
T = 10
t_input = np.linspace(0,T,10000)
Signal = Amplitude * np.sin(2 * np.pi * Frequency * t_input)
samps_per_chan=T*fs
-------------------------------------------------------------
#DEFINITION OF THE 2D ARRAY----------------
vector = np.append(Signal, Signal2)
vector = vector.reshape((2,Signal.size))
vector = np.transpose(vector)
-------------------------------------------
#GENERATION OF THE TASK----------------------
self.task_input_1 = nidaqmx.Task()
self.task_input_1.ao_channels.add_ao_voltage_chan('cDAQ9185-211A955Mod1/ao0:1')
self.task_input_1.timing.cfg_samp_clk_timing(rate=fs,sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS)
SignalStreamer = nidaqmx.stream_writers.AnalogMultiChannelWriter(self.task_input_1.out_stream)
SignalStreamer.write_many_sample(vector)
self.task_input_1.start()
Solved! Go to Solution.
06-07-2023 07:21 AM
Hi guys,
I found the solution, maybe it can be helpfull for others in the same situation as mine.
My error was the last step of the vector creation. It is sufficient to delete the following line and the script works.
vector = np.transpose(vector)
PS: I don't know which is the connection between the 2D array and the double task error.