Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

NI USB-6251 nidaqmx problem with python

Hi,

I'm just trying to output a single sinwave (pulse) on AnalogOutput with nidaqmx in Python. For some reason, the pulse is always 1ms long, no matter how long the pulse is. Maybe I have an obvious error in reasoning. The code looks like to following:

 

import matplotlib.pyplot as plt
import numpy as np
import nidaqmx
import nidaqmx.system
system = nidaqmx.system.System.local()
system.driver_version
for device in system.devices:
    print(device)


x = np.linspace(0, 2 * np.pi , num=100) #generate x values for sinwave
sinewave = np.sin(x)*10 #generate sinwave
plt.plot(x, sinewave) #plot sinewave


nidaqmx.constants.AcquisitionType.FINITE:10178 #set output to finite

with nidaqmx.Task() as task:
    task.ao_channels.add_ao_voltage_chan('Dev2/ao0') #set device
    task.timing.cfg_samp_clk_timing(1e6) #set rate

    print('1 Channel N Samples Write: ') #print text
    print(task.write(sinewave)) #print number of samples sent

    task.start() #start task
    task.wait_until_done(timeout=10.0) #wait till task is done
    task.stop() #stop task

When I change the size of the sinewave, the final pulse will still be just 1ms.

x = np.linspace(0, 2 * np.pi , num=100)
x = np.linspace(0, 4 * np.pi , num=100)
x = np.linspace(0, 2 * np.pi , num=150)

All arrays x will lead to different looking pulses, but the pulses are all 1ms long. I bet it is sth. obvious I'm missing,... but I don't get it.

 

Thank you in advance for your help!

 

0 Kudos
Message 1 of 2
(1,878 Views)

Hey, 

 

it is probably to late for you, but in your code you have changed the freq of you sine.

The time of the signal is dependent on the number of points and the freq. of your device.

 

All the best 

Ben

0 Kudos
Message 2 of 2
(1,630 Views)