def main(): t = PulseWidthModulator() device = yield selectFromList(getDevices(), 'select device') channel = yield selectFromList( getPhysicalChannels(device)[CO], 'select physical channel') t.createChannel(channel) frequency = yield getType(float, 'enter frequency: ') t.setFrequency(frequency) dutyCycle = yield getType(float, 'enter duty cycle: ') t.setDutyCycle(dutyCycle) yield getUserInput('press enter to start: ') t.generatePulses() while True: FREQ, DUTY, QUIT = 'frequency', 'duty cycle', 'quit' options = (FREQ, DUTY, QUIT) option = yield selectFromList(options, 'select command') if option is QUIT: break else: value = yield getType( float, 'set new %s (%.2f): ' % (option, getattr(t, { FREQ: 'getFrequency', DUTY: 'getDutyCycle' }[option])())) getattr(t, { FREQ: 'setFrequency', DUTY: 'setDutyCycle' }[option])(value) t.stop() reactor.stop()
def main(): t = PulseWidthModulator() device = yield selectFromList( getDevices(), 'select device' ) channel = yield selectFromList( getPhysicalChannels(device)[CO], 'select physical channel' ) t.createChannel(channel) frequency = yield getType( float, 'enter frequency: ' ) t.setFrequency(frequency) dutyCycle = yield getType( float, 'enter duty cycle: ' ) t.setDutyCycle(dutyCycle) yield getUserInput('press enter to start: ') t.generatePulses() while True: FREQ, DUTY, QUIT = 'frequency', 'duty cycle', 'quit' options = (FREQ,DUTY,QUIT) option = yield selectFromList( options, 'select command' ) if option is QUIT: break else: value = yield getType( float, 'set new %s (%.2f): ' % ( option, getattr( t, { FREQ:'getFrequency', DUTY:'getDutyCycle' }[option] )() ) ) getattr( t, { FREQ:'setFrequency', DUTY:'setDutyCycle' }[option] )(value) t.stop() reactor.stop()
def getVoltMeter(): if os.path.isfile(CONFIG_FILEPATH): with open(CONFIG_FILEPATH,'r') as config_file: config_dict = pickle.loads(config_file.read()) returnValue( VoltMeter( config_dict.values() ) ) else: device = yield selectFromList(daqmx.getDevices(),'select a device') returnValue( VoltMeter( ( {VoltMeter.PHYSICAL_CHANNEL:channel,VoltMeter.VOLTAGE_RANGE:VoltMeter.V0_05} for channel in daqmx.getPhysicalChannels(device)[daqmx.AI] ) ) )
def configureVoltMeter(): device = yield selectFromList(daqmx.getDevices(), 'select device') channelDicts = [] while True: channelDict = {} aborted = False #HACK channelDict['minVal'] = 0.0 for optionKey, getOption in ( ('physicalChannel', partial(selectFromList, [None] + daqmx.getPhysicalChannels(device)[daqmx.AI], 'select channel')), ('name', partial(getUserInput, 'enter name: ')), ('maxVal', partial(getFloat, 'insert max voltage: ')), ('terminalConfig', partial(selectFromList, ('default', 'differential'), 'select terminal configuration'))): opt = yield getOption() if opt is None: aborted = True break channelDict[optionKey] = opt if aborted: if channelDicts: quit = yield selectFromList([True, False], 'end task configuration?') if quit: break continue channelDicts.append(channelDict) vm = VoltMeter(channelDicts) samplingRate = yield getFloat('enter sampling rate: ') vm.setSamplingRate(samplingRate) callbackRate = yield getFloat('enter callback rate: ') vm.setCallbackRate(callbackRate) returnValue(vm)
step_tasks = { pulse_generator:daqmx.CO, digital_line:daqmx.DO } step_task = step_tasks[ select_from_list( step_tasks.keys(), 'select step mode' ) ] if 'config' in sys.argv: channels = ( select_from_list( daqmx.getPhysicalChannels( select_from_list( daqmx.getDevices(), 'select %s device' % role_name ) )[role_task], 'select %s channel' % role_name ) for role_task, role_name in ( (step_task,'step'), (daqmx.CI,'read'), (daqmx.DO,'direction') ) ) else: exit() sm = { daqmx.DO:DigitalLineStepperMotor,
print 'input must be between 0 and %d' % len(list) continue else: break return list[index] print '<---- STEPPER MOTOR CONFIGURATION --->' pulse_generator = 'pulse generator' digital_line = 'digital line' step_tasks = {pulse_generator: daqmx.CO, digital_line: daqmx.DO} step_task = step_tasks[select_from_list(step_tasks.keys(), 'select step mode')] if 'config' in sys.argv: channels = (select_from_list( daqmx.getPhysicalChannels( select_from_list(daqmx.getDevices(), 'select %s device' % role_name))[role_task], 'select %s channel' % role_name) for role_task, role_name in ((step_task, 'step'), (daqmx.CI, 'read'), (daqmx.DO, 'direction'))) else: exit() sm = { daqmx.DO: DigitalLineStepperMotor, daqmx.CO: PulseGeneratorStepperMotor }[step_task](*channels) print '<--- END CONFIGURATION --->' def log(x): print x
def configureVoltMeter(): device = yield selectFromList(daqmx.getDevices(),'select device') channelDicts = [] while True: channelDict = {} aborted = False #HACK channelDict['minVal'] = 0.0 for optionKey, getOption in ( ( 'physicalChannel', partial( selectFromList, [None] + daqmx.getPhysicalChannels(device)[daqmx.AI], 'select channel' ) ), ( 'name', partial( getUserInput, 'enter name: ' ) ), ( 'maxVal', partial( getFloat, 'insert max voltage: ' ) ), ( 'terminalConfig', partial( selectFromList, ( 'default', 'differential' ), 'select terminal configuration' ) ) ): opt = yield getOption() if opt is None: aborted = True break channelDict[optionKey] = opt if aborted: if channelDicts: quit = yield selectFromList([True,False],'end task configuration?') if quit: break continue channelDicts.append(channelDict) vm = VoltMeter(channelDicts) samplingRate = yield getFloat('enter sampling rate: ') vm.setSamplingRate(samplingRate) callbackRate = yield getFloat('enter callback rate: ') vm.setCallbackRate(callbackRate) returnValue(vm)