Skip to content

Instantly share code, notes, and snippets.

@omsai
Created February 20, 2012 22:52
Toggle safety shutter until open on Andor Laser Combiner
"""
Toggle safety shutter until open on Andor Laser Combiner
"""
from ctypes import windll, c_ulong, byref
from time import sleep, clock
import sys
class DeVaSys:
"""Microcontroller board in Combiner controlling laser safety interlocks
and shutter"""
handle = 0
ioconfig = c_ulong(0x48000) # B7, C6 inputs, others outputs
iodata = c_ulong(0x84000) # B6, C7 high, others low
B6 = 0x80000 # B6 input toggles interlock
C7 = 0x4000 # C7 input toggles safety shutter
B7 = 0x8000 # B7 output health ok
ioblank = c_ulong(0) # all low
ioread = c_ulong(0) # initialize to zero
lib = windll
def __init__(self):
"""Instantiate DeVaSys board from library and bypass interlocks"""
self.lib = windll.LoadLibrary("usbi2cio.dll")
self.handle = self.lib.DAPI_OpenDeviceInstance("UsbI2cIo", 0)
self.lib.DAPI_ConfigIoPorts(self.handle,
self.ioconfig)
self.lib.DAPI_WriteIoPorts(self.handle,
self.iodata,
self.B6)
def shutter_open(self):
"""Open laser safety shutter"""
self.lib.DAPI_WriteIoPorts(self.handle,
self.iodata,
self.C7)
sleep(0.5) # Give the DeVaSys board time to read back the value from the Prontor shutter board
self.lib.DAPI_ReadIoPorts(self.handle,
byref(self.ioread))
if self.ioread.value & self.B7 == 0:
return 1 # success
else:
return 0
def shutter_close(self):
"""Close laser safety shutter"""
self.lib.DAPI_WriteIoPorts(self.handle,
self.ioblank,
self.C7)
if __name__ == '__main__':
prog_start = clock() # assumed "0" timepoint of program execution
print "[%.3f] Disengaging laser interlocks" \
% (clock() - prog_start)
dvs = DeVaSys()
print "[%.3f] Toggling safety shutter till open" \
% (clock() - prog_start)
attempt = 1
status = dvs.shutter_open()
while status != 1:
print "[%.3f] Failed to open shutter on attempt %d. Trying again..." \
% (clock() - prog_start, attempt)
sleep(2) # wait 2 seconds
dvs.shutter_close()
sleep(2) # wait 2 seconds
attempt = attempt + 1
status = dvs.shutter_open()
del dvs
print "[%.3f] Success." \
% (clock() - prog_start)
raw_input("Press any enter to exit")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment