04-14-2020 06:37 PM
Hello,
I am now using python nidaqmx package to control my NI 9264 multiple channel analog output device.
The codes are below:
import nidaqmx
import numpy as np
import time
from nidaqmx import constants
def ave(a😞
return sum(i for i in a)/len(a)
delay=[]
t1 = nidaqmx.Task()
t1.ao_channels.add_ao_voltage_chan("cDAQ1Mod1/ao2")
t2 = nidaqmx.Task()
t2.ai_channels.add_ai_voltage_chan("Dev1/ai2")
t2.start()
t1.timing.cfg_samp_clk_timing( 25000,
sample_mode = nidaqmx.constants.AcquisitionType.FINITE,
samps_per_chan=2000)
#t1.start()
for j in np.linspace(-0.1,0.1,2000😞
start = time.time()
t1.write(j,auto_start=False)
end = time.time()
interval = end - start
delay.append(interval)
t2.read()
t1.close()
t2.close()
print(ave(delay))
print(1/ave(delay))
and the error occurs as :
DaqError: The generation is not yet started, and not enough space is available in the buffer.
Configure a larger buffer, or start the generation before writing more data than will fit in the buffer.
Property: DAQmx_Write_RelativeTo
Corresponding Value: DAQmx_Val_CurrWritePos
Property: DAQmx_Write_Offset
Corresponding Value: 0
Property: DAQmx_Buf_Output_BufSize
Corresponding Value: 1000
Task Name: _unnamedTask<14>
Status Code: -200293
what is the buffer size? looks like that the max buffer is 1000, can I change this value?
Thanks
04-15-2020 11:27 AM
For output task, you have to write data into the buffer before starting, or else as soon as it is started, it will be starved of data. The error is not exactly descriptive to help you figure this out though.
If you pre-write some data before starting the task, that should get past this error. Since your data set is finite, you can prewrite all of your data before starting the task.
04-15-2020 11:51 AM
Hello Jerry,
So in my case, how to write the data into buffer? Can you please show me the code?
Thx
04-17-2020 11:45 AM - edited 04-17-2020 11:46 AM
There is an AO example here: https://github.com/ni/nidaqmx-python/blob/master/nidaqmx_examples/ao_voltage_hw_timed.py
import nidaqmx
with nidaqmx.Task() as task:
task.ao_channels.add_ao_voltage_chan('Dev1/ao0')
task.timing.cfg_samp_clk_timing(1000)
print('1 Channel 1 Sample Write: ')
print(task.write(1.0))
task.stop()
print('1 Channel N Samples Write: ')
print(task.write([1.1, 2.2, 3.3, 4.4, 5.5], auto_start=True))
task.stop()
task.ao_channels.add_ao_voltage_chan('Dev1/ao1:3')
print('N Channel 1 Sample Write: ')
print(task.write([1.1, 2.2, 3.3, 4.4]))
task.stop()
print('N Channel N Samples Write: ')
print(task.write([[1.1, 2.2, 3.3], [1.1, 2.2, 4.4],
[2.2, 3.3, 4.4], [2.2, 3.3, 4.4]],
auto_start=True))
task.stop()
In your cases:
t1.write([1.0, 2.0], auto_start=False) <--- write at least 2 samples of data before starting will get you past the error
t1.start()
for j in np.linspace(-0.1,0.1,2000
start = time.time()
t1.write(j,auto_start=False)
end = time.time()
interval = end - start
delay.append(interval)
Or since your data is known before starting the task, you can collect the data into an array and write all of it before starting the AO task.
04-17-2020 02:58 PM
Thanks Jerry