Skip to content

Commit c471703

Browse files
zaberstage: Switch to BinarySerial, which seems to be compatible with the stage we have,
and implement move and close functions. Round values to ints before programming. Wait until device is in position before returning. Timeout after 60 seconds. TODO, low priority: smart programming and remote value checking.
1 parent a4b631f commit c471703

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

ZaberStageController/blacs_workers.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#####################################################################
1313

1414
from blacs.tab_base_classes import Worker
15+
from time import monotonic
1516
from labscript_utils import dedent
1617
import 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-
3131
zaber = None
3232

33+
TIMEOUT = 60
34+
3335
class 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

5359
class 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()
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from labscript import *
22
from labscript_devices.DummyPseudoclock.labscript_devices import DummyPseudoclock
33

4-
MOCK = True
5-
labscript_init('test.h5', new=True, overwrite=True)
4+
MOCK = False
5+
# labscript_init('test.h5', new=True, overwrite=True)
66

77
from labscript_devices.ZaberStageController.labscript_devices import (
88
ZaberStageTLS28M,
@@ -12,11 +12,11 @@
1212

1313
DummyPseudoclock()
1414
ZaberStageController('controller', com_port='COM1', mock=MOCK)
15-
ZaberStageTLS28M('stage', controller, 'stage 1')
16-
ZaberStageTLS28M('stage2', controller, 'stage 2')
15+
ZaberStageTLS28M('stage', controller, 'stage 1', limits=(0, 30000))
16+
# ZaberStageTLS28M('stage2', controller, 'stage 2')
1717

1818
start()
1919

20-
stage.constant(65465)
20+
stage.constant(30000)
2121

2222
stop(1)

0 commit comments

Comments
 (0)