Skip to content

Commit 86ba7c4

Browse files
Merged in cbillington/labscript_devices/arbitrary_subfolders (pull request #51)
Arbitrary subfolders for device code within labscript_devices
2 parents 4e90d38 + 5d35c70 commit 86ba7c4

24 files changed

+406
-193
lines changed

AlazarTechBoard.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
'ATS9462': 'a 200mV sine (conservatively peak-to-peak) between 9.5 and 10.5 MHz.'
7979
}
8080

81-
from labscript_devices import labscript_device
8281
from labscript import Device, AnalogIn, bitfield, config, LabscriptError, set_passed_properties
8382
import labscript_utils.h5_lock
8483
import h5py
@@ -177,7 +176,7 @@ def generate_code(self, hdf5_file):
177176
input_attrs), location='device_properties')
178177

179178

180-
from labscript_devices import BLACS_tab, BLACS_worker
179+
from labscript_devices import BLACS_tab
181180
from blacs.tab_base_classes import Worker, define_state
182181
from blacs.tab_base_classes import MODE_MANUAL, MODE_TRANSITION_TO_BUFFERED, MODE_TRANSITION_TO_MANUAL, MODE_BUFFERED
183182
from blacs.device_base_class import DeviceTab
@@ -274,7 +273,6 @@ def ats9462_clock(f):
274273
# to aborts never seeming to raise exceptions and the acquisition thread continuing on.
275274

276275

277-
@BLACS_worker
278276
class GuilessWorker(Worker):
279277
def init(self):
280278
global h5py

Camera.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818

1919
check_version('labscript', '2.0.1', '3')
2020

21-
from labscript_devices import labscript_device, BLACS_tab, BLACS_worker
21+
from labscript_devices import BLACS_tab
2222
from labscript import TriggerableDevice, LabscriptError, set_passed_properties
2323
import numpy as np
2424

25-
@labscript_device
25+
2626
class Camera(TriggerableDevice):
2727
description = 'Generic Camera'
2828

@@ -203,7 +203,7 @@ def update_responding_indicator(self, responding):
203203
self.ui.status_icon.setPixmap(pixmap)
204204
self.ui.server_status.setText(status_text)
205205

206-
@BLACS_worker
206+
207207
class CameraWorker(Worker):
208208
def init(self):#, port, host, use_zmq):
209209
# self.port = port

DummyPseudoclock.py

Lines changed: 0 additions & 104 deletions
This file was deleted.

DummyPseudoclock/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#####################################################################
2+
# #
3+
# /labscript_devices/DummyPseudoclock/__init__.py #
4+
# #
5+
# Copyright 2017, Christopher Billington #
6+
# #
7+
# This file is part of labscript_devices, in the labscript suite #
8+
# (see http://labscriptsuite.org), and is licensed under the #
9+
# Simplified BSD License. See the license.txt file in the root of #
10+
# the project for the full license. #
11+
# #
12+
#####################################################################
13+
from __future__ import division, unicode_literals, print_function, absolute_import
14+
from labscript_utils import PY2
15+
if PY2:
16+
str = unicode
17+
18+
from labscript_devices import deprecated_import_alias
19+
20+
21+
# For backwards compatibility with old experiment scripts:
22+
DummyPseudoclock = deprecated_import_alias(
23+
"labscript_devices.DummyPseudoclock.labscript_device.DummyPseudoclock"
24+
)

DummyPseudoclock/blacs_tab.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#####################################################################
2+
# #
3+
# /labscript_devices/DummyPseudoclock/blacs_tab.py #
4+
# #
5+
# Copyright 2017, Christopher Billington #
6+
# #
7+
# This file is part of labscript_devices, in the labscript suite #
8+
# (see http://labscriptsuite.org), and is licensed under the #
9+
# Simplified BSD License. See the license.txt file in the root of #
10+
# the project for the full license. #
11+
# #
12+
#####################################################################
13+
from __future__ import division, unicode_literals, print_function, absolute_import
14+
from labscript_utils import PY2
15+
if PY2:
16+
str = unicode
17+
from blacs.device_base_class import DeviceTab, define_state, MODE_BUFFERED
18+
19+
class DummyPseudoclockTab(DeviceTab):
20+
def initialise_workers(self):
21+
worker_initialisation_kwargs = {}
22+
self.create_worker(
23+
"main_worker",
24+
"labscript_devices.DummyPseudoclock.blacs_worker.DummyPseudoclockWorker",
25+
worker_initialisation_kwargs,
26+
)
27+
self.primary_worker = "main_worker"
28+
29+
@define_state(MODE_BUFFERED, True)
30+
def start_run(self, notify_queue):
31+
self.wait_until_done(notify_queue)
32+
33+
@define_state(MODE_BUFFERED, True)
34+
def wait_until_done(self, notify_queue):
35+
"""Call check_if_done repeatedly in the worker until the shot is complete"""
36+
done = yield (self.queue_work(self.primary_worker, 'check_if_done'))
37+
# Experiment is over. Tell the queue manager about it:
38+
if done:
39+
notify_queue.put('done')
40+
else:
41+
# Not actual recursion since this just queues up another call
42+
# after we return:
43+
self.wait_until_done(notify_queue)
44+

DummyPseudoclock/blacs_worker.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#####################################################################
2+
# #
3+
# /labscript_devices/DummyPseudoclock/blacs_worker.py #
4+
# #
5+
# Copyright 2017, Christopher Billington #
6+
# #
7+
# This file is part of labscript_devices, in the labscript suite #
8+
# (see http://labscriptsuite.org), and is licensed under the #
9+
# Simplified BSD License. See the license.txt file in the root of #
10+
# the project for the full license. #
11+
# #
12+
#####################################################################
13+
from __future__ import division, unicode_literals, print_function, absolute_import
14+
from labscript_utils import PY2
15+
if PY2:
16+
str = unicode
17+
import time
18+
import labscript_utils.h5_lock
19+
import h5py
20+
from blacs.tab_base_classes import Worker
21+
import labscript_utils.properties as properties
22+
23+
class DummyPseudoclockWorker(Worker):
24+
def program_manual(self, values):
25+
return {}
26+
27+
def transition_to_buffered(self, device_name, h5file, initial_values, fresh):
28+
# get stop time:
29+
with h5py.File(h5file, 'r') as f:
30+
props = properties.get(f, self.device_name, 'device_properties')
31+
self.stop_time = props.get('stop_time', None) # stop_time may be absent if we are not the master pseudoclock
32+
return {}
33+
34+
def check_if_done(self):
35+
# Wait up to 1 second for the shot to be done, returning True if it is
36+
# or False if not.
37+
if getattr(self, 'start_time', None) is None:
38+
self.start_time = time.time()
39+
timeout = min(self.start_time + self.stop_time - time.time(), 1)
40+
if timeout < 0:
41+
return True
42+
time.sleep(timeout)
43+
return self.start_time + self.stop_time < time.time()
44+
45+
def transition_to_manual(self):
46+
self.start_time = None
47+
self.stop_time = None
48+
return True
49+
50+
def shutdown(self):
51+
return
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#####################################################################
2+
# #
3+
# /labscript_devices/DummyPseudoclock/DummyPseudoclock.py #
4+
# #
5+
# Copyright 2017, Christopher Billington #
6+
# #
7+
# This file is part of labscript_devices, in the labscript suite #
8+
# (see http://labscriptsuite.org), and is licensed under the #
9+
# Simplified BSD License. See the license.txt file in the root of #
10+
# the project for the full license. #
11+
# #
12+
#####################################################################
13+
from __future__ import division, unicode_literals, print_function, absolute_import
14+
from labscript_utils import PY2
15+
if PY2:
16+
str = unicode
17+
18+
# This file represents a dummy labscript device for purposes of testing BLACS
19+
# and labscript. The device is a PseudoclockDevice, and can be the sole device
20+
# in a connection table or experiment.
21+
22+
import labscript_utils.h5_lock
23+
import h5py
24+
from labscript import PseudoclockDevice, Pseudoclock, ClockLine
25+
26+
27+
class DummyPseudoclock(PseudoclockDevice):
28+
29+
description = 'Dummy pseudoclock'
30+
clock_limit = 1e6
31+
clock_resolution = 1e-6
32+
33+
def __init__(self, name='dummy_pseudoclock', BLACS_connection='dummy_connection', **kwargs):
34+
self.BLACS_connection = BLACS_connection
35+
PseudoclockDevice.__init__(self, name, None, None, **kwargs)
36+
self.pseudoclock = Pseudoclock(self.name + '_pseudoclock', self, 'pseudoclock')
37+
self.clockline = ClockLine(name='clockline', pseudoclock=self.pseudoclock, connection='dummy')
38+
39+
def generate_code(self, hdf5_file):
40+
group = self.init_device_group(hdf5_file)
41+
self.set_property('stop_time', self.stop_time, location='device_properties')
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#####################################################################
2+
# #
3+
# /labscript_devices/DummyPseudoclock/register_classes.py #
4+
# #
5+
# Copyright 2017, Christopher Billington #
6+
# #
7+
# This file is part of labscript_devices, in the labscript suite #
8+
# (see http://labscriptsuite.org), and is licensed under the #
9+
# Simplified BSD License. See the license.txt file in the root of #
10+
# the project for the full license. #
11+
# #
12+
#####################################################################
13+
import labscript_devices
14+
15+
labscript_devices.register_classes(
16+
'DummyPseudoclock',
17+
BLACS_tab='labscript_devices.DummyPseudoclock.blacs_tab.DummyPseudoclockTab',
18+
runviewer_parser=None, #TODO make a runviwer parser for Dummy pseudoclock!
19+
)

NI_PCI_6733.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
str = unicode
1717

1818
from labscript import LabscriptError, AnalogOut
19-
from labscript_devices import labscript_device, BLACS_tab, BLACS_worker, runviewer_parser
19+
from labscript_devices import BLACS_tab, runviewer_parser
2020
import labscript_devices.NIBoard as parent
2121

2222
import numpy as np
2323
import labscript_utils.h5_lock, h5py
2424
import labscript_utils.properties
2525

26-
@labscript_device
26+
2727
class NI_PCI_6733(parent.NIBoard):
2828
description = 'NI-PCI-6733'
2929
n_analogs = 8
@@ -109,9 +109,8 @@ def do_sort(channel):
109109
# Set the capabilities of this device
110110
self.supports_remote_value_check(False)
111111
self.supports_smart_programming(False)
112-
113-
114-
@BLACS_worker
112+
113+
115114
class NiPCI6733Worker(Worker):
116115
def init(self):
117116
exec('from PyDAQmx import Task', globals())

NI_PCIe_6363.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
str = unicode
1717

1818
from labscript import LabscriptError
19-
from labscript_devices import labscript_device, BLACS_tab, BLACS_worker, runviewer_parser
19+
from labscript_devices import BLACS_tab, runviewer_parser
2020
import labscript_devices.NIBoard as parent
2121
from labscript_utils.numpy_dtype_workaround import dtype_workaround
2222

@@ -26,7 +26,6 @@
2626
from labscript_utils.connections import _ensure_str
2727

2828

29-
@labscript_device
3029
class NI_PCIe_6363(parent.NIBoard):
3130
description = 'NI-PCIe-6363'
3231
n_analogs = 4
@@ -111,8 +110,8 @@ def pfi_sort(channel):
111110
# Set the capabilities of this device
112111
self.supports_remote_value_check(False)
113112
self.supports_smart_programming(False)
114-
115-
@BLACS_worker
113+
114+
116115
class NiPCIe6363Worker(Worker):
117116
def init(self):
118117
exec('from PyDAQmx import Task, DAQmxGetSysNIDAQMajorVersion, DAQmxGetSysNIDAQMinorVersion, DAQmxGetSysNIDAQUpdateVersion, DAQmxResetDevice', globals())

0 commit comments

Comments
 (0)