#Acq_IncClk.py # This is a near-verbatim translation of the example program # C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Voltage\Acq-Int Clk\Acq-IntClk.c import numpy from pylab import * from nidaqmx import * class AnalogInDevice : def __init__(self, dll, parms) : # dll is the handle to the dll. device is the "Dev1", etc.. self.dll = dll # Define constants corresponding to values in C:\Program Files\National Instruments\NI-DAQ\DAQmx ANSI C Dev\include\NIDAQmx.h self.Cfg_Default = int32(-1) self.Volts = 10348 self.Rising = 10280 self.FiniteSamps = 10178 self.GroupByChannel = 0 self.ChanForAllLines = 1 self.RSE = 10083 self.ContSamps = 10123 self.GroupByScanNumber = 1 # initialize variables self.data = numpy.zeros((parms.samples_raw,),dtype=numpy.float64) def PotentialChannel(self, task_handle, parms) : # Establish the potential channel self.dll.DAQmxCreateAIVoltageChan(task_handle, parms.channel,"", self.Cfg_Default, parms.min, parms.max, self.Volts, None) # or RSE (single-ended) instead of Cfg_Default? def ConfigureTiming(self, task_handle, parms) : self.dll.DAQmxCfgSampClkTiming(task_handle, parms.clock_source, parms.sample_rate, self.Rising, self.FiniteSamps, parms.samples) # or ContSamps instead of FiniteSamps? def TakeData(self, task_handle, parms) : types=Types() read = types.read self.dll.DAQmxReadAnalogF64(task_handle, parms.samples_raw, parms.buffer_size, self.GroupByChannel, self.data.ctypes.data, parms.samples_raw, ctypes.byref(read),None) return read class ADCParameters : def __init__(self, types, min, max, timeout, buffer_size, sample_rate, samples, channel, clock): # Use: ADCParameters(t, -10.0, 10.0, 10, 10000.0, 2000, 'Dev1/ai0', 'OnboardClock') self.min = types.float64(min) #-10.0) self.max = types.float64(max) # 10.0 self.timeout = types.float64(timeout) #10.0 self.buffer_size = types.float64(buffer_size) #10 self.pointsToRead = buffer_size #self.pointsRead = types.uInt32() self.sample_rate = types.float64(sample_rate) #10000.0) self.samples = types.uInt64(samples) #2000) self.samples_raw=samples self.channel = ctypes.create_string_buffer(channel) #'Dev1/ai0') self.clock_source = ctypes.create_string_buffer(clock) #'OnboardClock') def Simple() : dll, message = LoadDLL() if dll == 0 : print 'Library not loadable. ' + message sys.exit() t = Types() task = CreateTask(dll, t, 0) # Create task 0 p = ADCParameters(t, -10.0, 10.0, 10, 100, 10000.0, 2000, 'Dev1/ai0', 'OnboardClock') # types, min, max, timeout, buffer_size, sample_rate, samples, channel, clock a = AnalogInDevice(dll, p) # Initialize the analog input device a.PotentialChannel(task, p) # Open an analog input channel for the task a.ConfigureTiming(task, p) # Configure the timing for taking data points on this channel for this task. StartTask(dll, task) # Begin the task data_points_taken = a.TakeData(task, p) # Take some data print "Acquired %d points"%(data_points_taken.value) plot(a.data) show() EndTask(dll, task) ClearTask(dll, task) #---------------------------------------------------------------------------------------------------------------------------------------------------- if __name__ == '__main__' : Simple()