Skip to content

Commit d6b042a

Browse files
committed
Extend device_base_class.py test script to include DummyIntermediateDevice,
with Enum outputs.
1 parent 10fae2b commit d6b042a

1 file changed

Lines changed: 80 additions & 6 deletions

File tree

blacs/device_base_class.py

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -754,18 +754,20 @@ def shutdown(self):
754754

755755
def program_manual(self,front_panel_values):
756756
for channel,value in front_panel_values.items():
757-
if type(value) != type(True):
757+
if isinstance(value, float):
758758
front_panel_values[channel] += 0.001
759759
self.fpv = front_panel_values
760760
return front_panel_values
761761

762762
def check_remote_values(self):
763763
front_panel_values = {}
764764
for channel,value in self.fpv.items():
765-
if type(value) != type(True):
765+
if isinstance(value, float):
766766
front_panel_values[channel] = value + 1.1
767-
else:
767+
elif isinstance(value, bool):
768768
front_panel_values[channel] = not value
769+
else:
770+
front_panel_values[channel] = value
769771

770772
if not front_panel_values:
771773
front_panel_values['ao0'] = 0
@@ -775,7 +777,7 @@ def check_remote_values(self):
775777
def transition_to_buffered(self,device_name,h5file,front_panel_values,refresh):
776778
time.sleep(3)
777779
for channel,value in front_panel_values.items():
778-
if type(value) != type(True):
780+
if isinstance(value, float):
779781
front_panel_values[channel] += 0.003
780782
return front_panel_values
781783

@@ -816,7 +818,7 @@ def transition_to_manual(self):
816818
from labscript_utils.connections import ConnectionTable
817819
from labscript_utils.qtwidgets.dragdroptab import DragDropTabWidget
818820

819-
class MyTab(DeviceTab):
821+
class MyDAQTab(DeviceTab):
820822

821823
def initialise_GUI(self):
822824
# Create Digital Output Objects
@@ -868,6 +870,77 @@ def sort(channel):
868870
button2 = QPushButton("Transition to Manual")
869871
button2.clicked.connect(lambda: self.transition_to_manual(Queue()))
870872
self.get_tab_layout().addWidget(button2)
873+
874+
class MyDummyTab(DeviceTab):
875+
876+
def initialise_GUI(self):
877+
# Create Digital Output Objects
878+
do_prop = {}
879+
for i in range(1):
880+
do_prop['port0/line%d'] = {}
881+
self.create_digital_outputs(do_prop)
882+
883+
# Create Analog Output objects
884+
ao_prop = {}
885+
for i in range(1):
886+
ao_prop['ao%d'%i] = {'base_unit':'V',
887+
'min':-10.0,
888+
'max':10.0,
889+
'step':0.01,
890+
'decimals':3
891+
}
892+
self.create_analog_outputs(ao_prop)
893+
894+
eo_prop = {
895+
'Enum1':{
896+
'options':['option 1', 'option 2'],
897+
'return_index':True,
898+
},
899+
'Enum2':{
900+
'options':{
901+
'option 1':{'index':2, 'tooltip':'description 1'},
902+
'option 2':4,
903+
}
904+
}
905+
}
906+
self.create_enum_outputs(eo_prop)
907+
908+
# Create widgets for output objects
909+
dds_widgets,ao_widgets,do_widgets = self.auto_create_widgets()
910+
eo_widgets = self.auto_create_enum_widgets()
911+
912+
# This function allows you do sort the order of widgets by hardware name.
913+
# it is pass to the Python 'sorted' function as key=sort when passed in as
914+
# the 3rd item of a tuple p(the tuple being an argument of self.auto_place_widgets()
915+
#
916+
# This function takes the channel name (hardware name) and returns a string (or whatever)
917+
# that when sorted alphabetically, returns the correct order
918+
def sort(channel):
919+
port,line = channel.replace('port','').replace('line','').split('/')
920+
port,line = int(port),int(line)
921+
return '%02d/%02d'%(port,line)
922+
923+
# and auto place them in the UI
924+
self.auto_place_widgets(("DDS Outputs",dds_widgets),
925+
("Analog Outputs",ao_widgets),
926+
("Digital Outputs - Port 0",do_widgets),
927+
('Enums', eo_widgets))
928+
929+
# Set the primary worker
930+
self.create_worker("my_worker_name",DeviceWorker,{})
931+
self.primary_worker = "my_worker_name"
932+
self.create_worker("my_secondary_worker_name",DeviceWorker,{})
933+
self.add_secondary_worker("my_secondary_worker_name")
934+
935+
self.supports_remote_value_check(True)
936+
937+
# Create buttons to test things!
938+
button1 = QPushButton("Transition to Buffered")
939+
button1.clicked.connect(lambda: self.transition_to_buffered('',Queue()))
940+
self.get_tab_layout().addWidget(button1)
941+
button2 = QPushButton("Transition to Manual")
942+
button2.clicked.connect(lambda: self.transition_to_manual(Queue()))
943+
self.get_tab_layout().addWidget(button2)
871944

872945
connection_table = ConnectionTable('../tests/device_base_classes_connection_table.h5')
873946

@@ -895,7 +968,8 @@ def add_my_tab(self,tab):
895968
notebook = DragDropTabWidget()
896969
layout.addWidget(notebook)
897970

898-
tab1 = MyTab(notebook,settings = {'device_name': 'ni_pcie_6363_0', 'connection_table':connection_table})
971+
tab1 = MyDAQTab(notebook,settings = {'device_name': 'ni_pcie_6363_0', 'connection_table':connection_table})
972+
tab2 = MyDummyTab(notebook,settings = {'device_name': 'intermediate_device', 'connection_table':connection_table})
899973
window.add_my_tab(tab1)
900974
window.show()
901975
def run():

0 commit comments

Comments
 (0)