Exemplo n.º 1
0
def AD_acquire(detsyms, filename, counttime, frames=1, wait=False):
    """Set parameters for an area detector and collect image(s)
    
    :param object detsyms: An area detector variable (or name as a string), as defined in
      :func:`DefineAreaDetector`. Alternately, a list of area detectors variable or names
      (as strings) can be supplied.
    :param str filename: The name of the data file to be used
    :param float counttime: The data collection pre frame time to be used (sec)
    :param int frames: The number of images to be recorded
    :param bool wait: If False (default) return immediately; if True, return after
      waiting the appropriate amount of time and 
      when the ``state`` command (if defined) indicates the data collection is done.
      
    """
    # set the PV's
    AD_set(detsyms,'filename',filename)
    AD_set(detsyms,'acquire_time',counttime)
    AD_set(detsyms,'frames',frames)
    spec.sleep(0.01)
    # for Retiga, transfer the values from EPICS to the device, for others this will be ignored
    AD_set(detsyms,'transfer',1,ignoreOK=True)
    spec.sleep(0.01)
    # start the acquisition
    AD_set(detsyms,'acquire',1)
    if not wait: return
    # wait for the detectors to finish
    AD_done(detsyms,wait=True)
Exemplo n.º 2
0
def AD_done(detsyms,wait=True):
    """Test and optionally wait for the detector(s) have completed data collection

    :param object detsyms: An area detector variable (or name as a string), as defined in
      :func:`DefineAreaDetector`. Alternately, a list of area detectors variable or names
      (as strings) can be supplied.
    :param bool wait: If False test and return immediately; if True (default), return
      after the ``state`` command (if defined) indicates the data collection is done
      for each detector.

    :returns: True if all detector(s) are done; False is wait is False and any detectors are
      not done; or None if after 30 seconds, any detector is not complete
    """
    # is the detector specified as a string? 
    if isinstance(detsyms,str): detsyms = tuple((detsyms,))
    # is there a list of detectors?
    try:
        symList = tuple(detsyms)
    except TypeError:
        symList = tuple((detsyms,))
    alldone = True
    sleeptime = 0.0
    for sym in symList:
        detObj = globals().get(sym)
        if detObj is None: detObj = sym
        if not isinstance(detObj,_ADobject):
            raise spec.specException('AD_done error: detsyms '+str(sym)+' is not defined in DefineAreaDetector')
        # get cmdObj of correct type for the current detector ==============================
        for cmdObj in CommandDict['state']:
            if cmdObj.detectortype is None: break #  this a generic command
            if cmdObj.detectortype == detObj.detectortype: break # matches selected device
        else:
            continue
        if cmdObj.readstr == "": continue
        if cmdObj.useImagePrefix:
            PV = detObj.imageprefix + cmdObj.readstr
        else:
            PV = detObj.controlprefix + cmdObj.readstr
        if not (EPICS and spec.UseEPICS()): # in simulation
            print("Confirming detector "+detObj.symbol+" is done with collection")
            continue
        else:
            val = ep.caget(PV)
            if val == 0: continue # detector has completed
            if not wait: return False
            # detector is not done and a wait is requested
            while val != 0:
                if sleeptime > 30.0:
                    print('AD_done wait exceeded count*frames+30 seconds for'+detObj.symbol+', continuing with script')
                    return
                spec.sleep(0.1)
                sleeptime += 0.1
                val = ep.caget(PV)
    # all detector(s) have signed off as done
    return True
Exemplo n.º 3
0
def PUP_AFRL_Oct13_hydra1(SetupOptionList):
    spec.EnableEPICS()      # TEMP - WHERE THIS HAPPENS NEED TO BE DETERMINED
        
    AD1id.DTHInitialize(SetupOptionList['DetList'], TrigMode=0)
    print '==========================================='
    print 'Active Detector List'
    print '==========================================='
    AD1id.PrintDetList(SetupOptionList)
    print '==========================================='
    
    AD1id.HydraInitialize(SetupOptionList)
    AD1id.DTHInitialize(SetupOptionList['DetList'], TrigMode=0)
    SetupOptionList['DetDelay'] = 0.0
    
    print '==========================================='
    print 'Next file paths:   '
    AD1id.GetPathName(SetupOptionList['DetList'])
    print 'Next file names:   '
    AD1id.GetFileName(SetupOptionList['DetList'])
    print 'Next file formats: '
    AD1id.GetFileNameFormat(SetupOptionList['DetList'])
    print 'Next file numbers: '
    AD1id.GetFileNumber(SetupOptionList['DetList'])
    print '==========================================='
    AD1id.SetAutoStore(SetupOptionList['DetList'], YesOrNo=1)
    AD1id.SetAcquisitionType(SetupOptionList['DetList'], AcqType=2)
    AD1id.SetNumFrames(SetupOptionList['DetList'], numFrames=1)
    print '==========================================='

    # SetupOptionList['ParFile'] = 'PUP_AFRL_Oct13_FF.par'                      # SET THIS OUTSIDE
    # SetupOptionList['FastParFile'] = 'FS_PUP_AFRL_Oct13_FF.par'               # SET THIS OUTSIDE
    
    hookup1id.SetEHutch(SetupOptionList, OpMode = 1)
    sweepcore1id.SetHydra(SetupOptionList, OpMode = 1)
    
    ## CHECK THIS / THIS IS ALREADY SET
    print SetupOptionList['FrameSignalPV']
    print SetupOptionList['DetPulsePV']
    SetupOptionList['FrameSignalPV'] = SetupOptionList['DetPulsePV']
    
    fpga1id.FS_GE2SEControl()
    
    SetupOptionList['OscThreshold'] = -1
    SetupOptionList['DefaultGapTime'] = 0.150
    
    spec.sleep(SetupOptionList['EpicsDelay'])
    
    ## CHECK THIS
    # sync
    ## CHECK THIS
    # printOscGlobals
    return SetupOptionList
Exemplo n.º 4
0
        if not (EPICS and spec.UseEPICS()): # in simulation
            print("For "+detObj.symbol+", setting PV="+str(PV)+' to '+str(val))
            global pvSim
            pvSim[PV] = val
            pvSim[PV+'_RBV'] = val
            continue
        if isinstance(val,str):
            # add a \0 to the string, since EPICS does not seem to handle 
            # this correctly otherwise for some clients
            ep.caput(PV,val + '\0')
        else:
            ep.caput(PV,val)
        # now validate that the setting has been completed
        if cmdObj.valtyp == float and rPV != "":
            spec.sleep(0.05)
            setVal = ep.caget(rPV)
            i = 0
            while not np.allclose(setVal,val):
                i += 1
                if i > spec.MAX_RETRIES:
                    print("Warning: For "+detObj.symbol+", unable to set PV="+str(PV)+' to '+str(val))
                    break
                spec.sleep(0.1)
                setVal = ep.caget(rPV)
        elif  cmdObj.valtyp == str and rPV != "":
            setVal = None
            i = 0
            while setVal != val:
                if i > spec.MAX_RETRIES:
                    print("Warning: For "+detObj.symbol+", unable to set PV="+str(PV)+' to '+str(val))