From b98304429d468352aedf1164f35fb5c8d897ceb9 Mon Sep 17 00:00:00 2001 From: "Hood, Jonathan D" Date: Mon, 14 Jun 2021 11:16:20 -0400 Subject: [PATCH] safe --- Andor/andorv2/andor/SimplestScript.py | 3 +- Andor/andorv2/andor/SimplestScriptv2.py | 74 ++++++++++++++++++ andor_repo/andor/andor_driver.py | 60 +++++++------- .../picomotor_driver.cpython-38.pyc | Bin 3729 -> 3729 bytes 4 files changed, 104 insertions(+), 33 deletions(-) create mode 100644 Andor/andorv2/andor/SimplestScriptv2.py diff --git a/Andor/andorv2/andor/SimplestScript.py b/Andor/andorv2/andor/SimplestScript.py index 8f85423..7b126d3 100644 --- a/Andor/andorv2/andor/SimplestScript.py +++ b/Andor/andorv2/andor/SimplestScript.py @@ -19,7 +19,7 @@ cam.SetAcquisitionMode(1) # Single scan cam.SetReadMode(4) # Image readmode cam.SetShutter(0,1,50,50) # (0,1,50,50) opens shutter - cam.SetExposureTime(1) # 1 second + cam.SetExposureTime(.1) # 1 second cam.SetTriggerMode(1) # External TTL trigger (ret, xpixels, ypixels) = cam.GetDetector() # Returns detector properties imagesize = xpixels*ypixels # Set image size @@ -45,6 +45,7 @@ cam.CancelWait() # Cancels WaitForAcquisition cam.AbortAcquisition() # Cancels StartAcquisition cam.StartAcquisition() # Restarts StartAcquisition + cam.ShutDown() if ret == 20002: print("Script ran correctly...") diff --git a/Andor/andorv2/andor/SimplestScriptv2.py b/Andor/andorv2/andor/SimplestScriptv2.py new file mode 100644 index 0000000..bede13d --- /dev/null +++ b/Andor/andorv2/andor/SimplestScriptv2.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python + +### Section 1: Imports ### + +import sys, os +sys.path.append(r'C:/Users/hoodl/Documents/GitHub/Instruments/Andor/andorv2/andor') +from atmcd import * +import numpy as np +import matplotlib.pyplot as plt +import win32event + + +seriesLength = 30; + +cam = atmcd() + +error = cam.Initialize("/usr/local/etc/andor") +print("Init",error) +if (error == cam.DRV_SUCCESS): + (err, sensorWidth, sensorHeight) = cam.GetDetector() + cam.SetTriggerMode(1); + cam.SetFastExtTrigger(1); + cam.SetReadMode(4); + cam.SetExposureTime(1); + cam.SetAcquisitionMode(3); + cam.SetNumberKinetics(seriesLength); + cam.SetShutter(1, 1, 0, 0); + cam.SetVSSpeed(0); + # (error, speed) = cam.GetVSSpeed(); + # print("VSS = %g usecs\n", speed); + cam.SetHSSpeed(0, 0); # check if first input right + # cam.GetHSSpeed(0, 0, 0, speed); + # print("HSS = %g MHz\n", speed); + + cam.EnableKeepCleans(0); + cam.SetIsolatedCropMode(1, 30, 30, 1, 1); + + cam.SetImage(1, 1, 1, 30, 1, 30); + cam.PrepareAcquisition(); + cam.SetShutter(1, 1, 0, 0); + # GetAcquisitionTimings(float(exp), float(acc), float(kin)); + # print("Cycle time = %g\n", kin); + # Set up events + + print("pre") + event = 0#win32event.CreateEvent(None, False, False, None) + print(event) + + x = cam.SetDriverEvent(event) + + error = cam.StartAcquisition() + print("StartAcquisition returned", error); + +# if (error == cam.DRV_SUCCESS): +# WaitStatus = np.uint64(0); +# first, last = 0, validFirst, validLast; +# while (last < seriesLength): +# # auto start = high_resolution_clock::now(); +# WaitStatus = cam.WaitForSingleObject(event, float('inf')); +# if (WaitStatus == WAIT_FAILED): +# continue +# if (WaitStatus == WAIT_OBJECT_0): +# cam.GetNumberAvailableImages(first, last); +print(cam.GetNumberAvailableImages()) + + +(ret, xpixels, ypixels) = cam.GetDetector() # Returns detector properties +imagesize = xpixels*ypixels # Set image size +(ret, fullFrameBuffer) = cam.GetMostRecentImage(imagesize) # Retrieves most recent image +image = np.reshape(fullFrameBuffer, (512,512)) #Converts c_long 262k array to 512x512 image numpy array +plt.imshow(image) # Plots image + +cam.SetShutter(1, 2, 0, 0); +# print("ShutDown() returned %d\n", ShutDown()); \ No newline at end of file diff --git a/andor_repo/andor/andor_driver.py b/andor_repo/andor/andor_driver.py index 00242ae..b03b1f6 100644 --- a/andor_repo/andor/andor_driver.py +++ b/andor_repo/andor/andor_driver.py @@ -1,19 +1,20 @@ #!/usr/bin/env python -from andor.atmcd import * +from pyAndorSDK2 import atmcd +import win32event import numpy as np import matplotlib.pyplot as plt import time - class ANDOR: """Driver for ANDOR camera """ def __init__(self): - self.cam = atmcd() #load the atmcd library + self.cam = atmcd("") #load the atmcd library # self.reset() (ret) = self.cam.Initialize("/usr/local/etc/andor") #initialise camera # C:\Program Files\Andor SDK (ret, iSerialNumber) = self.cam.GetCameraSerialNumber() + (ret) = self.cam.CoolerON() (ret) = self.cam.SetCoolerMode(1) (ret) = self.cam.SetTemperature(-40) #David added this @@ -22,7 +23,12 @@ def __init__(self): (ret) = self.cam.SetVSAmplitude(0) #David added this (ret) = self.cam.SetPreAmpGain(3) #David added this (ret) = self.cam.SetOutputAmplifier(0) # 0 is EMCCD. David added this - (ret) = self.cam.SetEMCCDGain(2) # Max is 300? David added this + (ret) = self.cam.SetEMGainMode(0) # Max is 300? David added this + (ret) = self.cam.SetEMCCDGain(50) # Max is 300? David added this + (ret) = self.cam.SetCountConvertMode(2) + (ret) = self.cam.SetCountConvertWavelength(float(852)) + # (ret,low,high) = self.cam.GetEMGainRange() + # print(low,high) #The only setting I have missed is the readout rate which I could not find. might be SetHSSpeed and SetHorizontalSpeed (ret) = self.cam.SetShutter(0,1,50,50) # (0,1,50,50) opens shutter. (0,2,50,50) closes shutter. @@ -33,10 +39,8 @@ def __init__(self): (ret, self.xpixels, self.ypixels) = self.cam.GetDetector() self.imageSize = self.xpixels*self.ypixels (ret) = self.cam.SetImage(1, 1, 1, self.xpixels, 1, self.ypixels) - (ret) = self.cam.SetExposureTime(.1) # Set exposure time here! + (ret) = self.cam.SetExposureTime(0.01) # Set exposure time here! (ret, self.fminExposure, self.fAccumulate, self.fKinetic) = self.cam.GetAcquisitionTimings() - # (ret) = self.cam.PrepareAcquisition() - (ret) = self.cam.StartAcquisition() if atmcd.DRV_SUCCESS==ret: print("Andor Initializiation was successful...") @@ -48,42 +52,34 @@ def __init__(self): # ,Pre-Amp Gain (Gain 3), Output Amplifier (Electron Multiplying), Electron Multiplier (EM) Gain (Enabled->2) - def await_trigger(self): - # try: - - - - print("Awaiting trigger...") - (ret) = self.cam.WaitForAcquisition()#TimeOut(1000) - # self.cam.WaitForAcquisition(); - print("Taking image...") - # self.cam.CancelWait() + def retrieve_trigger(self): + # print("Retrieving trigger...") + # time1 = time.time() + win32event.WaitForSingleObject(self.event, 12000) # 12000 is 12 second timeout + # print(time.time()-time1) - - - - # except: - # try: - # (ret) = self.cam.ShutDown() - # except: - # pass - # print("Error in await_trigger(), try restarting artiq...") - - def reset_image(self): self.cam.CancelWait() self.cam.AbortAcquisition() - def start_acq(self): + def start_acquisition_event(self): + self.event = win32event.CreateEvent(None, 0, 0, None) + self.cam.SetDriverEvent(self.event) self.cam.StartAcquisition() - def get_last_image(self): - - # try: (ret, fullFrameBuffer) = self.cam.GetMostRecentImage(self.imageSize) # GetImages(somethinghere) might be a better command if we want to do background subtraction image = np.reshape(fullFrameBuffer, (512,512)) #Converts c_long 262k array to 512x512 image numpy array + return image + def trigger_count(self): + _,__,x = self.cam.GetNumberAvailableImages() + print(x,"triggers received") + return x + + def get_specific_image(self): + (ret, fullFrameBuffer, validfirst, validlast) = self.cam.GetImages(1,1,self.imageSize) + image = np.reshape(fullFrameBuffer, (512,512)) #Converts c_long 262k array to 512x512 image numpy array return image def plot_image(self,image=None): diff --git a/picomotor_repo/picomotor/__pycache__/picomotor_driver.cpython-38.pyc b/picomotor_repo/picomotor/__pycache__/picomotor_driver.cpython-38.pyc index 7c3ff2c4038ad56580c8bed9cba7a6849851f170..9f9b4e08217f5902e9b7ca8cff9d1e13a99eb3e8 100644 GIT binary patch delta 20 acmbOzJ5iQ9l$V!_0SJ~w9oop<#s>f|p9J#& delta 20 acmbOzJ5iQ9l$V!_0SHuuz2;{yOLLj