diff --git a/Gui/QtGUIutils/QtStartWindow.py b/Gui/QtGUIutils/QtStartWindow.py index a504b596..ca86cba3 100644 --- a/Gui/QtGUIutils/QtStartWindow.py +++ b/Gui/QtGUIutils/QtStartWindow.py @@ -571,7 +571,7 @@ def openRunWindow_starter(self): self.NextButton.setDisabled(True) self.NextButton.setText(". . .") # Only show the waiting popup if coldbox is present - if self._check_instrument_presence("cb"): + if cooler == "Tessie": self.waiting_popup = QMessageBox(self) self.waiting_popup.setWindowTitle("Waiting for Coldbox") self.waiting_popup.setText("Waiting for Coldbox to reach target temperature...") @@ -674,165 +674,25 @@ def openRunWindow(self): def update_instrument_cluster(self): if hasattr(self.master, 'instruments') and 'auto' in json_setup: logger.info("Automatically setting instrument cluster channels.") - has_cb = self._check_instrument_presence("cb") - has_hb = self._check_instrument_presence("hb") - channels_dict = self._create_channels_dict(has_cb, has_hb) - self._update_module_dict(channels_dict) - - def _check_instrument_presence(self, instrument_key): - """Check if a specific instrument key exists in the instrument dictionary.""" - instrument_dict = self.master.instruments.get_instruments() - logger.debug(f"Checking for instrument key '{instrument_key}' in instrument_dict: {instrument_dict.keys()}") - return instrument_key in instrument_dict - - def _create_channels_dict(self, has_cb, has_hb): - """Create the channels dictionary based on the presence of coldbox and hb.""" - if len(WorkingChannels) < len(self.BeBoardWidget.getModules()): - logger.error("Not enough working channels defined in siteConfig.WorkingChannels.") - raise ValueError("Insufficient working channels in siteConfig.WorkingChannels.") - - channels_dict = {} - for index, module in enumerate(self.BeBoardWidget.getModules()): - try: - if WorkingChannels[index] < 5: - channels_dict[index] = self._create_channel_entry("lv_1", WorkingChannels[index], WorkingChannels[index], has_cb, has_hb) - logger.info(f"Added channel {index} with lv_1 and hv.") - else: - channels_dict[index] = self._create_channel_entry("lv_2", WorkingChannels[index]-4, WorkingChannels[index], has_cb, has_hb) - logger.info(f"Added channel {index} with lv_2 and hv.") - except IndexError: - logger.error(f"No working channel defined for module index {index}.") - raise ValueError(f"WorkingChannels does not have enough entries for module index {index}.") - - logger.info(f"Final module_dict: {channels_dict}") - return channels_dict - - def _create_channel_entry(self, lv_instrument, lv_channel, cb_channel, has_cb, has_hb): - """Create a single channel entry for the channels dictionary.""" - channel_entry = { - "lv": { - "instrument": lv_instrument, - "channel": lv_channel - }, - "hv": { - "instrument": "hv", - "channel": 1 - } - } - if has_cb: - channel_entry["cb"] = { - "instrument": "cb", - "channel": cb_channel - } - if has_hb: - channel_entry["hb"] = { - "instrument": "hb", - "channel": cb_channel - } - return channel_entry - - def _update_module_dict(self, channels_dict): - """Update self._module_dict with DummyInstrument and Power/TempChannel objects using InstrumentCluster's instrument dictionary.""" - if not hasattr(self.master, 'instruments'): - raise AttributeError("Master does not have an 'instruments' attribute.") - - instrument_dict = self.master.instruments.get_instruments() - self._module_dict = {} - for number, channel in channels_dict.items(): - temp_dict = {} - if "lv" in channel.keys(): - instr_object = instrument_dict[channel["lv"]["instrument"]] - instr_object.role = "lv" - temp_dict["lv"] = instr_object.channel( - "PowerChannel", channel["lv"]["channel"] - ) - temp_dict["lv"].instr_name = channel["lv"]["instrument"] - else: - temp_dict["lv"] = DummyInstrument("lv") - - if "hv" in channel.keys(): - instr_object = instrument_dict[channel["hv"]["instrument"]] - instr_object.role = "hv" - temp_dict["hv"] = instr_object.channel( - "PowerChannel", channel["hv"]["channel"] - ) - temp_dict["hv"].instr_name = channel["hv"]["instrument"] - else: - temp_dict["hv"] = DummyInstrument("hv") - - temp_dict["ab"] = DummyInstrument("ab") - if "cb" in channel.keys(): - instr_object = instrument_dict[channel["cb"]["instrument"]] - instr_object.role = "cb" - temp_dict["cb"] = instr_object.channel( - "TemperatureChannel", channel["cb"]["channel"] - ) - temp_dict["cb"].instr_name = channel["cb"]["instrument"] - assert hasattr(instr_object, "default_temperature") - temp_dict["cb"].default_temperature = float( - instr_object.default_temperature - ) - temp_dict["cb"].default_step_size = ( - instr_object.default_speed - if hasattr(instr_object, "default_speed") - else 0 - ) - temp_dict["cb"].temperature_tolerance = ( - instr_object.temperature_tolerance - if hasattr(instr_object, "temperature_tolerance") - else 0.5 - ) - temp_dict["cb"].validation_time = ( - instr_object.validation_time - if hasattr(instr_object, "validation_time") - else 20 - ) - temp_dict["cb"].validation_timeout = ( - instr_object.validation_timeout - if hasattr(instr_object, "validation_timeout") - else 600 - ) - temp_dict["cb"].humidity_control = ( - instr_object.humidity_control - if hasattr(instr_object, "humidity_control") - else True - ) - temp_dict["cb"].dewpoint_delta = ( - instr_object.dewpoint_delta - if hasattr(instr_object, "dewpoint_delta") - else 1.0 - ) - else: - temp_dict["cb"] = DummyInstrument("cb") - - if "hb" in channel: - instr_object = instrument_dict[channel["hb"]["instrument"]] - assert hasattr(instr_object, "channel_compliance") - hvbox_cfg = { - "instrument": instr_object, - "source_instr": instrument_dict[channel["hv"]["instrument"]], - "source_channel": channel["hv"]["channel"], - "hvbox_channel": channel["hb"]["channel"], - "channel_compliance": float(instr_object.channel_compliance), - } - self.master.instruments._hvbox_config[number] = hvbox_cfg - else: - temp_dict["hb"] = DummyInstrument("hb") - - self._module_dict[number] = temp_dict - self.master.instruments._module_dict[number] = temp_dict - print("Get HB: ", self.master.instruments.get_hb()) - - self.master.instruments.open() - keys_to_remove = [key for key in self.master.instruments._module_dict.keys() if isinstance(key, str)] + self._update_module_dict(UsedChannels=self._get_used_channels()) + + def _get_used_channels(self): + UsedChannels = WorkingChannels[:len(self.BeBoardWidget.getModules())] + logger.info(f"Working channels being used: {UsedChannels}") + return UsedChannels + + def _update_module_dict(self, UsedChannels): + keys_to_remove = [key for key in self.master.instruments._module_dict.keys()] + for key in UsedChannels: + if str(key-1) in keys_to_remove: + keys_to_remove.remove(str(key-1)) for key in keys_to_remove: self.master.instruments._module_dict.pop(key) - logger.debug(f"Module Dict:",self.master.instruments.get_modules()) - logger.debug(f"Instruments:",self.master.instruments.get_instruments()) + logger.info(f"Module Dict:",self.master.instruments.get_modules()) + logger.info(f"Instruments:",self.master.instruments.get_instruments()) def set_default_temperature(self): """Set the temperature of every active TEC to the default temperature if 'Tessie' is chosen as the cooler.""" - print("Get HB:", self.master.instruments.get_hb()) if cooler == "Tessie": try: default_temperature = icicle_instrument_setup["instrument_dict"]["cb"]["default_temperature"] diff --git a/Gui/jsonFiles/instruments_osu_auto.json b/Gui/jsonFiles/instruments_osu_auto.json index d7df9658..f7947f3d 100644 --- a/Gui/jsonFiles/instruments_osu_auto.json +++ b/Gui/jsonFiles/instruments_osu_auto.json @@ -17,14 +17,14 @@ "cb": { "class": "PSIColdbox", "resource": "TCPIP::coldbox::1883::SOCKET", - "default_temperature": -35, + "default_temperature": -10, "temperature_tolerance": 0.5, "validation_time": 20, "validation_timeout": 600 }, "hb": { "class": "PSIHVBox", - "resource": "ASRL/dev/ttyACM2::INSTR", + "resource": "ASRL/dev/ttyACM1::INSTR", "channel_compliance": 5e-6 }, "hv": { @@ -38,42 +38,50 @@ "channels_dict":{ "0":{ "lv": {"instrument":"lv_1", "channel":1}, - "cb": {"instrument":"cb", "channel":1}, + "cb": {"instrument":"cb", "channel":1}, + "hb": {"instrument":"hb", "channel":1}, "hv": {"instrument":"hv", "channel":1} }, "1":{ "lv": {"instrument":"lv_1", "channel":2}, - "cb": {"instrument":"cb", "channel":2}, + "cb": {"instrument":"cb", "channel":2}, + "hb": {"instrument":"hb", "channel":2}, "hv": {"instrument":"hv", "channel":1} }, "2":{ "lv": {"instrument":"lv_1", "channel":3}, - "cb": {"instrument":"cb", "channel":3}, + "cb": {"instrument":"cb", "channel":3}, + "hb": {"instrument":"hb", "channel":3}, "hv": {"instrument":"hv", "channel":1} }, "3":{ "lv": {"instrument":"lv_1", "channel":4}, - "cb": {"instrument":"cb", "channel":4}, + "cb": {"instrument":"cb", "channel":4}, + "hb": {"instrument":"hb", "channel":4}, "hv": {"instrument":"hv", "channel":1} }, "4":{ "lv": {"instrument":"lv_2", "channel":1}, - "cb": {"instrument":"cb", "channel":5}, + "cb": {"instrument":"cb", "channel":5}, + "hb": {"instrument":"hb", "channel":5}, "hv": {"instrument":"hv", "channel":1} }, "5":{ "lv": {"instrument":"lv_2", "channel":2}, - "cb": {"instrument":"cb", "channel":6}, + "cb": {"instrument":"cb", "channel":6}, + "hb": {"instrument":"hb", "channel":6}, "hv": {"instrument":"hv", "channel":1} }, "6":{ "lv": {"instrument":"lv_2", "channel":3}, - "cb": {"instrument":"cb", "channel":7}, + "cb": {"instrument":"cb", "channel":7}, + "hb": {"instrument":"hb", "channel":7}, "hv": {"instrument":"hv", "channel":1} }, "7":{ "lv": {"instrument":"lv_2", "channel":4}, - "cb": {"instrument":"cb", "channel":8}, + "cb": {"instrument":"cb", "channel":8}, + "hb": {"instrument":"hb", "channel":8}, "hv": {"instrument":"hv", "channel":1} } }