Skip to content

Commit

Permalink
safe
Browse files Browse the repository at this point in the history
  • Loading branch information
dpeana committed Jun 14, 2021
1 parent 0e721f3 commit b983044
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 33 deletions.
3 changes: 2 additions & 1 deletion Andor/andorv2/andor/SimplestScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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...")
Expand Down
74 changes: 74 additions & 0 deletions Andor/andorv2/andor/SimplestScriptv2.py
Original file line number Diff line number Diff line change
@@ -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());
60 changes: 28 additions & 32 deletions andor_repo/andor/andor_driver.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand All @@ -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...")
Expand All @@ -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):
Expand Down
Binary file not shown.

0 comments on commit b983044

Please sign in to comment.