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 setChannelParameter(self): channel, parameter = yield self.selectChannelParameter() if parameter is AI.PHYSICAL_CHANNEL: returnValue("not yet supported") if parameter in (AI.MIN, AI.MAX): value = yield getType(float, "enter voltage: ") if parameter is AI.TERMINAL_CONFIG: trmCfgIndex = yield getListIndex(zip(*AI.TERMINAL_CONFIGS)[2], "select configuration") value = zip(*self.TERMINAL_CONFIGS)[0][trmCfgIndex] if parameter is AI.DESCRIPTION: value = yield getUserInput("enter description: ") yield self.protocol.sendCommand("set-channel-parameter", channel, parameter, value)
def main(): from sitz import TEST_STEPPER_MOTOR_SERVER from ab.abbase import getUserInput, sleep from ab.abclient import getProtocol from twisted.internet.defer import Deferred ## connect to server protocol = yield getProtocol(TEST_STEPPER_MOTOR_SERVER) ## get sm configuration config = yield protocol.sendCommand('get-configuration') delta = 2000 for id in config.keys(): # create client client = ChunkedStepperMotorClient(protocol, id) ## register for position updates def log(prompt, x): print '%s: %s' % (prompt, x) listener = partial(log, 'update for client %s' % client.id) client.addListener(client.POSITION, listener) ## change positions position = yield client.getPosition() delta /= 2 yield client.setPosition(position + delta) position = yield client.getPosition() # demonstrate canceling capabilities delta = -10000 d = Deferred() def onPositionChanged(newPosition): if d.called: print 'canceling!' client.cancel() client.removeListener(client.POSITION, onPositionChanged) else: print 'new pos: %d' % newPosition client.removeListener(client.POSITION, listener) client.addListener(client.POSITION, onPositionChanged) print '' yield sleep(.5) print 'starting long journey: press enter to quit' yield sleep(1.5) print '' e = client.setPosition(position + delta) yield getUserInput('') d.callback(None) yield e print 'shutting down' reactor.stop()
def setChannelParameter(self): channel, parameter = yield self.selectChannelParameter() if parameter is AI.PHYSICAL_CHANNEL: returnValue('not yet supported') if parameter in (AI.MIN, AI.MAX): value = yield getType(float, 'enter voltage: ') if parameter is AI.TERMINAL_CONFIG: trmCfgIndex = yield getListIndex( zip(*AI.TERMINAL_CONFIGS)[2], 'select configuration') value = zip(*self.TERMINAL_CONFIGS)[0][trmCfgIndex] if parameter is AI.DESCRIPTION: value = yield getUserInput('enter description: ') yield self.protocol.sendCommand('set-channel-parameter', channel, parameter, value)