class dac: def connect_nidaqmx(self): '''look at nidaqmx''' system = System() '''search for the card that we want to use''' card = None for dev in system.devices: if dev.get_product_type() == CARD_NAME: card = dev assert (card != None) '''create the 8-channel task''' self.task = AnalogOutputTask() channels = card.get_analog_output_channels()[:8] for channel in channels: self.task.create_voltage_channel(channel, min_val=0, max_val=7) '''zero everything''' self.zero() def write_voltages(self, voltages): av = np.array(voltages) if max(av) > 7.0: print 'CANNOT WRITE VOLTAGES GREATER THAN 7.0V' voltages = [0, 0, 0, 0, 0, 0, 0, 0] av = voltages self.task.write(voltages) print 'wrote', av.round(2) def zero(self): self.write_voltages([0, 0, 0, 0, 0, 0, 0, 0]) def __init__(self): print 'CNOT-MZ heater server\n' self.connect_nidaqmx()
class dac: def connect_nidaqmx(self): '''look at nidaqmx''' system=System() '''search for the card that we want to use''' card=None for dev in system.devices: if dev.get_product_type() == CARD_NAME: card=dev assert(card!=None) '''create the 8-channel task''' self.task = AnalogOutputTask() channels=card.get_analog_output_channels()[:8] for channel in channels: self.task.create_voltage_channel(channel, min_val=0, max_val=7) '''zero everything''' self.zero() def write_voltages(self, voltages): av=np.array(voltages) if max(av)>7.0: print 'CANNOT WRITE VOLTAGES GREATER THAN 7.0V' voltages=[0,0,0,0,0,0,0,0] av=voltages self.task.write(voltages) print 'wrote', av.round(2) def zero(self): self.write_voltages([0,0,0,0,0,0,0,0]) def __init__(self): print 'CNOT-MZ heater server\n' self.connect_nidaqmx()
def set_voltage_to_channel(channel,voltage): from nidaqmx import AnalogOutputTask tolerance = 1 laserTask = AnalogOutputTask("pointer") laserTask.create_voltage_channel(channel,min_val=voltage - tolerance, max_val=voltage + tolerance) laserTask.write(voltage) laserTask.clear()
def set_voltage_to_channel(channel, voltage): from nidaqmx import AnalogOutputTask tolerance = 1 laserTask = AnalogOutputTask("pointer") laserTask.create_voltage_channel(channel, min_val=voltage - tolerance, max_val=voltage + tolerance) laserTask.write(voltage) laserTask.clear()
def write(self, context): task = AnalogOutputTask(_task_name(context)) minimum = context.minimum if context.minimum is not None else -10 maximum = context.maximum if context.maximum is not None else 10 task.create_voltage_channel(_phys_channel(context), terminal="rse", min_val=minimum, max_val=maximum) task.write(self, context.value, auto_start=False) task.start()
def move_daq(signal,daq_config): try: from nidaqmx import AnalogOutputTask except Exception: print "nidaqmx missing, continuing anyway" daq = AnalogOutputTask() daq.create_voltage_channel(**daq_config['X']) daq.create_voltage_channel(**daq_config['Y']) daq.write(signal) del daq
def move_daq(signal, daq_config): try: from nidaqmx import AnalogOutputTask except Exception: print "nidaqmx missing, continuing anyway" daq = AnalogOutputTask() daq.create_voltage_channel(**daq_config['X']) daq.create_voltage_channel(**daq_config['Y']) daq.write(signal) del daq
def runner(parser, options, args): task = AnalogOutputTask() args, kws = get_method_arguments('create_voltage_channel', options) phys_channel = kws['phys_channel'] task.create_voltage_channel(**kws) channels = task.get_names_of_channels() if not channels: print 'No channels specified' return args, kws = get_method_arguments('configure_timing_sample_clock', options) clock_rate = kws.get('rate', 1000.0) if not task.configure_timing_sample_clock(**kws): return args, kws = get_method_arguments('ao_write', options) layout = kws.get('layout', 'group_by_scan_number') if options.ao_task == 'sin': min_val = task.get_min(phys_channel) max_val = task.get_max(phys_channel) samples_per_channel = clock_rate / len(channels) x = np.arange(samples_per_channel, dtype=float) * 2 * np.pi / samples_per_channel data = [] for index, channel in enumerate(channels): data.append(0.5 * (max_val + min_val) + 0.5 * (max_val - min_val) * np.sin(x - 0.5 * index * np.pi / len(channels))) data = np.array(data) if layout == 'group_by_scan_number': data = data.T else: raise NotImplementedError( ` options.ai_task `) print 'samples available/written per channel= %s/%s ' % ( data.size // len(channels), task.write(data.ravel(), **kws)) if not options.ao_write_auto_start: task.start() try: time.sleep(options.ao_task_duration) except KeyboardInterrupt, msg: print 'Caught Ctrl-C.'
def runner (parser, options, args): task = AnalogOutputTask() args, kws = get_method_arguments('create_voltage_channel', options) phys_channel = kws['phys_channel'] task.create_voltage_channel (**kws) channels = task.get_names_of_channels() if not channels: print 'No channels specified' return args, kws = get_method_arguments('configure_timing_sample_clock', options) clock_rate = kws.get('rate', 1000.0) if not task.configure_timing_sample_clock(**kws): return args, kws = get_method_arguments('ao_write', options) layout = kws.get('layout', 'group_by_scan_number') if options.ao_task=='sin': min_val = task.get_min(phys_channel) max_val = task.get_max(phys_channel) samples_per_channel = clock_rate / len(channels) x = np.arange(samples_per_channel, dtype=float)*2*np.pi/samples_per_channel data = [] for index, channel in enumerate(channels): data.append(0.5*(max_val+min_val) + 0.5*(max_val-min_val)*np.sin(x-0.5*index*np.pi/len(channels))) data = np.array(data) if layout=='group_by_scan_number': data = data.T else: raise NotImplementedError (`options.ai_task`) print 'samples available/written per channel= %s/%s ' % (data.size//len(channels), task.write(data.ravel(), **kws)) if not options.ao_write_auto_start: task.start() try: time.sleep(options.ao_task_duration) except KeyboardInterrupt, msg: print 'Caught Ctrl-C.'
""" from yepy import instruments, yeutil, output, alternateDecelerator from time import sleep from nidaqmx import AnalogOutputTask import copy # Setup Timing Card pb = instruments.PulseBlaster() pb.add(5, [0], [22.6 * pb.us]) # start the valve # Setup the Analog Output Card for the PS voltage task = AnalogOutputTask() task.create_voltage_channel('Dev1/ao0', min_val=0.0, max_val=9) # 5.3V corresponds to 8 kV task.configure_timing_sample_clock(rate=100000) task.write(100000 * [12500 / 15000.0 * 10]) # Setup Decelerator decelSeq = alternateDecelerator.delayMode def decelProg(vi, vf, select): if select == 'SF': decelSeq = alternateDecelerator.delayMode elif select == 'S=1': decelSeq = alternateDecelerator.normalMode decelSeq.calcPhase(vi, vf, 57) decelSeq.calcTime() offset = 0.186 / 810 for i in xrange(1, 5):
import niScope from nidaqmx import AnalogOutputTask import numpy as np scope = niScope.Scope("Dev4") task = AnalogOutputTask() task.create_voltage_channel("Dev3/ao3") task.configure_timing_sample_clock(source="RTSI0") data = np.sin(0.5*np.pi*np.arange(10000))**2 task.write(data) scope.ConfigureHorizontalTiming(sampleRate=30000,numPts=1000000) scope.ConfigureVertical() scope.ConfigureTrigger("Edge") scope.ExportSignal(signal=4, outputTerminal='VAL_RTSI_0') raw_input("signal exported") scope.Commit() raw_input("committed") scope.InitiateAcquisition() raw_input("Acquisition initiated")
from nidaqmx import AnalogOutputTask import numpy as np task = AnalogOutputTask() task.create_voltage_channel('Dev1/ao0', max_val=10) task.configure_timing_sample_clock() task.write(np.ones(1000) * 3) data = [i * 0.001 for i in range(1000)] for n in range(1000): task = AnalogOutputTask() task.create_voltage_channel("Dev1/ao3") task.configure_timing_sample_clock() task.write(data, auto_start=False) # del task
from nidaqmx import AnalogOutputTask import numpy as np task = AnalogOutputTask() task.create_voltage_channel('Dev1/ao0', max_val = 10) task.configure_timing_sample_clock() task.write(np.ones(1000)*3) data = [i*0.001 for i in range(1000)] for n in range(1000): task = AnalogOutputTask() task.create_voltage_channel("Dev1/ao3") task.configure_timing_sample_clock() task.write(data,auto_start=False) # del task
for v in densitytable: out1 = o.filehandles[(v, 'Ne')] for m in xtime: out1.write('%.3f\t' % (m)) out1.write('\n') out1.flush() #time.sleep(0.1) #raw_input('Final Check! Enter when done.') set = 1 while True: for density in densitytable: task2.write(100000 * [density]) #raw_input('Final Check! Enter when done.') sleep(1) # for v in voltages: # alarm() # pb.add(1,[20*i*pb.us for i in range(100)],[10*pb.us]*100) # pb.build() #task.write(100000*[v/15000.0*10]) #sleep(30) sleep(0.1) #raw_input('Set voltage to %s V. Then ENTER.' %(str(v))) #print '%dV' %v # pb.add(1,[300*pb.us],[400*pb.us]) # pb.build()
# Setup Pulseblaster pb = instruments.PulseBlaster() pb.add(5,[0],[22.6*pb.us]) # Valve Fire Pulse # Setup the Analog Output Card # channel 0 sets the HV PS Voltage #task = AnalogOutputTask() #task.create_voltage_channel('Dev1/ao0', min_val=0.0, max_val=9) #task.configure_timing_sample_clock(rate=100000) #task.write(100000*[12500/15000.0*10]) # Channel 1 sets the amplitude for the valve driving pulse task2 = AnalogOutputTask() task2.create_voltage_channel('Dev1/ao1', min_val=0.0, max_val=8.75) task2.configure_timing_sample_clock(rate=100000) task2.write(100000*[8.75]) # Setup Decelerator offset = 0.186/810 def decelProg(num,select): n = num/4 if select == 'SF': decelSeq = alternateDecelerator.bunchFirstSF decelSeq.labelArray = 'xyzw'*n+'As'+'bjarbias'*(83-n) elif select == 'S=1': decelSeq = alternateDecelerator.bunchFirstS1 decelSeq.labelArray = 'xyzw'*n+'A' + 'baba'*(83-n) else: raise ValueError('Select argument to function ' +\ 'decelProg must be one of the strings "SF" or "S=1"') decelSeq.calcVel(810,55)
from nidaqmx import AnalogOutputTask import numpy as np from six.moves import input data = 9.95 * np.sin(np.arange(1000, dtype=np.float64) * 2 * np.pi / 1000) task = AnalogOutputTask() task.create_voltage_channel('Dev1/ao2', min_val=-10.0, max_val=10.0) task.configure_timing_sample_clock(rate=1000.0) task.write(data, auto_start=False) task.start() input('Generating voltage continuously. Press Enter to interrupt..') task.stop() del task