1+ #####################################################################
2+ # #
3+ # /DummyIntermediateDevice.py #
4+ # #
5+ # Copyright 2013, Monash University #
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+
14+ from __future__ import division , unicode_literals , print_function , absolute_import
15+ from labscript_utils import PY2
16+ if PY2 :
17+ str = unicode
18+
19+ # This file represents a dummy labscript device for purposes of testing BLACS
20+ # and labscript. The device is a Intermediate Device, and can be attached to
21+ # a pseudoclock in labscript in order to test the pseudoclock behaviour
22+ # without needing a real Intermediate Device.
23+ #
24+ # You can attach an arbitrary number of outputs to this device, however we
25+ # currently only support outputs of type AnalogOut and DigitalOut. I would be
26+ # easy to extend this is anyone needed further functionality.
27+
28+
29+ from labscript_devices import labscript_device , BLACS_tab , BLACS_worker
30+ from labscript import IntermediateDevice , DigitalOut , AnalogOut , config
31+ import numpy as np
32+
33+ @labscript_device
34+ class DummyIntermediateDevice (IntermediateDevice ):
35+
36+ description = 'Dummy IntermediateDevice'
37+ clock_limit = 1e6
38+
39+ # If this is updated, then you need to update generate_code to support whatever types you add
40+ allowed_children = [DigitalOut , AnalogOut ]
41+
42+ def __init__ (self , name , parent , BLACS_connection = 'dummy_connection' , ** kwargs ):
43+ self .BLACS_connection = BLACS_connection
44+ IntermediateDevice .__init__ (self , name , parent , ** kwargs )
45+
46+ def generate_code (self , hdf5_file ):
47+ group = self .init_device_group (hdf5_file )
48+
49+ clockline = self .parent_device
50+ pseudoclock = clockline .parent_device
51+ times = pseudoclock .times [clockline ]
52+
53+ # out_table = np.empty((len(times),len(self.child_devices)), dtype=np.float32)
54+ # determine dtypes
55+ dtypes = []
56+ for device in self .child_devices :
57+ if isinstance (device , DigitalOut ):
58+ device_dtype = np .int8
59+ elif isinstance (device , AnalogOut ):
60+ device_dtype = np .float64
61+ dtypes .append ((device .name , device_dtype ))
62+
63+ # create dataset
64+ out_table = np .zeros (len (times ), dtype = dtypes )
65+ for device in self .child_devices :
66+ out_table [device .name ][:] = device .raw_output
67+
68+ group .create_dataset ('OUTPUTS' , compression = config .compression , data = out_table )
69+
70+
71+ from blacs .device_base_class import DeviceTab
72+ from blacs .tab_base_classes import Worker
73+
74+ @BLACS_tab
75+ class DummyIntermediateDeviceTab (DeviceTab ):
76+ def initialise_GUI (self ):
77+ self .create_worker ("main_worker" ,DummyIntermediateDeviceWorker ,{})
78+ self .primary_worker = "main_worker"
79+
80+ @BLACS_worker
81+ class DummyIntermediateDeviceWorker (Worker ):
82+ def init (self ):
83+ pass
84+
85+ def program_manual (self , front_panel_values ):
86+ return front_panel_values
87+
88+ def transition_to_buffered (self , device_name , h5file , initial_values , fresh ):
89+ return initial_values
90+
91+ def transition_to_manual (self ,abort = False ):
92+ return True
93+
94+ def abort_transition_to_buffered (self ):
95+ return self .transition_to_manual (True )
96+
97+ def abort_buffered (self ):
98+ return self .transition_to_manual (True )
99+
100+ def shutdown (self ):
101+ pass
0 commit comments