Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lange50 committed Jan 24, 2024
2 parents 3082e70 + f68dff7 commit e6edd3e
Show file tree
Hide file tree
Showing 28 changed files with 866 additions and 174 deletions.
71 changes: 71 additions & 0 deletions AWGCommandScripts/WindowsScripts/AWGCommand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import socket
import sys
import subprocess

# Example command: python AWGCommand.py start 140

server_ip = "192.168.1.179"
server_port = 5080

arg_message = sys.argv[1]

if len(sys.argv)>2:
data = sys.argv[2]
else:
data = '140'

freq_add = '2;'+data
freq_drop = '14;'+data
channel0 = '12;0'
channel1 = '12;1'

if arg_message == '1chan_freq': # Set channel0 to freq MHz, channel1 is off (only works if AWG.ini is configured T,F,F,F)
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(channel0, "utf-8"), (server_ip, server_port))
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(freq_add, "utf-8"), (server_ip, server_port))

elif arg_message == '2chan_freq': # Set channel1 to freq MHz, channel1 is freq MHz (only works if AWG.ini is configured T,T,F,F)
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(channel0, "utf-8"), (server_ip, server_port))
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(freq_add, "utf-8"), (server_ip, server_port))
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(channel1, "utf-8"), (server_ip, server_port))
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(freq_add, "utf-8"), (server_ip, server_port))

elif arg_message == 'start': # Start server
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('6', "utf-8"), (server_ip, server_port))

elif arg_message == 'stop': # Stop server
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('7', "utf-8"), (server_ip, server_port))

elif arg_message == 'bootup': # Kill server
try:
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('1', "utf-8"), (server_ip, server_port)) # Kills any running instance of server
subprocess.check_output('ssh awglics@192.168.1.179 ". run_server.sh"') # Starts new server
except:
subprocess.check_output('ssh awglics@192.168.1.179 ". run_server.sh"') # Starts new server

elif arg_message == 'kill': # Kill server
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('1', "utf-8"), (server_ip, server_port))

elif arg_message == 'sweep': # Give it array of good values AND total number of roi's. e.g. if out of 6 atoms, [0,1,4] are bad, give it the command 'python AWGCommand.py sweep 6;2;3;5'
data_arr = data.split(';')
message = '13'
roi_correction = 0
for i in range(1,len(data_arr)):
message += ';'+str(int(data_arr[i]) - roi_correction)+';'+str(i-1)
roi_correction += 1
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(message, "utf-8"), (server_ip, server_port))

else:
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(arg_message, "utf-8"), (server_ip, server_port))

############ For reference: ############

# EXIT: 1
# FREQ: 2
# ADD: 3
# MODIFY: 4
# START: 6
# STOP: 7
# CHAN: 12
# SWEEP: 13
# DUMP: 14
# RESTORE 15
57 changes: 57 additions & 0 deletions AWGCommandScripts/WindowsScripts/sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import socket
import sys
import subprocess

arg_message = sys.argv[1]

if len(sys.argv)>2:
freq = sys.argv[2]
else:
freq = '140'

freq_add = '2;'+freq
freq_drop = '14;'+freq
channel0 = '12;0'
channel1 = '12;1'

if arg_message == '1chan_start': # Set channel0 to freq MHz, channel1 is off (only works if AWG.ini is configured T,F,F,F)
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(channel0, "utf-8"), ("192.168.1.179", 5080))
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(freq_add, "utf-8"), ("192.168.1.179", 5080))

elif arg_message == '2chan_start': # Set channel0 to freq MHz, channel1 is freq MHz
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(channel0, "utf-8"), ("192.168.1.179", 5080))
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(freq_add, "utf-8"), ("192.168.1.179", 5080))
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(channel1, "utf-8"), ("192.168.1.179", 5080))
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(freq_add, "utf-8"), ("192.168.1.179", 5080))

elif arg_message == 'start': # Start server
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('6', "utf-8"), ("192.168.1.179", 5080))

elif arg_message == 'stop': # Stop server
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('7', "utf-8"), ("192.168.1.179", 5080))

elif arg_message == 'bootup': # Kill server
try:
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('1', "utf-8"), ("192.168.1.179", 5080)) # Kills any running instance of server
subprocess.check_output('ssh awglics@192.168.1.179 ". run_server.sh"') # Starts new server
except:
subprocess.check_output('ssh awglics@192.168.1.179 ". run_server.sh"') # Starts new server

elif arg_message == 'kill': # Kill server
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('1', "utf-8"), ("192.168.1.179", 5080))

else:
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(arg_message, "utf-8"), ("192.168.1.179", 5080))

############ For reference: ############

# EXIT: 1
# FREQ: 2
# ADD: 3
# MODIFY: 4
# START: 6
# STOP: 7
# CHAN: 12
# SWEEP: 13
# DUMP: 14
# RESTORE 15
28 changes: 28 additions & 0 deletions AWGCommandScripts/WindowsScripts/sample_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import socket
import sys
import subprocess
import time

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.sendto(bytes('12;0', "utf-8"), ("192.168.1.179", 5080))
sock.sendto(bytes('2;120', "utf-8"), ("192.168.1.179", 5080))
sock.sendto(bytes('6', "utf-8"), ("192.168.1.179", 5080))

# socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('12;0', "utf-8"), ("192.168.1.179", 5080))
# time.sleep(1)
# socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('2;120', "utf-8"), ("192.168.1.179", 5080))
# time.sleep(1)
# socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('6', "utf-8"), ("192.168.1.179", 5080))
# time.sleep(1)
############ For reference: ############

# EXIT: 1
# FREQ: 2
# ADD: 3
# MODIFY: 4
# START: 6
# STOP: 7
# CHAN: 12
# SWEEP: 13
# DUMP: 14
# RESTORE 15
8 changes: 4 additions & 4 deletions andor_repo/andor.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Metadata-Version: 1.0
Metadata-Version: 2.1
Name: andor
Version: 0.0.0
Summary: UNKNOWN
Home-page: UNKNOWN
Author: UNKNOWN
Author-email: UNKNOWN
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN

UNKNOWN

118 changes: 85 additions & 33 deletions andor_repo/andor/andor_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,81 +11,105 @@ def __init__(self):
self.cam = atmcd()# atmcd("") was working. Switch back if a problem! Without the "" also appears to be working #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
(ret) = self.cam.SetHSSpeed(0,0) #David added this 0
(ret) = self.cam.SetVSSpeed(4)#.3) #David added this
(ret) = self.cam.SetVSAmplitude(0) #David added this
(ret) = self.cam.SetPreAmpGain(2) #David added this
(ret) = self.cam.SetTemperature(-60)
(ret) = self.cam.SetADChannel(0) # Added 4/6/22
(ret) = self.cam.SetHSSpeed(0,0) # 0 corresponds to 17MHz on AD channel 0 (the only channel for our camera) in EM Gain mode
# print("HSSpeed",self.cam.GetHSSpeed(0, 0, 0))
(ret) = self.cam.SetVSSpeed(4) # 4 corresponds to 3.3us. 0 is .3
# print("VSSpeed",self.cam.GetVSSpeed(4))
(ret) = self.cam.SetVSAmplitude(0) # 0 corresponds to 'Normal' 3 required for good image at 0.3 usec VSSpeed
# print("Number VSAmplitudes is",self.cam.GetNumberVSAmplitudes())
(ret) = self.cam.SetPreAmpGain(2) # 2 corresponds to a gain of 3.0
# print("PreAmpGain", self.cam.GetPreAmpGain(2))
(ret) = self.cam.SetBaselineClamp(1)
(ret) = self.cam.SetOutputAmplifier(0) # 0 is EMCCD. David added this
(ret) = self.cam.SetEMGainMode(3) # Max is 300? David added this
(ret) = self.cam.SetEMCCDGain(50) # Max is 300? David added this
(ret) = self.cam.SetEMCCDGain(100) # Max is 300? David added this ###########################################################
(ret) = self.cam.SetCountConvertMode(1) # 1 is electron, 2 is photon
(ret) = self.cam.SetFrameTransferMode(0)
# (ret) = self.cam.SetCountConvertWavelength(float(852))

#The only setting I have missed is the readout rate which I could not find. might be SetHorizontalSpeed


(ret) = self.cam.SetShutter(0,1,50,50) # (0,1,50,50) opens shutter. (0,2,50,50) closes shutter.
# (ret) = self.cam.SetAcquisitionMode(1)

##############################################################
(ret) = self.cam.SetFastExtTrigger(1)
(ret) = self.cam.SetAcquisitionMode(3)
(ret) = self.cam.SetNumberKinetics(2)
(ret) = self.cam.SetFastExtTrigger(1) #when FastExtTrigger is active, set to 1, camera will NOT wait until a Keep Clean cycle is complete before taking an image
(ret) = self.cam.SetAcquisitionMode(3) #3 is Kinetics
(ret) = self.cam.SetNumberKinetics(2) #number of images taken in an acquisition
(ret) = self.cam.EnableKeepCleans(1)
(ret) = self.cam.SetNumberAccumulations(1) #Default value is 1. Excplicitly stating this is probably unnecessary.
# (ret) = self.cam.SaveEEPROMToFile(r'C:\Users\hoodl\Desktop\EEPROM.txt') # This breaks the camera initialization.
#(ret) = SetIsolatedCropMode(1, 30, 30, 1, 1)
##############################################################


(ret) = self.cam.SetReadMode(4)

(ret) = self.cam.SetTriggerMode(1) # 0 is internal, 1 is external, 6 is external start?
(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(0.012) # Set exposure time here!
(ret) = self.cam.SetExposureTime(0.030) # seoncds, Set exposure time here!
(ret, self.fminExposure, self.fAccumulate, self.fKinetic) = self.cam.GetAcquisitionTimings()

##############################################################
(ret) = self.cam.PrepareAcquisition()
##############################################################

if atmcd.DRV_SUCCESS==ret:
print("Andor Initializiation was successful...")
else:
print("Andor Initializiation failed...Try restarting Artiq and/or powercycling camera")

# # # def shift_speed_change(self, x, HSSpeed = 0, VSSpeed = 4, VSAmplitude = 0, PreAmpGain = 2):

# # # (ret) = self.cam.SetHSSpeed(0, HSSpeed) # The first 0 declares electron multiplication
#print("HSSpeed",self.cam.GetHSSpeed(0,0,HSSpeed))
# # # (ret) = self.cam.SetVSSpeed(VSSpeed)
#print("VSSpeed",self.cam.GetVSSpeed(VSSpeed))
# # # (ret) = self.cam.SetVSAmplitude(VSAmplitude)
# # # (ret) = self.cam.SetPreAmpGain(PreAmpGain)
#print("PreAmpGain", self.cam.GetPreAmpGain(PreAmpGain))

# # # (ret) = self.cam.SetEMCCDGain(50) # Max is 300? David added this
# # # (ret) = self.cam.SetExposureTime(0.012) # Set exposure time here! 0.012

# # # (ret) = self.cam.PrepareAcquisition()
# # # if atmcd.DRV_SUCCESS==ret:
# # # print("shift success")
# # # else:
# # # print("shift_speed_change failed")

def retrieve_trigger(self,images=2,timeout = 0): # Time out time in milliseconds

#Settings we still need: temperature(-40), shift speed (3.3), Vertical Clock Voltage Amplitude (Normal/+0), Readout Rate (17MHz at 16-bit)
# ,Pre-Amp Gain (Gain 3), Output Amplifier (Electron Multiplying), Electron Multiplier (EM) Gain (Enabled->2)


def retrieve_trigger(self,images=1,timeout = 0): # Time out time in seconds
# print("Retrieving trigger...")
# time1 = time.time()
for i in range(images):
win32event.WaitForSingleObject(self.event, (timeout*1000 + 1000)) # 12000 is 12 second timeout
# print(time.time()-time1)
# win32event.WaitForSingleObject(self.event, (timeout*1000 + 1000)) # This was the old, working one
ret = win32event.WaitForSingleObject(self.event, (timeout)) # 1 second extra delay was removed as of 7/29
# time.sleep(0.07)
# ret = win32event.WaitForSingleObject(self.event, (timeout)) # 1 second extra delay was removed as of 7/29
return np.int32(ret)

def reset_image(self):
self.cam.CancelWait()
self.cam.AbortAcquisition()

def start_acquisition_event(self):
self.event = win32event.CreateEvent(None, 0, 0, None)
self.cam.SetDriverEvent(self.event)
self.cam.StartAcquisition()
ret = self.cam.SetDriverEvent(self.event)
if atmcd.DRV_SUCCESS==ret:
ret = self.cam.StartAcquisition()
else:
pass

return np.int32(ret)
# print('started')

def trigger_count(self):
_,__,x = self.cam.GetNumberAvailableImages()
print(x,"triggers received")
return x
x = self.cam.GetNumberAvailableImages()[2]
# print(x,"triggers received")
return np.int32(x)

def get_last_image(self):
(ret, fullFrameBuffer) = self.cam.GetMostRecentImage(self.imageSize) # GetImages(somethinghere) might be a better command if we want to do background subtraction
Expand All @@ -96,7 +120,35 @@ def get_specific_image(self, image_number):
(ret, fullFrameBuffer, validfirst, validlast) = self.cam.GetImages(image_number,image_number,self.imageSize)
image = np.reshape(fullFrameBuffer, (512,512)) #Converts c_long 262k array to 512x512 image numpy array
return image


def get_crop_image(self, cropx_min = 419, cropx_max = 459, cropy_min = 358, cropy_max = 398, image_number = 1, zero = False):
(ret, fullFrameBuffer, validfirst, validlast) = self.cam.GetImages(image_number,image_number,self.imageSize)
image = np.reshape(fullFrameBuffer, (512,512))
image = image[cropx_min:cropx_max,cropy_min:cropy_max]*1
# image[19:21,18:20] = image[19:21,18:20] + 10000 # This line is used for visualizing pixels of interest on image in artiq
if zero == False:
image = image * 1
if zero == True:
image = image * 0
return image

def get_both_crop_image(self, cropx_min = 401, cropx_max = 441, cropy_min = 358, cropy_max = 398, zero = False):
(ret, image0, validfirst, validlast) = self.cam.GetImages(1,1,self.imageSize)
image0 = np.reshape(image0, (512,512))
image0 = image0[cropx_min:cropx_max,cropy_min:cropy_max]

(ret, image1, validfirst, validlast) = self.cam.GetImages(2,2,self.imageSize)
image1 = np.reshape(image1, (512,512))
image1 = image1[cropx_min:cropx_max,cropy_min:cropy_max]
if zero == False:
image0 = image0 * 1
image1 = image1 * 1
if zero == True:
image0 = image0 * 0
image1 = image1 * 0
return image0


def get_all_images(self,image_number = 2):
image_arr = [0]*image_number
for i in range(image_number):
Expand Down Expand Up @@ -146,4 +198,4 @@ def take_pic(self):
def reset(self):
(ret) = self.cam.SetShutter(0,2,50,50)
(ret) = self.cam.ShutDown()
print("Camera Reset Successful...")
print("Camera Reset Successful...")

0 comments on commit e6edd3e

Please sign in to comment.