'''
A very simple example of just the nidaqmx package. This program
demonstrates the basics of interfacing with an NI DAQ card.
This code based on the ANSI C DAQmx example Acq-IntClk.c
'''
#Load the nidaqmx library and name it DAQmx so that all functions
#are available as DAQmx.function_name
import nidaqmx as DAQmx
#Load the matplotlib plotting library so we can plot our resutls
import pylab as pl
#Create a new DAQmx task. All of these function calls can be found
#in the ANSI C DAQmx reference document simply by removing the period.
taskHandle = DAQmx.CreateTask("AnalogAcq")
#Configure which phiscial channels this task will control. Here the
#first two Analog Input channels are used.
#Help can also be found for these functions by using
#'doc(DAQmx.CreateAIVoltageChan)' in a Python terminal or
#'DAQmx.CreateAIVoltageChan?' in IPython
DAQmx.CreateAIVoltageChan(taskHandle,"Dev1/ai0:1","",DAQmx.Val_Cfg_Default,-10.0,10.0,DAQmx.Val_Volts,None)
#Configure the timing clock for this task
DAQmx.CfgSampClkTiming(taskHandle,"",10000.0,DAQmx.Val_Rising,DAQmx.Val_FiniteSamps,1000)
#Take the analog measurement
DAQmx.StartTask(taskHandle)
#Read the data stored in the DAQ's internal buffer. Because there are
#two channles, 2000 points must be read.
data = DAQmx.ReadAnalogF64(taskHandle,1000,10.0,DAQmx.Val_GroupByChannel,2000,None)
#Stop the task
DAQmx.StopTask(taskHandle)
#Erase the task and all its configuration
DAQmx.ClearTask(taskHandle)
#Report the results
print "Acquired %d points\n" % len(data)
pl.plot(data[:1000], label="ai0") #Plot first channel
pl.plot(data[1000:], label="ai1") #Plot second channel
pl.legend(loc='best') #Add a legend
pl.show() #Show the plot on the screen. The plot will not appear before this calls