Skip to content

Commit c50eb43

Browse files
committed
Merged in pstarkey/labscript/remote-device-connections (pull request labscript-suite#31)
Updates to RemoteWorker and similar classes Approved-by: Jan Werkmann <[email protected]> Approved-by: Chris Billington <[email protected]>
2 parents 78bab8f + 337c382 commit c50eb43

File tree

1 file changed

+59
-22
lines changed

1 file changed

+59
-22
lines changed

labscript.py

+59-22
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class Device(object):
182182
property_names = {"device_properties": ["added_properties"]}
183183
)
184184
def __init__(self,name,parent_device,connection, call_parents_add_device=True,
185-
added_properties = {}, **kwargs):
185+
added_properties = {}, gui=None, worker=None, **kwargs):
186186
# Verify that no invalid kwargs were passed and the set properties
187187
if len(kwargs) != 0:
188188
raise LabscriptError('Invalid keyword arguments: %s.'%kwargs)
@@ -230,6 +230,33 @@ def __init__(self,name,parent_device,connection, call_parents_add_device=True,
230230

231231
# Add self to the compiler's device inventory
232232
compiler.inventory.append(self)
233+
234+
# handle remote workers/gui interface
235+
if gui is not None or worker is not None:
236+
# remote GUI and worker
237+
if gui is not None:
238+
# if no worker is specified, assume it is the same as the gui
239+
if worker is None:
240+
worker = gui
241+
242+
# check that worker and gui are appropriately typed
243+
if not isinstance(gui, _RemoteConnection):
244+
raise LabscriptError('the "gui" argument for %s must be specified as a subclass of _RemoteConnection'%(self.name))
245+
else:
246+
# just remote worker
247+
gui = compiler._PrimaryBLACS
248+
249+
if not isinstance(worker, _RemoteConnection):
250+
raise LabscriptError('the "worker" argument for %s must be specified as a subclass of _RemoteConnection'%(self.name))
251+
252+
# check that worker is equal to, or a child of, gui
253+
if worker != gui and worker not in gui.get_all_children():
254+
print gui.get_all_children()
255+
raise LabscriptError('The remote worker (%s) for %s must be a child of the specified gui (%s) '%(worker.name, self.name, gui.name))
256+
257+
# store worker and gui as properties of the connection table
258+
self.set_property('gui', gui.name, 'connection_table_properties')
259+
self.set_property('worker', worker.name, 'connection_table_properties')
233260

234261

235262
# Method to set a property for this device.
@@ -248,7 +275,7 @@ def set_property(self, name, value, location=None, overwrite=False):
248275
if location is None or location not in labscript_utils.properties.VALID_PROPERTY_LOCATIONS:
249276
raise LabscriptError('Device %s requests invalid property assignment %s for property %s'%(self.name, location, name))
250277

251-
# if this try failes then self."location" may not be instantiated
278+
# if this try fails then self."location" may not be instantiated
252279
if not hasattr(self, "_properties"):
253280
self._properties = {}
254281

@@ -431,29 +458,32 @@ def init_device_group(self, hdf5_file):
431458
return group
432459

433460

434-
class _RemoteBLACSConnection(Device):
435-
delimeter = '|'
436-
461+
class _PrimaryBLACS(Device):
462+
pass
463+
464+
class _RemoteConnection(Device):
437465
@set_passed_properties(
438466
property_names = {}
439467
)
440-
def __init__(self, name, external_address):
441-
Device.__init__(self, name, None, None)
442-
# this is the address:port the parent BLACS will connect on
443-
self.BLACS_connection = str(external_address)
444-
445-
def __call__(self, port):
446-
""" This modifies the connection string so that a parent BLACS knows not to instantiate it directly"""
447-
return '%s%s%s'%(self.name, self.delimeter, port)
448-
449-
450-
class RemoteWorkerBroker(_RemoteBLACSConnection):
451-
pass
452-
453-
454-
class SecondaryControlSystem(_RemoteBLACSConnection):
455-
pass
456-
468+
def __init__(self, name, parent=None, connection=None):
469+
if parent is None:
470+
# define a hidden parent of top level remote connections so that
471+
# "connection" is stored correctly in the connection table
472+
if compiler._PrimaryBLACS is None:
473+
compiler._PrimaryBLACS = _PrimaryBLACS('__PrimaryBLACS', None, None)
474+
parent = compiler._PrimaryBLACS
475+
Device.__init__(self, name, parent, connection)
476+
477+
478+
class RemoteBLACS(_RemoteConnection):
479+
def __init__(self, name, host, port=7340, parent=None):
480+
_RemoteConnection.__init__(self, name, parent, "%s:%s"%(host, port))
481+
482+
483+
class SecondaryControlSystem(_RemoteConnection):
484+
def __init__(self, name, host, port, parent=None):
485+
_RemoteConnection.__init__(self, name, parent, "%s:%s"%(host, port))
486+
457487

458488
class IntermediateDevice(Device):
459489

@@ -1944,6 +1974,11 @@ def generate_connection_table(hdf5_file):
19441974
else:
19451975
BLACS_connection = ""
19461976

1977+
#if there is no BLACS connection, make sure there is no "gui" or "worker" entry in the connection table properties
1978+
if 'worker' in properties or 'gui' in properties:
1979+
raise LabscriptError('You cannot specify a remote GUI or worker for a device (%s) that does not have a tab in BLACS'%(device.name))
1980+
1981+
19471982
connection_table.append((device.name, device.__class__.__name__,
19481983
device.parent_device.name if device.parent_device else str(None),
19491984
str(device.connection if device.parent_device else str(None)),
@@ -2241,6 +2276,7 @@ def labscript_cleanup():
22412276
compiler.trigger_duration = 0
22422277
compiler.wait_delay = 0
22432278
compiler.time_markers = {}
2279+
compiler._PrimaryBLACS = None
22442280

22452281
class compiler:
22462282
# The labscript file being compiled:
@@ -2258,6 +2294,7 @@ class compiler:
22582294
trigger_duration = 0
22592295
wait_delay = 0
22602296
time_markers = {}
2297+
_PrimaryBLACS = None
22612298

22622299
# safety measure in case cleanup is called before init
22632300
_existing_builtins_dict = _builtins_dict.copy()

0 commit comments

Comments
 (0)