1212#####################################################################
1313
1414from blacs .tab_base_classes import Worker
15+ from time import monotonic
1516from labscript_utils import dedent
1617import labscript_utils .h5_lock , h5py
1718
@@ -27,9 +28,10 @@ def move(self, stage_number, position):
2728 def close (self ):
2829 print (f"mock close" )
2930
30-
3131zaber = None
3232
33+ TIMEOUT = 60
34+
3335class ZaberInterface (object ):
3436 def __init__ (self , com_port ):
3537 global zaber
@@ -40,33 +42,34 @@ def __init__(self, com_port):
4042 installed. It is installable via pip with 'pip install zaber.serial'"""
4143 raise ImportError (dedent (msg ))
4244
43- self .port = zaber .AsciiSerial (com_port )
45+ self .port = zaber .BinarySerial (com_port )
4446
4547 def move (self , stage_number , position ):
46- pass
48+ device = zaber .BinaryDevice (self .port , stage_number )
49+ device .move_abs (position )
50+ deadline = monotonic () + TIMEOUT
51+ while device .get_position () != position :
52+ if monotonic () > deadline :
53+ msg = "Device did not move to requested position within timeout"
54+ raise TimeoutError (msg )
4755
4856 def close (self ):
49- pass
50-
51-
57+ self .port .close ()
5258
5359class ZaberWorker (Worker ):
5460 def init (self ):
5561 if self .mock :
5662 self .controller = MockZaberInterface (self .com_port )
5763 else :
5864 self .controller = ZaberInterface (self .com_port )
59-
65+
6066 def program_manual (self , values ):
61- #print "***************programming static*******************"
62- #self.stages.move_absolute(settings)
6367 for connection , value in values .items ():
6468 stage_number = get_stage_number (connection )
65- self .controller .move (stage_number , value )
66-
69+ self .controller .move (stage_number , int (round (value )))
6770 #TODO: return actual position of the zaber stage. Are they readable? Check API
6871 return values
69-
72+
7073 # TODO: home stage function?
7174
7275 def transition_to_buffered (self , device_name , h5file , initial_values , fresh ):
@@ -76,18 +79,18 @@ def transition_to_buffered(self, device_name, h5file, initial_values, fresh):
7679 data = group ['static_values' ]
7780 values = {name : data [0 ][name ] for name in data .dtype .names }
7881 else :
79- values = {}
80-
82+ values = {}
83+
8184 return self .program_manual (values )
82-
85+
8386 def transition_to_manual (self ):
8487 return True
85-
88+
8689 def abort_buffered (self ):
8790 return True
88-
91+
8992 def abort_transition_to_buffered (self ):
9093 return True
91-
94+
9295 def shutdown (self ):
93- self .controller .close ()
96+ self .controller .close ()
0 commit comments