Example #1
0
def scanRoutine():
    "This is the scan routine"
    pvscan.printMsg('Starting')
    sleep(0.5) # Collect some initial data first
    # Grab images of the sample
    if grab0.grabFlag:
        grab0.grabImages(5)
    # Close pump and HeNe shutters, but only if enabled from PV.
    if shutter2.enabled:
        pvscan.printMsg('Closing pump shutter')
        shutter2.close.put(1)
    if shutter3.enabled:
        pvscan.printMsg('Closing HeNe shutter')
        shutter3.close.put(1)
    # Set all shutters to fast mode
    pvscan.shutterFunction(shutterGroup1.fast,1)
    sleep(0.5)
    # Make sure shutters are closed
    #pvscan.shutterCheck(shutterRBVPVList)
    # Do motor scan
    motorScan(motor1,motor2,motor3,grab1,radius,radius2,resetMotorPv)
    # Close pump and HeNe shutters, but only if enabled from PV.
    if shutter2.enabled:
        pvscan.printMsg('Closing pump shutter')
        shutter2.close.put(1)
    if shutter3.enabled:
        pvscan.printMsg('Closing HeNe shutter')
        shutter3.close.put(1)
Example #2
0
def scanRoutine():
    "This is the scan routine"
    # Print scan info
    pvscan.printScanInfo(exp, exp.scanpvs)
    pvscan.printMsg('Starting')
    sleep(0.5)  # Collect some initial data first
    # Scan delay stage and grab images...
    pvscan.pvNDScan(exp, exp.scanpvs, exp.grabber, exp.shutters)
Example #3
0
def scanRoutine():
    "This is the scan routine"
    # Print scan info
    pvscan.printScanInfo(exp1,scanPv1,scanPv2)
    pvscan.printMsg('Starting')
    # Open all shutters, but only if enabled from PV.
    shutterGroup1.open() 
    # Do WDM PV Scan
    wdmScan(exp1,scanPv1,scanPv2,scanPv3,scanPv4,grab2)
    # Close all shutters, but only if enabled from PV.
    shutterGroup1.close(0)
Example #4
0
def scanRoutine():
    "This is the scan routine"
    # Print scan info
    pvscan.printScanInfo(exp1, scanPv1, scanPv2)
    pvscan.printMsg('Starting')
    # Open all shutters, but only if enabled from PV.
    shutterGroup1.open()
    # Do WDM PV Scan
    wdmScan(exp1, scanPv1, scanPv2, scanPv3, scanPv4, grab2)
    # Close all shutters, but only if enabled from PV.
    shutterGroup1.close(0)
Example #5
0
def grabSampleImages(filenameExtras, when=""):
    # Turn LED on
    pvscan.printMsg("Turning Sample LED on")
    LedPv.put(1)
    sleep(0.5)
    # Grab some images
    grab1.filenameExtras = filenameExtras + when
    grab1.grabImages()
    # Turn LED off
    pvscan.printMsg("Turning Sample LED off")
    LedPv.put(0)
    sleep(0.5)
Example #6
0
def grabSampleImages(filenameExtras, when=''):
    # Turn LED on
    pvscan.printMsg('Turning Sample LED on')
    LedPv.put(1)
    sleep(0.5)
    # Grab some images
    grab1.filenameExtras = filenameExtras + when
    grab1.grabImages()
    # Turn LED off
    pvscan.printMsg('Turning Sample LED off')
    LedPv.put(0)
    sleep(0.5)
Example #7
0
def scanRoutine():
    "This is the scan routine"
    # Print scan info
    pvscan.printScanInfo(exp1,scanPv1,scanPv2)
    pvscan.printMsg('Starting')
    sleep(0.5) # Collect some initial data first
    # Open all shutters, but only if enabled from PV.
    shutterGroup1.open()
    #shutter1.openCheck()
    # Scan delay stage and grab images...
    pvscan.pvNDScan(exp1,scanPv1,scanPv2,grab1,shutter1,shutter2,shutter3)
    # Close all shutters, but only if enabled from PV.
    shutterGroup1.close(0)
def abortRoutine():
    "This is the abort routine"
    pvscan.printMsg('Aborting')
    # Stop motors
    pvscan.printMsg('Stopping motors')
    motor1.abort.put(1)
    # Kill scan routine process
    pvscan.printMsg('Killing process %d...' % (pid))
    os.kill(pid, signal.SIGKILL)
    # Disable shutters
    #pvscan.printMsg('Disabling shutters')
    #pvscan.shutterFunction(shutterGroup1.ttlInDisable,0)
    #sleep(0.5)
    # Close shutters
    pvscan.printMsg('Closing shutters')
    pvscan.shutterFunction(shutterGroup1.close,0)
    pvscan.printMsg('Aborted')
Example #9
0
def abortRoutine():
    "This is the abort routine"
    pvscan.printMsg('Aborting')
    # Stop motors
    pvscan.printMsg('Stopping motors')
    motor1.abort.put(1)
    # Kill scan routine process
    pvscan.printMsg('Killing process %d...' % (pid))
    os.kill(pid, signal.SIGKILL)
    # Disable shutters
    #pvscan.printMsg('Disabling shutters')
    #pvscan.shutterFunction(shutterGroup1.ttlInDisable,0)
    #sleep(0.5)
    # Close shutters
    pvscan.printMsg('Closing shutters')
    pvscan.shutterFunction(shutterGroup1.close, 0)
    pvscan.printMsg('Aborted')
Example #10
0
def abortRoutine():
    "This is the abort routine"
    # Kill scan routine process
    pvscan.printMsg('Killing process %d...' % (pid))
    os.kill(pid, signal.SIGKILL)
    # Stop the wrapper script
    pvscan.printMsg('Stopping wrapper script')
    runFlagPv.put(0)
    # Stop move(s)
    pvscan.printMsg('Stopping move(s)')
    if scanPv1.scanpv:
        if scanPv1.scanpv.abort:
            scanPv1.scanpv.abort.put(1)
    if scanPv2.scanpv:
        if scanPv2.scanpv.abort:
            scanPv2.scanpv.abort.put(1)
    # Close shutters if enabled from PV
    pvscan.printMsg('Closing shutters')
    shutterGroup1.close(0)
    pvscan.printMsg('Aborted')
Example #11
0
def scanRoutine():
    "This is the scan routine"
    pvscan.printMsg('Starting')
    sleep(0.5) # Collect some initial data first
    # Open shutters
    pvscan.printMsg('Opening shutters')
    pvscan.shutterFunction(shutterGroup1.open,1)
    # Scan delay stage and grab images...
    pvscan.Motor.motor1DScan(motor1,grab1)
    #pvscan.Motor.pv1DScan(motor1,grab1)
    # Close shutters
    pvscan.printMsg('Closing shutters')
    pvscan.shutterFunction(shutterGroup1.close,0)
    pvscan.printMsg('Done')
Example #12
0
def scanRoutine():
    "This is the scan routine"
    pvscan.printMsg('Starting')
    sleep(0.5)  # Collect some initial data first
    # Open shutters
    pvscan.printMsg('Opening shutters')
    pvscan.shutterFunction(shutterGroup1.open, 1)
    # Scan delay stage and grab images...
    pvscan.Motor.motor1DScan(motor1, grab1)
    #pvscan.Motor.pv1DScan(motor1,grab1)
    # Close shutters
    pvscan.printMsg('Closing shutters')
    pvscan.shutterFunction(shutterGroup1.close, 0)
    pvscan.printMsg('Done')
Example #13
0
def wdmGrabRoutine(filenameExtras=''):
    # Grab sample images if enabled from PV
    if grabSampleImagesFlag:
        grabSampleImages(filenameExtras, when='_before')
    # Grab images of beam in separate thread, if enabled from PV
    if ssBeamFlag:
        grab2.filenameExtras = filenameExtras + '_beam'
        grab2Thread = Thread(target=grab2.grabImages, args=())
        grab2Thread.start()
        #sleep(waitTime/2.0)
        # Single shot of beam only
        pvscan.printMsg('Getting single shot of beam')
        subprocess.call(
            '/afs/slac/g/testfac/extras/scripts/asta/singleShotUED-test.py ' +
            pvPrefix + ' beam',
            shell=True)
        # Wait for image grabbing to finish
        grab2Thread.join()
        # Wait for capturing to finish
        while grab2.captureRBVPv.get() or grab2.writingRBVPv.get():
            sleep(0.1)
    # Grab images of pump in separate thread, if enabled from PV
    if ssBeamPumpFlag:
        # Close sample cam shutter (0=open, 1=close)
        pvscan.printMsg('Closing sample cam shutter')
        sampleCamShutterPv.put(1)
        grab2.filenameExtras = filenameExtras + '_beam_pump'
        grab2Thread = Thread(target=grab2.grabImages, args=())
        grab2Thread.start()
        #sleep(waitTime/2.0)
        # Single shot of beam and pump
        pvscan.printMsg('Getting single shot of beam and pump')
        subprocess.call(
            '/afs/slac/g/testfac/extras/scripts/asta/singleShotUED-test.py ' +
            pvPrefix + ' beam-pump',
            shell=True)
        grab2Thread.join()
        while grab2.captureRBVPv.get() or grab2.writingRBVPv.get():
            sleep(0.1)
        # Open sample cam shutter (0=open, 1=close)
        pvscan.printMsg('Opening sample cam shutter')
        sampleCamShutterPv.put(0)
    # Grab sample images if enabled from PV
    if grabSampleImagesFlag:
        grabSampleImages(filenameExtras, when='_after')
Example #14
0
def abortRoutine():
    "This is the abort routine"
    # Kill scan routine process
    pvscan.printMsg('Killing process %d...' % (pid))
    os.kill(pid, signal.SIGKILL)
    # Stop move(s)
    pvscan.printMsg('Stopping move(s)')
    if scanPv1.scanpv:
        if scanPv1.scanpv.abort:
            scanPv1.scanpv.abort.put(1)
    if scanPv2.scanpv:
        if scanPv2.scanpv.abort:
            scanPv2.scanpv.abort.put(1)
    #sleep(0.5)
    # Close shutters if enabled from PV
    pvscan.printMsg('Closing shutters')
    shutterGroup1.close(0)
    pvscan.printMsg('Aborted')
Example #15
0
def wdmGrabRoutine(filenameExtras=""):
    # Grab sample images if enabled from PV
    if grabSampleImagesFlag:
        grabSampleImages(filenameExtras, when="_before")
    # Grab images of beam in separate thread, if enabled from PV
    if ssBeamFlag:
        grab2.filenameExtras = filenameExtras + "_beam"
        grab2Thread = Thread(target=grab2.grabImages, args=())
        grab2Thread.start()
        # sleep(waitTime/2.0)
        # Single shot of beam only
        pvscan.printMsg("Getting single shot of beam")
        subprocess.call(
            "/afs/slac/g/testfac/extras/scripts/asta/singleShotUED-test.py " + pvPrefix + " beam", shell=True
        )
        # Wait for image grabbing to finish
        grab2Thread.join()
        # Wait for capturing to finish
        while grab2.captureRBVPv.get() or grab2.writingRBVPv.get():
            sleep(0.1)
    # Grab images of pump in separate thread, if enabled from PV
    if ssBeamPumpFlag:
        # Close sample cam shutter (0=open, 1=close)
        pvscan.printMsg("Closing sample cam shutter")
        sampleCamShutterPv.put(1)
        grab2.filenameExtras = filenameExtras + "_beam_pump"
        grab2Thread = Thread(target=grab2.grabImages, args=())
        grab2Thread.start()
        # sleep(waitTime/2.0)
        # Single shot of beam and pump
        pvscan.printMsg("Getting single shot of beam and pump")
        subprocess.call(
            "/afs/slac/g/testfac/extras/scripts/asta/singleShotUED-test.py " + pvPrefix + " beam-pump", shell=True
        )
        grab2Thread.join()
        while grab2.captureRBVPv.get() or grab2.writingRBVPv.get():
            sleep(0.1)
        # Open sample cam shutter (0=open, 1=close)
        pvscan.printMsg("Opening sample cam shutter")
        sampleCamShutterPv.put(0)
    # Grab sample images if enabled from PV
    if grabSampleImagesFlag:
        grabSampleImages(filenameExtras, when="_after")
Example #16
0
def wdmGrabRoutine(filenameExtras=''):
    # Grab sample images if enabled from PV
    if grabSampleImagesFlag:
        grabSampleImages(filenameExtras, when='_before')
    # Grab images of beam in separate thread, if enabled from PV
    if ssBeamFlag:
        grab2.filenameExtras=filenameExtras + '_beam'
        grab2Thread=Thread(target=grab2.grabImages,args=())
        grab2Thread.start()
        # Single shot of beam only
        pvscan.printMsg('Getting single shot of beam')
        subprocess.call('/afs/slac/g/testfac/extras/scripts/asta/singleShotUED.py ' + pvPrefix + ' beam', shell=True)
        # Wait for image grabbing to finish
        grab2Thread.join()
        # Wait for capturing to finish
        while grab2.captureRBVPv.get() or grab2.writingRBVPv.get():
            sleep(0.1)
    # Grab images of beam/pump in separate thread, if enabled from PV
    if ssBeamPumpFlag:
        # Close sample cam shutter (0=open, 1=close)
        pvscan.printMsg('Closing sample cam shutter')
        sampleCamShutterPv.put(1)
        grab2.filenameExtras=filenameExtras + '_beam_pump'
        grab2Thread=Thread(target=grab2.grabImages,args=())
        grab2Thread.start()
        # Single shot of beam and pump
        pvscan.printMsg('Getting single shot of beam and pump')
        subprocess.call('/afs/slac/g/testfac/extras/scripts/asta/singleShotUED.py ' + pvPrefix + ' beam-pump', shell=True)
        grab2Thread.join()
        while grab2.captureRBVPv.get() or grab2.writingRBVPv.get():
            sleep(0.1)
        # Open sample cam shutter (0=open, 1=close)
        pvscan.printMsg('Opening sample cam shutter')
        sampleCamShutterPv.put(1)
        #sleep(grab2.nImages*0.5)
    # Grab sample images if enabled from PV
    if grabSampleImagesFlag:
        grabSampleImages(filenameExtras, when='_after')
Example #17
0
def motorScan(motor1,motor2,motor3,grabObject='',radius=0,resetFlag=0,resetMotorPv=''):
    "Scans motor1 from start to stop in n steps, moving motors 2 and 3 and doing a reset loop at each step."
    initialPos1=motor1.get()
    initialPos2=motor2.get()
    initialPos3=motor3.get()
    pvscan.printMsg('Starting motor scan')
    inc=(motor1.stop-motor1.start)/(motor1.nsteps-1)
    for i in range(motor1.nsteps):
        # Move motor 1
        newPos0=motor1.start + i*inc
        newPos1=newPos0 + motor1.offset
        pvscan.printMsg('Moving %s to %f' % (motor1.pvname,newPos1))
        motor1.move(newPos1,timeout=300)
        # Move motor 2
        newPos2=motor2.offset + radius*math.cos(newPos0*math.pi/180)
        pvscan.printMsg('Moving %s to %f' % (motor2.pvname,newPos2))
        motor2.move(newPos2)
        # Move motor 3
        newPos3=motor3.offset + radius*math.sin(newPos0*math.pi/180)
        pvscan.printMsg('Moving %s to %f' % (motor3.pvname,newPos3))
        motor3.move(newPos3)
        pvscan.printSleep(motor1.settletime,'Settling')
        # Do reset loop if resetFlag==1
        if resetFlag:
            resetLoop(grabObject,resetMotorPv)
    # Move motors back to initial positions
    pvscan.printMsg('Moving %s back to initial position: %f' %(motor1.pvname,initialPos1))
    motor1.move(initialPos1)
    pvscan.printMsg('Moving %s back to initial position: %f' %(motor2.pvname,initialPos2))
    motor2.move(initialPos2)
    pvscan.printMsg('Moving %s back to initial position: %f' %(motor3.pvname,initialPos3))
    motor3.move(initialPos3)
Example #18
0
### Main program ##########################################################3

if __name__ == "__main__":
    "Do scan routine; log PV data to file as a separate thread if enabled"
    try:
        args='PV_PREFIX'
        def show_usage():
            "Prints usage"
            print 'Usage: %s %s' %(sys.argv[0], args)
        if len(sys.argv) != 2:
            show_usage()
            sys.exit(1)
        pid=os.getpid()
        pvscan.pidPV.put(pid)
        if dataLog1.dataEnable:
            # Start logging data
            dataLog1.start()
        scanRoutine()
        sleep(1) # Log data for a little longer
    finally:
        # Stop logging data
        dataLog1.stop()
        pvscan.printMsg('Done')

        
### End ##########################################################################
        

exit

Example #19
0
def wdmScan(exp, pv1, pv2, pv3, pv4, grabObject=""):
    if 1 <= exp.scanmode <= 2 and pv2.scanpv and not pv1.scanpv:
        pv1 = pv2
        exp.scanmode = 1
    if 1 <= exp.scanmode <= 2 and pv1.scanpv:
        initialPos1 = pv1.scanpv.get()
        inc1 = (pv1.scanpv.stop - pv1.scanpv.start) / (pv1.scanpv.nsteps - 1)
        if zLockFlag:
            initialPos3 = pv3.scanpv.get()
        if yLockFlag:
            initialPos4 = pv4.scanpv.get()
        if exp.scanmode == 2 and pv2.scanpv:
            initialPos2 = pv2.scanpv.get()
            inc2 = (pv2.scanpv.stop - pv2.scanpv.start) / (pv2.scanpv.nsteps - 1)
        pvscan.printMsg(
            "Scanning %s from %f to %f in %d steps"
            % (pv1.scanpv.pvname, pv1.scanpv.start, pv1.scanpv.stop, pv1.scanpv.nsteps)
        )
        for i in range(pv1.scanpv.nsteps):
            newPos1 = pv1.scanpv.start + i * inc1
            pvscan.printMsg("Setting %s to %f" % (pv1.scanpv.pvname, newPos1))
            pv1.scanpv.move(newPos1, delta=delta)
            if zLockFlag:
                newPos3 = zSlope * newPos1 + zIntercept
                pvscan.printMsg("Setting %s to %f" % (pv3.scanpv.pvname, newPos3))
                pv3.scanpv.move(newPos3, delta=delta)
            if yLockFlag:
                newPos4 = ySlope * newPos1 + yIntercept
                pvscan.printMsg("Setting %s to %f" % (pv4.scanpv.pvname, newPos4))
                pv4.scanpv.move(newPos4, delta=delta)
            pvscan.printSleep(pv1.scanpv.settletime, "Settling")
            if exp.scanmode == 2 and pv2.scanpv:
                pvscan.printMsg(
                    "Scanning %s from %f to %f in %d steps"
                    % (pv2.scanpv.pvname, pv2.scanpv.start, pv2.scanpv.stop, pv2.scanpv.nsteps)
                )
                for i in range(pv2.scanpv.nsteps):
                    newPos2 = pv2.scanpv.start + i * inc2
                    pvscan.printMsg("Setting %s to %f" % (pv2.scanpv.pvname, newPos2))
                    pv2.scanpv.move(newPos2, delta=delta)
                    pvscan.printSleep(pv2.scanpv.settletime, "Settling")
                    if grabObject:
                        if grabObject.grabFlag:
                            if grabObject.stepFlag:
                                grabObject.filenameExtras = (
                                    "_"
                                    + pv1.scanpv.desc
                                    + "-"
                                    + "{0:03d}".format(i + 1)
                                    + "-"
                                    + "{0:08.4f}".format(pv1.scanpv.get())
                                    + "_"
                                    + pv2.scanpv.desc
                                    + "-"
                                    + "{0:03d}".format(j + 1)
                                    + "-"
                                    + "{0:08.4f}".format(pv2.scanpv.get())
                                )
                            else:
                                grabObject.filenameExtras = (
                                    "_"
                                    + pv1.scanpv.desc
                                    + "-"
                                    + "{0:08.4f}".format(pv1.scanpv.get())
                                    + "_"
                                    + pv2.scanpv.desc
                                    + "-"
                                    + "{0:08.4f}".format(pv2.scanpv.get())
                                )
                            if multiStaticFlag:
                                wdmGrabRoutine2(grabObject.filenameExtras)
                            else:
                                wdmGrabRoutine(grabObject.filenameExtras)
            else:
                if grabObject:
                    if grabObject.grabFlag:
                        if grabObject.stepFlag:
                            grabObject.filenameExtras = (
                                "_"
                                + pv1.scanpv.desc
                                + "-"
                                + "{0:03d}".format(i + 1)
                                + "-"
                                + "{0:08.4f}".format(pv1.scanpv.get())
                            )
                        else:
                            grabObject.filenameExtras = (
                                "_" + pv1.scanpv.desc + "-" + "{0:08.4f}".format(pv1.scanpv.get())
                            )
                        if multiStaticFlag:
                            wdmGrabRoutine2(grabObject.filenameExtras)
                        else:
                            wdmGrabRoutine(grabObject.filenameExtras)
        # Move back to initial positions
        pvscan.printMsg("Setting %s back to initial position: %f" % (pv1.scanpv.pvname, initialPos1))
        pv1.scanpv.move(initialPos1, delta=delta)
        if zLockFlag:
            pvscan.printMsg("Setting %s back to initial position: %f" % (pv3.scanpv.pvname, initialPos3))
            pv3.scanpv.move(initialPos3, delta=delta)
        if yLockFlag:
            pvscan.printMsg("Setting %s back to initial position: %f" % (pv4.scanpv.pvname, initialPos4))
            pv4.scanpv.move(initialPos4, delta=delta)
        if exp.scanmode == 2 and pv2.scanpv:
            pvscan.printMsg("Setting %s back to initial position: %f" % (pv2.scanpv.pvname, initialPos2))
            pv2.scanpv.move(initialPos2, delta=delta)
    elif exp.scanmode == 3:  # Grab images only
        if grabObject:
            if grabObject.grabFlag:
                grab1.grabImages()
                grab2.grabImages()
    elif exp.scanmode == 4:  # WDM grab routine only
        if multiStaticFlag:
            wdmGrabRoutine2(grabObject.filenameExtras)
        else:
            wdmGrabRoutine(grabObject.filenameExtras)

    else:
        pvscan.printMsg('Scan mode "None" selected or no PVs entered, continuing...')
        sleep(1)
Example #20
0
def wdmGrabRoutine2(filenameExtras=""):
    # --- Grab sample images if enabled from PV ----------------------------------------
    if grabSampleImagesFlag:
        grabSampleImages(filenameExtras, when="_before")
    # --- Grab background images -------------------------------------------------------
    # Make sure shutters are closed
    pvscan.printMsg("Closing all shutters")
    shutter1.close.put(0)
    shutter2.close.put(0)
    shutter3.close.put(0)
    sleep(0.5)
    grab2.filenameExtras = filenameExtras + "_BG"
    grab2.grabImages(3)
    # --- Grab images of beam if enabled from PV ---------------------------------------
    if ssBeamFlag:
        grab2.filenameExtras = filenameExtras + "_beam"
        # Open drive and master shutters
        pvscan.printMsg("Opening drive and master shutters")
        shutter1.open.put(1)
        shutter3.open.put(1)
        grab2.grabImages(nStaticImages)
        # Close drive and master shutters
        pvscan.printMsg("Closing drive and master shutters")
        shutter1.close.put(0)
        shutter3.close.put(0)
        sleep(0.5)
        # Wait for capturing to finish
        while grab2.captureRBVPv.get() or grab2.writingRBVPv.get():
            sleep(0.1)
    # --- Grab images of beam/pump in separate thread, if enabled from PV --------------
    if ssBeamPumpFlag:
        # Close sample cam shutter (0=open, 1=close)
        pvscan.printMsg("Closing sample cam shutter")
        sampleCamShutterPv.put(0)
        grab2.filenameExtras = filenameExtras + "_beam_pump"
        grab2Thread = Thread(target=grab2.grabImages, args=())
        grab2Thread.start()
        # shutter3.close.put(1)
        # shutter2.open.put(1)
        # sleep(waitTime/2.0)
        # Single shot of beam and pump
        pvscan.printMsg("Getting single shot of beam and pump")
        subprocess.call(
            "/afs/slac/g/testfac/extras/scripts/asta/singleShotUED-test.py " + pvPrefix + " beam-pump", shell=True
        )
        grab2Thread.join()
        while grab2.captureRBVPv.get() or grab2.writingRBVPv.get():
            sleep(0.1)
        # Open sample cam shutter (0=open, 1=close)
        pvscan.printMsg("Opening sample cam shutter")
        sampleCamShutterPv.put(1)
        sleep(0.5)
    # --- Grab sample images if enabled from PV ----------------------------------------
    if grabSampleImagesFlag:
        grabSampleImages(filenameExtras, when="_after")
Example #21
0
def scanRoutine():
    "This is the scan routine"
    pvscan.printMsg('Starting')
    sleep(0.5) # Collect some initial data first
    # Open all shutters, but only if enabled from PV.
    if shutter1.enabled:
        pvscan.printMsg('Opening drive shutter')
        shutter1.open.put(1)
    if shutter2.enabled:
        pvscan.printMsg('Opening pump shutter')
        shutter2.open.put(1)
    if shutter3.enabled:
        pvscan.printMsg('Opening shutter 3')
        shutter3.open.put(1)
    # Scan delay stage and grab images...
    pvscan.pv1DScan(scanPv1.scanpv,grab1)
    # Close all shutters, but only if enabled from PV.
    if shutter1.enabled:
        pvscan.printMsg('Closing drive shutter')
        shutter1.close.put(0)
    if shutter2.enabled:
        pvscan.printMsg('Closing pump shutter')
        shutter2.close.put(0)
    if shutter3.enabled:
        pvscan.printMsg('Closing shutter 3')
        shutter3.close.put(0)
    pvscan.printMsg('Done')
def abortRoutine():
    "This is the abort routine"
    # Kill scan routine process
    pvscan.printMsg('Killing process %d...' % (pid))
    os.kill(pid, signal.SIGKILL)
    # Stop the wrapper script
    pvscan.printMsg('Stopping wrapper script')
    runFlagPv.put(0)
    # Stop move(s)
    pvscan.printMsg('Stopping scan')
    try:
        for pv in exp.scanpvs:
            pv.abort.put(1)
    except AttributeError:
        'Warning: abortRoutine: AttributeError'
    # Shutters
    pvscan.printMsg('Returning shutters to initial state')
    for shutter in exp.shutters:
        shutter.abort()
    pvscan.printMsg('Aborting image grabbing')
    exp.grabber.abort()
    pvscan.printMsg('Aborted')
Example #23
0
### Main program ##########################################################3

if __name__ == "__main__":
    "Do scan routine; log PV data to file as a separate thread if enabled"
    try:
        args='PV_PREFIX'
        def show_usage():
            "Prints usage"
            print 'Usage: %s %s' %(sys.argv[0], args)
        if len(sys.argv) != 2:
            show_usage()
            sys.exit(1)
        pid=os.getpid()
        pvscan.pidPV.put(pid)
        if dataLog1.dataEnable:
            # Start logging data
            dataLog1.start()
        scanRoutine()
        sleep(1) # Log data for a little longer
    finally:
        # Stop logging data
        dataLog1.stop()
        pvscan.printMsg('Done')

        
### End ##########################################################################
        

exit

Example #24
0
def scanRoutine():
    "This is the scan routine"
    pvscan.printMsg('Starting')
    sleep(0.5)  # Collect some initial data first
    # Open all shutters, but only if enabled from PV.
    if shutter1.enabled:
        pvscan.printMsg('Opening drive shutter')
        shutter1.open.put(1)
    if shutter2.enabled:
        pvscan.printMsg('Opening pump shutter')
        shutter2.open.put(1)
    if shutter3.enabled:
        pvscan.printMsg('Opening shutter 3')
        shutter3.open.put(1)
    # Scan delay stage and grab images...
    pvscan.ScanPv.pv1DScan(scanPv1, grab1)
    # Close all shutters, but only if enabled from PV.
    if shutter1.enabled:
        pvscan.printMsg('Closing drive shutter')
        shutter1.close.put(1)
    if shutter2.enabled:
        pvscan.printMsg('Closing pump shutter')
        shutter2.close.put(1)
    if shutter3.enabled:
        pvscan.printMsg('Closing shutter 3')
        shutter3.close.put(1)
    pvscan.printMsg('Done')
Example #25
0
def resetLoop(grabObject='',resetMotorPv=''):
    "Does UED DAE reset routine."
    pvscan.printMsg('Starting reset loop')
    # Open drive laser shutter
    #shutter1.open.put(1)
    if shutter2.enabled:
        pvscan.printMsg('Opening pump shutter')
        shutter2.open.put(1)
    # Enable TTL In for HeNe shutter if enabled from PV. 
    if shutter3.enabled:
        pvscan.printMsg('Enabling TTL In for HeNe shutter')
        shutter3.ttlInEnable.put(1)
    pvscan.printSleep(0.5)
    if grabObject:
        if grabObject.grabFlag:
            grabObject.filenameExtras='_' + resetMotorPv.desc + '-' + '{0:08.4f}'.format(resetMotorPv.get())
            grabObject.grabImages()
    # Disable TTL In for HeNe shutter if enabled from PV. 
    if shutter3.enabled:
        pvscan.printMsg('Disabling TTL In for HeNe shutter')
        shutter3.ttlInDisable.put(0)
    # Close pump and HeNe shutters, but only if enabled from PV.
    if shutter2.enabled:
        pvscan.printMsg('Closing pump shutter')
        shutter2.close.put(0)
    if shutter3.enabled:
        pvscan.printMsg('Closing HeNe shutter')
        shutter3.close.put(0)
    pvscan.printMsg('Reset loop done')
Example #26
0
def wdmGrabRoutine2(filenameExtras=''):
    #--- Grab sample images if enabled from PV ----------------------------------------
    if grabSampleImagesFlag:
        grabSampleImages(filenameExtras, when='_before')
    #--- Grab background images -------------------------------------------------------
    # Make sure shutters are closed
    pvscan.printMsg('Closing all shutters')
    shutter1.close.put(0)
    shutter2.close.put(0)
    shutter3.close.put(0)
    sleep(0.5)
    grab2.filenameExtras = filenameExtras + '_BG'
    grab2.grabImages(3)
    #--- Grab images of beam if enabled from PV ---------------------------------------
    if ssBeamFlag:
        grab2.filenameExtras = filenameExtras + '_beam'
        # Open drive and master shutters
        pvscan.printMsg('Opening drive and master shutters')
        shutter1.open.put(1)
        shutter3.open.put(1)
        grab2.grabImages(nStaticImages)
        # Close drive and master shutters
        pvscan.printMsg('Closing drive and master shutters')
        shutter1.close.put(0)
        shutter3.close.put(0)
        sleep(0.5)
        # Wait for capturing to finish
        while grab2.captureRBVPv.get() or grab2.writingRBVPv.get():
            sleep(0.1)
    #--- Grab images of beam/pump in separate thread, if enabled from PV --------------
    if ssBeamPumpFlag:
        # Close sample cam shutter (0=open, 1=close)
        pvscan.printMsg('Closing sample cam shutter')
        sampleCamShutterPv.put(0)
        grab2.filenameExtras = filenameExtras + '_beam_pump'
        grab2Thread = Thread(target=grab2.grabImages, args=())
        grab2Thread.start()
        #shutter3.close.put(1)
        #shutter2.open.put(1)
        #sleep(waitTime/2.0)
        # Single shot of beam and pump
        pvscan.printMsg('Getting single shot of beam and pump')
        subprocess.call(
            '/afs/slac/g/testfac/extras/scripts/asta/singleShotUED-test.py ' +
            pvPrefix + ' beam-pump',
            shell=True)
        grab2Thread.join()
        while grab2.captureRBVPv.get() or grab2.writingRBVPv.get():
            sleep(0.1)
        # Open sample cam shutter (0=open, 1=close)
        pvscan.printMsg('Opening sample cam shutter')
        sampleCamShutterPv.put(1)
        sleep(0.5)
    #--- Grab sample images if enabled from PV ----------------------------------------
    if grabSampleImagesFlag:
        grabSampleImages(filenameExtras, when='_after')
Example #27
0
def wdmScan(exp, pv1, pv2, pv3, pv4, grabObject=''):
    if 1 <= exp.scanmode <= 2 and pv2.scanpv and not pv1.scanpv:
        pv1 = pv2
        exp.scanmode = 1
    if 1 <= exp.scanmode <= 2 and pv1.scanpv:
        initialPos1 = pv1.scanpv.get()
        inc1 = (pv1.scanpv.stop - pv1.scanpv.start) / (pv1.scanpv.nsteps - 1)
        if zLockFlag:
            initialPos3 = pv3.scanpv.get()
        if yLockFlag:
            initialPos4 = pv4.scanpv.get()
        if exp.scanmode == 2 and pv2.scanpv:
            initialPos2 = pv2.scanpv.get()
            inc2 = (pv2.scanpv.stop - pv2.scanpv.start) / (pv2.scanpv.nsteps -
                                                           1)
        pvscan.printMsg('Scanning %s from %f to %f in %d steps' %
                        (pv1.scanpv.pvname, pv1.scanpv.start, pv1.scanpv.stop,
                         pv1.scanpv.nsteps))
        for i in range(pv1.scanpv.nsteps):
            newPos1 = pv1.scanpv.start + i * inc1
            pvscan.printMsg('Setting %s to %f' % (pv1.scanpv.pvname, newPos1))
            pv1.scanpv.move(newPos1, delta=delta)
            if zLockFlag:
                newPos3 = zSlope * newPos1 + zIntercept
                pvscan.printMsg('Setting %s to %f' %
                                (pv3.scanpv.pvname, newPos3))
                pv3.scanpv.move(newPos3, delta=delta)
            if yLockFlag:
                newPos4 = ySlope * newPos1 + yIntercept
                pvscan.printMsg('Setting %s to %f' %
                                (pv4.scanpv.pvname, newPos4))
                pv4.scanpv.move(newPos4, delta=delta)
            pvscan.printSleep(pv1.scanpv.settletime, 'Settling')
            if exp.scanmode == 2 and pv2.scanpv:
                pvscan.printMsg('Scanning %s from %f to %f in %d steps' %
                                (pv2.scanpv.pvname, pv2.scanpv.start,
                                 pv2.scanpv.stop, pv2.scanpv.nsteps))
                for i in range(pv2.scanpv.nsteps):
                    newPos2 = pv2.scanpv.start + i * inc2
                    pvscan.printMsg('Setting %s to %f' %
                                    (pv2.scanpv.pvname, newPos2))
                    pv2.scanpv.move(newPos2, delta=delta)
                    pvscan.printSleep(pv2.scanpv.settletime, 'Settling')
                    if grabObject:
                        if grabObject.grabFlag:
                            if grabObject.stepFlag:
                                grabObject.filenameExtras = '_' + pv1.scanpv.desc + '-' + '{0:03d}'.format(
                                    i + 1
                                ) + '-' + '{0:08.4f}'.format(
                                    pv1.scanpv.get()
                                ) + '_' + pv2.scanpv.desc + '-' + '{0:03d}'.format(
                                    j + 1) + '-' + '{0:08.4f}'.format(
                                        pv2.scanpv.get())
                            else:
                                grabObject.filenameExtras = '_' + pv1.scanpv.desc + '-' + '{0:08.4f}'.format(
                                    pv1.scanpv.get()
                                ) + '_' + pv2.scanpv.desc + '-' + '{0:08.4f}'.format(
                                    pv2.scanpv.get())
                            if multiStaticFlag:
                                wdmGrabRoutine2(grabObject.filenameExtras)
                            else:
                                wdmGrabRoutine(grabObject.filenameExtras)
            else:
                if grabObject:
                    if grabObject.grabFlag:
                        if grabObject.stepFlag:
                            grabObject.filenameExtras = '_' + pv1.scanpv.desc + '-' + '{0:03d}'.format(
                                i + 1) + '-' + '{0:08.4f}'.format(
                                    pv1.scanpv.get())
                        else:
                            grabObject.filenameExtras = '_' + pv1.scanpv.desc + '-' + '{0:08.4f}'.format(
                                pv1.scanpv.get())
                        if multiStaticFlag:
                            wdmGrabRoutine2(grabObject.filenameExtras)
                        else:
                            wdmGrabRoutine(grabObject.filenameExtras)
        # Move back to initial positions
        pvscan.printMsg('Setting %s back to initial position: %f' %
                        (pv1.scanpv.pvname, initialPos1))
        pv1.scanpv.move(initialPos1, delta=delta)
        if zLockFlag:
            pvscan.printMsg('Setting %s back to initial position: %f' %
                            (pv3.scanpv.pvname, initialPos3))
            pv3.scanpv.move(initialPos3, delta=delta)
        if yLockFlag:
            pvscan.printMsg('Setting %s back to initial position: %f' %
                            (pv4.scanpv.pvname, initialPos4))
            pv4.scanpv.move(initialPos4, delta=delta)
        if exp.scanmode == 2 and pv2.scanpv:
            pvscan.printMsg('Setting %s back to initial position: %f' %
                            (pv2.scanpv.pvname, initialPos2))
            pv2.scanpv.move(initialPos2, delta=delta)
    elif exp.scanmode == 3:  # Grab images only
        if grabObject:
            if grabObject.grabFlag:
                grab1.grabImages()
                grab2.grabImages()
    elif exp.scanmode == 4:  # WDM grab routine only
        if multiStaticFlag:
            wdmGrabRoutine2(grabObject.filenameExtras)
        else:
            wdmGrabRoutine(grabObject.filenameExtras)

    else:
        pvscan.printMsg(
            'Scan mode "None" selected or no PVs entered, continuing...')
        sleep(1)
Example #28
0
def scanRoutine():
    "This is the scan routine"
    pvscan.printMsg('Starting')
    sleep(0.5) # Collect some initial data first
    # Grab images of the sample
    if grab0.grabFlag: 
        grab0.grabImages(2)
    # Close pump and HeNe shutters, but only if enabled from PV.
    if shutter2.enabled:
        pvscan.printMsg('Closing pump shutter')
        shutter2.close.put(0)
    if shutter3.enabled:
        pvscan.printMsg('Closing HeNe shutter')
        shutter3.close.put(0)
    # Set all shutters to fast mode
    shutterGroup1.fast()
    # Do motor scan
    if exp1.scanflag:
        motorScan(motor1,motor2,motor3,grab1,radius,resetFlag,resetMotorPv)
    else:
        sleep(2)
    # Close pump and HeNe shutters, but only if enabled from PV.
    if shutter2.enabled:
        pvscan.printMsg('Closing pump shutter')
        shutter2.close.put(0)
    if shutter3.enabled:
        pvscan.printMsg('Closing HeNe shutter')
        shutter3.close.put(0)
    pvscan.printMsg('Done')