Example #1
0
def driveFlipper(value):
    slog('Driving flipper to %s ...' % value)

    # make sure that value is int
    value = int(value)

    counter = 0
    while True:
        try:
            counter += 1

            waitUntilSicsIs(ServerStatus.EAGER_TO_EXECUTE)
            sics.handleInterrupt()

            sics.set('/instrument/flipper/set_flip_on', value)

            waitUntilSicsIs(ServerStatus.EAGER_TO_EXECUTE)
            sics.handleInterrupt()

            if getFlipper() != value:
                raise Exception('unable to set Flipper')

            break

        except (Exception, SicsExecutionException) as e:
            if isInterruptException(e) or (counter >= 20):
                raise

            slog('Retry setting Flipper')
            time.sleep(1)

    slog('Flipper is set to %s' % getFlipper())
Example #2
0
def driveSample(position):
    log('Driving sample holder to position ' + str(position) + ' ...')
    cur = sics.getValue('sampleNum').getFloatData()
    if abs(cur - position) < 0.01:
        log('sampleNum is already at ' + str(position))
        return

    sicsController = sics.getSicsController()
    controller = sicsController.findComponentController(devices['sampleNum'])
    #    controller.drive(position)
    cnt = 0
    while cnt < 20:
        try:
            controller.drive(position)
            break
        except SicsExecutionException, e:
            em = str(e.getMessage())
            if em.__contains__('Interrupted'):
                raise e
            time.sleep(0.6)

            log(str(e))
            log('retry driving sampleNum')

            time.sleep(1)
            while not sicsController.getServerStatus().equals(ServerStatus.EAGER_TO_EXECUTE):
                time.sleep(0.3)
            cnt += 1
            sics.handleInterrupt()

            cur = sics.getValue('sampleNum').getFloatData()
            if abs(cur - position) < 0.01:
                log('sampleNum is already at ' + str(position))
                return
Example #3
0
def driveFlipper(value):
    slog('Driving flipper to %s ...' % value)

    # make sure that value is int
    value = int(value)

    counter = 0
    while True:
        try:
            counter += 1

            waitUntilSicsIs(ServerStatus.EAGER_TO_EXECUTE)
            sics.handleInterrupt()

            sics.set('/instrument/flipper/set_flip_on', value)

            waitUntilSicsIs(ServerStatus.EAGER_TO_EXECUTE)
            sics.handleInterrupt()

            if getFlipper() != value:
                raise Exception('unable to set Flipper')

            break

        except (Exception, SicsExecutionException) as e:
            if isInterruptException(e) or (counter >= 20):
                raise

            slog('Retry setting Flipper')
            time.sleep(1)

    slog('Flipper is set to %s' % getFlipper())
Example #4
0
def driveSample(position):
    log('Driving sample holder to position ' + str(position) + ' ...')
    cur = sics.getValue('sampleNum').getFloatData()
    if abs(cur - position) < 0.01:
        log('sampleNum is already at ' + str(position))
        return

    sicsController = sics.getSicsController()
    controller = sicsController.findComponentController(devices['sampleNum'])
    #    controller.drive(position)
    cnt = 0
    while cnt < 20:
        try:
            controller.drive(position)
            break
        except SicsExecutionException, e:
            em = str(e.getMessage())
            if em.__contains__('Interrupted'):
                raise e
            time.sleep(0.6)

            log(str(e))
            log('retry driving sampleNum')

            time.sleep(1)
            while not sicsController.getServerStatus().equals(ServerStatus.EAGER_TO_EXECUTE):
                time.sleep(0.3)
            cnt += 1
            sics.handleInterrupt()

            cur = sics.getValue('sampleNum').getFloatData()
            if abs(cur - position) < 0.01:
                log('sampleNum is already at ' + str(position))
                return
Example #5
0
def driveToSamplePosition(position):
    if state.sample_stage == SAMPLE_STAGE.fixed:
        slog('fixed sample stage cannot be driven to %s' % position)
        return

    # drive to position
    slog('Driving sample holder to position %s ...' % position)

    if state.sample_stage == SAMPLE_STAGE.manual:
        checkedDrive('samx', position)
        return

    if state.sample_stage != SAMPLE_STAGE.lookup:
        raise Exception('unexpected sample stage configuration')

    sicsController = sics.getSicsController()
    controller = sicsController.findComponentController('/sample/sampleNum')

    counter = 0
    position = int(position)
    tolerance = 0.1
    while True:
        try:
            counter += 1

            waitUntilSicsIs(ServerStatus.EAGER_TO_EXECUTE)
            sics.handleInterrupt()

            controller.drive(position)
            sics.handleInterrupt()

            break

        except (Exception, SicsExecutionException) as e:
            if isInterruptException(e) or (counter >= 20):
                raise

            if abs(controller.getValue(True).getFloatData() -
                   position) <= tolerance:
                break

            slog('Retry driving sampleNum')
            time.sleep(1)

    # wait until
    for counter in xrange(10):
        if abs(controller.getValue(True).getFloatData() -
               position) > tolerance:
            time.sleep(0.1)
        else:
            break

    slog('Position of sample holder: %s' %
         controller.getValue(True).getFloatData())
Example #6
0
def waitUntilSicsIs(status, dt=0.2):
    repeat = True
    while repeat:
        sics.handleInterrupt()

        while not sics.getSicsController().getServerStatus().equals(status):
            time.sleep(dt)

        time.sleep(dt)
        repeat = not sics.getSicsController().getServerStatus().equals(status)

    sics.handleInterrupt()
Example #7
0
def run_action(act):
    act.set_running_status()
    try:
        exec(act.command)
        act.set_done_status()
#    except Exception, e:
#        raise e
    except:
        if sics.getSicsController() != None: 
            act.set_interrupt_status()
        act.set_error_status()
        traceback.print_exc(file = sys.stdout)
        raise Exception, 'Error in running <' + act.text + '>'
    if sics.getSicsController() != None:
        sics.handleInterrupt()
Example #8
0
def sleep(secs, dt=0.1):
    # interruptable sleep
    target = datetime.now() + timedelta(seconds=secs)

    while True:
        if target < datetime.now():
            break
        else:
            sics.handleInterrupt()

        if target < datetime.now():
            break
        else:
            time.sleep(dt)

    sics.handleInterrupt()
Example #9
0
def sleep(secs, dt=0.1):
    # interruptable sleep
    target = datetime.now() + timedelta(seconds=secs)

    while True:
        if target < datetime.now():
            break
        else:
            sics.handleInterrupt()

        if target < datetime.now():
            break
        else:
            time.sleep(dt)

    sics.handleInterrupt()
Example #10
0
def waitUntilSicsIs(status, dt=0.2):
    controller = sics.getSicsController()
    timeout = 5
    while True:
        sics.handleInterrupt()

        count = 0
        while not controller.getServerStatus().equals(status) and count < timeout:
            time.sleep(dt)
            count += dt
        
        if controller.getServerStatus().equals(status):
            break
        else:
            controller.refreshServerStatus()

    sics.handleInterrupt()
Example #11
0
def driveGuide(value):
    if value not in GUIDE_CONFIG:
        slog('[WARNING] unknown guide configuration: ' + value)

    # set target configuration
    sics.set('/commands/optics/guide/configuration', value)

    if getGuideConfig() == value:
        slog('Guide was already moved to %s (no action is required)' % value)
        return

    slog('Moving guide to ' + value)

    sicsController = sics.getSicsController()
    controller = sicsController.findComponentController('/commands/optics/guide')

    # setting of configuration and starting a command are committed to SICS via different communication channels
    # in order to make those in sync, we need to wait for the configuration to settle
    time.sleep(0.5)

    counter = 0
    while True:
        try:
            counter += 1

            waitUntilSicsIs(ServerStatus.EAGER_TO_EXECUTE)
            sics.handleInterrupt()

            timeout = datetime.now() + timedelta(minutes=5)
            controller.syncExecute()

            while (getGuideConfig() != value) and (datetime.now() < timeout):
                sleep(0.5)

            break

        except (Exception, SicsExecutionException) as e:
            if isInterruptException(e) or (counter >= 20):
                raise

            slog(str(e), f_err=True)
            slog('Retry moving guide')
            time.sleep(1)

    slog('Guide is moved to ' + getGuideConfig())
Example #12
0
def run_action(act):
    act.set_running_status()
    try:
        exec(act.command)
        act.set_done_status()


#    except Exception, e:
#        raise e
    except:
        if sics.getSicsController() != None:
            act.set_interrupt_status()
        act.set_error_status()
        traceback.print_exc(file=sys.stdout)
        raise Exception, 'Error in running <' + act.text + '>'
    if not act.no_interrupt_check == 'True':
        if sics.getSicsController() != None:
            sics.handleInterrupt()
Example #13
0
    def drive(self):
        if self.__is_dirty__ :
            driveAtt(330)
        else:
            return
        try:
            sics.clearInterrupt()
            log('starting configuration')
            
            if not self.bs is None:
                selBs(self.bs)
            if self.need_drive_guide():
                driveGuide(self.guide)
            self.multi_drive()
            self.multi_set()
            
        finally:
            self.clear()
        log('skipping status checking')
#	while not sics.get_status().equals(ServerStatus.EAGER_TO_EXECUTE) :
#            time.sleep(0.3)
        sics.handleInterrupt()
        log('configuration is finished')
Example #14
0
def driveGuide(value):
    if value not in GUIDE_CONFIG:
        slog('[WARNING] unknown guide configuration: ' + value)

    # set target configuration
    sics.set('/commands/optics/guide/configuration', value)

    slog('Moving guide to ' + value)

    sicsController = sics.getSicsController()
    controller = sicsController.findComponentController(
        '/commands/optics/guide')

    # setting of configuration and starting a command are committed to SICS via different communication channels
    # in order to make those in sync, we need to wait for the configuration to settle
    time.sleep(0.5)

    counter = 0
    while True:
        try:
            counter += 1

            waitUntilSicsIs(ServerStatus.EAGER_TO_EXECUTE)
            sics.handleInterrupt()

            controller.syncExecute()
            sics.handleInterrupt()
            break

        except (Exception, SicsExecutionException) as e:
            if isInterruptException(e) or (counter >= 20):
                raise

            slog('Retry moving guide')
            time.sleep(1)

    slog('Guide is moved to ' + getGuideConfig())
Example #15
0
	print 'not closable'
def load_script(fname):
	fname = os.path.dirname(__UI__.getScriptFilename()) + '/' + fname
	__UI__.loadScript(fname)
def confirm(msg): 
	return __runner__.openConfirm(msg)
def selectSaveFolder():
	return __runner__.selectSaveFile()
Plot1.close = noclose
Plot2.close = noclose
Plot3.close = noclose
#        Plot1 = Image(widget=__register__.getPlot1())
#        Plot2 = Plot(widget=__register__.getPlot2())
#        Plot3 = Image(widget=__register__.getPlot3())
if '__dispose__' in globals() :
	__dispose__()
def auto_run():
	pass
def run_action(act):
	act.set_running_status()
	try:
		exec(act.command)
		act.set_done_status()
	except Exception, e:
		act.set_interrupt_status()
		raise Exception, e.message
	except:
		act.set_error_status()
		raise Exception, 'Error in running ' + act.name
	sics.handleInterrupt()
Example #16
0
    def drive(self):
        if self.__is_dirty__:
            driveAtt(330)
        else:
            return
        try:
            sics.clearInterrupt()
            log("starting configuration")
            if self.need_drive_det():

                ########### below code drop dhv1 and select beam stop together ###########
                precision = 20
                startingValue = getDhv1Value()
                if startingValue > precision:
                    self.test_dhv1("down")
                    startingValue = getDhv1Value()
                    log("Driving dhv1 to down ...")
                    sics.execute("dhv1 down")
                    time.sleep(1)

                if not self.bs is None:
                    selBs(self.bs)

                if startingValue > precision:
                    time_count = 0
                    time_out = 6
                    while getDhv1Value() == startingValue and time_count < time_out:
                        time.sleep(0.5)
                        time_count += 0.5
                    if getDhv1Value() == startingValue:
                        raise Exception, "failed to start dropping dhv1"
                    time_count = 0
                    time_out = 300
                    while getDhv1Value() > precision and time_count < time_out:
                        time.sleep(0.5)
                        time_count += 0.5
                    if getDhv1Value() > precision:
                        raise Exception, "time out dropping dhv1"
                    log("dhv1 is now down")

                ########### below drive det and other motors ###########
                self.multi_drive()

                ########### below code raise dhv1 and drive guide together ###########
                self.test_dhv1("up")
                startingValue = getDhv1Value()
                log("Driving dhv1 to up ...")
                sics.execute("dhv1 up")
                time.sleep(1)
                if self.need_drive_guide():
                    driveGuide(self.guide)
                time_count = 0
                time_out = 6
                while getDhv1Value() == startingValue and time_count < time_out:
                    time.sleep(0.5)
                    time_count += 0.5
                if getDhv1Value() == startingValue:
                    raise Exception, "failed to start raising dhv1"
                time_count = 0
                time_out = 300
                while getDhv1Value() < 2350.0 - precision and time_count < time_out:
                    time.sleep(0.5)
                    time_count += 0.5
                if getDhv1Value() < 2350.0 - precision:
                    raise Exception, "time out raising dhv1"
                log("dhv1 is now up")

                self.multi_set()
            else:
                if not self.bs is None:
                    selBs(self.bs)
                if self.need_drive_guide():
                    driveGuide(self.guide)
                self.multi_drive()
                self.multi_set()
        finally:
            self.clear()
        while sics.getStatus() != "EAGER TO EXECUTE":
            time.sleep(0.3)
        sics.handleInterrupt()
        log("configuration is finished")
Example #17
0
    def drive(self):
        if self.__is_dirty__:
            driveAtt(330)
        else:
            return
        try:
            sics.clearInterrupt()
            log('starting configuration')
            if self.need_drive_det():

                ########### below code drop dhv1 and select beam stop together ###########
                precision = 20
                safe_voltage = 800
                working_voltage = 2100
                startingValue = getDhv1()
                if startingValue > safe_voltage:
                    self.test_dhv1('down')
                    startingValue = getDhv1()
                    log('Driving dhv1 to down ...')
                    sics.execute('dhv1 down')
                    time.sleep(1)

                if not self.bs is None:
                    selBs(self.bs)

                if startingValue > safe_voltage:
                    time_count = 0
                    time_out = 30
                    while getDhv1() == startingValue and time_count < time_out:
                        time.sleep(0.5)
                        time_count += 0.5
                    if getDhv1() == startingValue:
                        raise Exception, 'failed to start dropping dhv1'
                    time_count = 0
                    time_out = 600
                    while getDhv1() > safe_voltage and time_count < time_out:
                        time.sleep(0.5)
                        time_count += 0.5
                    if getDhv1() > safe_voltage:
                        raise Exception, 'time out dropping dhv1'
                    log('dhv1 is now down')

                ########### below drive det and other motors ###########
                self.multi_drive()

                ########### below code raise dhv1 and drive guide together ###########
                self.test_dhv1('up')
                startingValue = getDhv1()
                log('Driving dhv1 to up ...')
                sics.execute('dhv1 up')
                time.sleep(1)
                if self.need_drive_guide():
                    driveGuide(self.guide)
                time_count = 0
                time_out = 30
                while getDhv1() == startingValue and time_count < time_out:
                    time.sleep(0.5)
                    time_count += 0.5
                if getDhv1() == startingValue:
                    raise Exception, 'failed to start raising dhv1'
                time_count = 0
                time_out = 600
                while getDhv1() < working_voltage and time_count < time_out:
                    time.sleep(0.5)
                    time_count += 0.5
                if getDhv1() < working_voltage:
                    raise Exception, 'time out raising dhv1'
                log('dhv1 is now up')

                self.multi_set()
            else:
                if not self.bs is None:
                    selBs(self.bs)
                if self.need_drive_guide():
                    driveGuide(self.guide)
                self.multi_drive()
                self.multi_set()
        finally:
            self.clear()
        while sics.getStatus() != 'EAGER TO EXECUTE':
            time.sleep(0.3)
        sics.handleInterrupt()
        log('configuration is finished')
Example #18
0
def run_action(act):
    act.set_running_status()
    try:
        exec(act.command)
        act.set_done_status()
    except Exception, e:
        if sics.getSicsController() != None:
            act.set_interrupt_status()
        raise Exception, e.message
    except:
        act.set_error_status()
        traceback.print_exc(file=sys.stdout)
        raise Exception, 'Error in running <' + act.text + '>'
    if sics.getSicsController() != None:
        sics.handleInterrupt()


def get_prof_value(name):
    value = __UI__.getPreference(name)
    if value == None:
        value = ''
    else:
        value = str(value)
    return value


def set_prof_value(name, value):
    if value == None:
        value = ''
    __UI__.setPreference(name, value)
Example #19
0
 def drive(self):
     if self.__is_dirty__ :
         driveAtt(330)
     else:
         return
     try:
         sics.clearInterrupt()
         log('starting configuration')
         if self.need_drive_det():
             
             ########### below code drop dhv1 and select beam stop together ###########
             precision = 20
             safe_voltage = 800
             working_voltage = 2100
             startingValue = getDhv1Value()
             if startingValue > safe_voltage:
                 self.test_dhv1('down')
                 startingValue = getDhv1Value()
                 log('Driving dhv1 to down ...')
                 sics.execute('dhv1 down')
                 time.sleep(1)
                 
             if not self.bs is None:
                 selBs(self.bs)
             
             if startingValue > safe_voltage:
                 time_count = 0
                 time_out = 30
                 while getDhv1Value() == startingValue and time_count < time_out:
                     time.sleep(0.5)
                     time_count += 0.5
                 if getDhv1Value() == startingValue :
                     raise Exception, 'failed to start dropping dhv1'
                 time_count = 0
                 time_out = 600
                 while getDhv1Value() > safe_voltage and time_count < time_out:
                     time.sleep(0.5)
                     time_count += 0.5
                 if getDhv1Value() > safe_voltage:
                     raise Exception, 'time out dropping dhv1'
                 log('dhv1 is now down')
             
             ########### below drive det and other motors ###########
             self.multi_drive()
             
             ########### below code raise dhv1 and drive guide together ###########
             self.test_dhv1('up')
             startingValue = getDhv1Value()
             log('Driving dhv1 to up ...')
             sics.execute('dhv1 up')
             time.sleep(1)
             if self.need_drive_guide():
                 driveGuide(self.guide)
             time_count = 0
             time_out = 30
             while getDhv1Value() == startingValue and time_count < time_out:
                 time.sleep(0.5)
                 time_count += 0.5
             if getDhv1Value() == startingValue :
                 raise Exception, 'failed to start raising dhv1'
             time_count = 0
             time_out = 600
             while getDhv1Value() < working_voltage and time_count < time_out:
                 time.sleep(0.5)
                 time_count += 0.5
             if getDhv1Value() < working_voltage :
                 raise Exception, 'time out raising dhv1'
             log('dhv1 is now up')
             
             self.multi_set()
         else:
             if not self.bs is None:
                 selBs(self.bs)
             if self.need_drive_guide():
                 driveGuide(self.guide)
             self.multi_drive()
             self.multi_set()
     finally:
         self.clear()
     while sics.getStatus() != 'EAGER TO EXECUTE':
         time.sleep(0.3)
     sics.handleInterrupt()
     log('configuration is finished')