Commits

Anonymous committed 90d503d

working example, not definitive because still have timing issues

  • Participants

Comments (0)

Files changed (2)

File .hgignore

Empty file added.
+# coding=UTF-8
+# Chris Lee-Messer 12/15/2008 (c)
+
+from serial import *
+
+# in command mode, just send an integer 0-12 at least and the filter will change to that
+# use ord() to convert a one character string result back to an integer for display
+
+# value source: Lambda DG-4 high-speed filter changer operation manual Rev 2.10 (20051103)
+
+SWITCH_TO_SERIAL=238 # switch the DG4 to serial mode, DG4 hangs until it receives the next serial command
+OPEN_SHUTTER = 170
+# DATANUM = 171 MARKER BETWEEN 235 OR 236 IN N.D. ADJUST
+CLOSE_SHUTTER = 172 
+ENABLE_TURBO_BLANKING=186
+DISABLE_TURBO_BLANKING = 188 
+TRIGGERED_BY_STROBE = 202
+DISABLE_TRIGGERED_BY_STROBE = 203
+SELECT_VIDEO_SYNC= 204 
+
+DISABLE_VIDEO_SYNC = 205
+SELECT_VIDEO_SYNC_GATED_BY_STROBE_LOW = 206
+DISABLE_VIDEO_SYNC_GATED_BY_STROBE_LOW = 207
+FREEZE_DISPLAY = 218 
+TURN_DISPLAY_ON = 219 
+START_LOADING_RING_BUFFER = 223 #START LOADING RING BUFFER (UP TO 256 VALUES)
+START_REMOTE_CHANGE_OF_ND_FILTER_SETTING = 234 #START REMOTE CHANGE OF N.D. FILTER SETTING
+INCREASE_THE_DAC_GALVO_VALUE = 235 #-SEND 171 AS SPACE
+END_CHANGE_OF_ND_FILTER_SETTING_AND_SAVE = 237 
+FORCE_ONLINE_FOR_CHANNEL_THAT_RECEIVED_IT = 238 
+END_LOADING_RING_BUFFER_FILTERS = 240 
+RUN_RING_BUFFER = 241 # (FIRST SELECT TRIGGER SOURCE)
+END_RING_BUFFER_RUN = 242 
+
+#toHex = lambda x:"".join([hex(ord(c))[2:].zfill(2) for c in x])
+# str.encode("hex"), str.decode("hex")
+
+class DG4Serial(object):
+    def __init__(self, comname):
+        "example comname = 3 if want to open com4 on windows"
+        self.com = Serial(comname)
+        
+    def wdec(self,val):
+        self.com.write("%c" % val)  # do I need a reply?
+    
+    def cmd(self,val):
+        self.wdec(val)
+        while self.com.inWaiting():
+            print "dg4: %d" % ord(self.com.read(1))
+    
+    
+    
+    
+
+    def switchToSerialMode(self):
+        self.wdec(SWITCH_TO_SERIAL)
+    
+ 
+#  Reading the Status of the Lambda DG-4
+#  T he Lambda DG-4 controller signals that it has completed commands received through its serial port by sending a carriage return back. 
+#  so we're wating for int(13)
+# The 
+#~ following is an example of a QuickBASIC routine that might be used to monitor the status of the DG-4, assuming that #1 has already been 
+#~ opened as the serial port to which the DG-4 is connected.
+
+
+#~ In [2]: cd Desktop/
+#~ C:\Documents and Settings\cleemesser\Desktop
+
+#~ In [3]: from dg4 import *
+
+#~ In [4]: dg = DG4
+#~ DG4Serial dg4.py    dg4.pyc
+
+#~ In [4]: dg = DG4Serial(3)
+
+#~ In [5]: dg.cmd(SWITCH_TO_SERIAL)
+
+#~ In [6]: dg.cmd(OPEN_SHUTTER)
+
+#~ In [7]: dg.cmd(CLOW_SHUTTER)
+#~ ---------------------------------------------------------------------------
+#~ <type 'exceptions.NameError'>             Traceback (most recent call last)
+
+#~ C:\Documents and Settings\cleemesser\Desktop\<ipython console> in <module>()
+
+#~ <type 'exceptions.NameError'>: name 'CLOW_SHUTTER' is not defined
+
+#~ In [8]: dg.cmd(CLOs_SHUTTER)
+#~ ---------------------------------------------------------------------------
+#~ <type 'exceptions.NameError'>             Traceback (most recent call last)
+
+#~ C:\Documents and Settings\cleemesser\Desktop\<ipython console> in <module>()
+
+#~ <type 'exceptions.NameError'>: name 'CLOs_SHUTTER' is not defined
+
+#~ In [9]: dg.cmd(CLOS_SHUTTER)
+#~ ---------------------------------------------------------------------------
+#~ <type 'exceptions.NameError'>             Traceback (most recent call last)
+
+#~ C:\Documents and Settings\cleemesser\Desktop\<ipython console> in <module>()
+
+#~ <type 'exceptions.NameError'>: name 'CLOS_SHUTTER' is not defined
+
+#~ In [10]: dg.cmd(CLOSE_SHUTTER)
+#~ repy: 170
+
+#~ In [11]:   
+
+def setupForStrobeFilter(filt=1,comnum=3):
+    """
+    specific to inverted rig where we use COM4 (comnum 3 opens COM4) to control the DG4
+    this will set up the dg4 to switch to filter 1 setting on strobe pulse then
+    back to 0 on the next strobe pulse
+    """
+    import time
+    dg = DG4Serial(comnum)
+    dg.cmd(SWITCH_TO_SERIAL)
+    time.sleep(0.1)
+    dg.cmd(START_LOADING_RING_BUFFER)
+    time.sleep(0.5)
+    dg.cmd(filt)
+    time.sleep(0.5)
+    dg.cmd(0)
+    time.sleep(0.5)
+    dg.cmd(END_LOADING_RING_BUFFER_FILTERS)
+    time.sleep(0.5)
+    dg.cmd(TRIGGERED_BY_STROBE)
+    time.sleep(0.5)
+    dg.cmd(RUN_RING_BUFFER)
+    return dg
+    
+    
+    
+    
+if __name__ == '__main__':
+    setupForStrobeFilter(filt=1)