Пример #1
0
    def testao_outputdc_single_ch(self):
        """
        testao_outputdc_single_ch
        Connect analog-out pin 0 to analog-in pin 0
        Connect analog-out pin 1 to analog-in pin 1        
        """
        ao0 = pdt.analog_output(daqid=0,
                                channel=0)
        ao0.output_dc(0.5)
        ai0 = pdt.analog_input(daqid=0,
                               channel=0,
                               rsediff='rse',
                               samplerate=1250000)
        a = ai0.acquire(10)
        print a
        
        self.assertAlmostEqual(a[0], 0.5, places=2)


        ao1 = pdt.analog_output(daqid=0,
                                channel=1)
        ao1.output_dc(1.0)
        ai1 = pdt.analog_input(daqid=0,
                               channel=1,
                               rsediff='rse',
                               samplerate=50000)
        a = ai1.acquire(10)    
        self.assertAlmostEqual(a[0], 1.0, places=2)
Пример #2
0
    def testconterms(self):
        """
        test connect terminals
        """
        ai = pdt.analog_input()
        ao = pdt.analog_output()

        pdt.connect_terms(0,ao,ai)
Пример #3
0
    def test_speakers_sine(self):
        """
        Outputs a 1kHz sine wave for 2 seconds on speakers
        """
        speakers = pdt.analog_output(daqid=2,
				     channel=(0,1))
        speakers.output_sin(freq=1000)
        time.sleep(2)
        speakers.stop()        
Пример #4
0
 def testao_outputdc_multi_ch(self):
     """
     testao_outputdc_multi_ch
     Connect analog-out pin 0 to analog-in pin 0
     Connect analog-out pin 1 to analog-in pin 1
     """
     ao = pdt.analog_output(daqid=0,
                             channel=[0,1])
     ao.output_dc([0.5,1.0])
     ai = pdt.analog_input(daqid=0,
                            channel=[0,1],
                            rsediff='rse',
                            samplerate=50000)
     a = ai.acquire(5)
     print a
     self.assertAlmostEqual(a[0], 0.5, places=2)
     self.assertAlmostEqual(a[5], 1.0, places=2)
Пример #5
0
    def testao_output_waveform(self):
        """
        test counter inputs
        """
	y = numpy.zeros(1000,dtype=numpy.float64)
        # create 1000 evenly spaced values from time=0 to x
        t = numpy.linspace(0,0.01,1000)
        f = 1000
        A = 5

        #y = A*waveforms.square(2*math.pi*f*t,duty=0.5)
        #y = A*waveforms.sawtooth(2*math.pi*f*t,width=0.5)

        
        for i in numpy.arange(1000):
            y[i] = 9.95*math.sin(i*2.0*math.pi*1000.0/16000.0)	
        
        ao = pdt.analog_output(channel=[0],samplerate=10000,contfin='cont')#clock='ai/SampleClock')
	ai = pdt.analog_input(channel=[0],samplerate=1E6)
	ao.output_waveform(y)
	ai.AcquireAndGraph(100000)
	ao.output_waveform(y)
Пример #6
0
import pydaqtools as pdt
import matplotlib.pyplot as plt
import numpy
import time

daqid = 2

sample_rate = 44100
num_samples = sample_rate / 10  # 100ms of data

# let pydaqtools find daqs installed on system
pdt.daqfind()

# get an analog output from the sound card
speakers = pdt.analog_output(daqid=daqid, channel=(0))
# output a 1kHz sin wave
speakers.output_sin(freq=1000)

# give it a second to start outputting on the speakers
time.sleep(1)

# grab the default microphone
microphone = pdt.analog_input(daqid=daqid, channel=0, samplerate=sample_rate)

# acquire a seconds worth of samples
samples = microphone.acquire(num_samples)

# stop the sound card from outputting
speakers.stop()

# calculate estimated acquisition time in milliseconds