def cb_get_statistics(self, statistics): self.label_messages_from_brick.setText( str(statistics.messages_from_brick)) self.label_messages_from_bricklet.setText( str(statistics.messages_from_bricklet)) try: name = infos.get_info(statistics.connected_bricklet_uid ).plugin.device_class.DEVICE_DISPLAY_NAME except: name = None if statistics.connected_bricklet_uid != '' and name != None: self.label_isolated_bricklet.setText( '<b>{0}</b> with UID "{1}"'.format( name, statistics.connected_bricklet_uid)) self.button_bricklet.setText('Open {0}'.format(name)) if self.last_connected != statistics.connected_bricklet_uid: self.last_connected = statistics.connected_bricklet_uid try: self.button_bricklet.clicked.disconnect() except: pass self.button_bricklet.clicked.connect(lambda: get_main_window( ).show_plugin(statistics.connected_bricklet_uid)) self.button_bricklet.setEnabled(True) else: self.label_isolated_bricklet.setText( 'Unknown Bricklet (Did you connect a Bricklet?)') self.button_bricklet.setText('Open Bricklet') self.button_bricklet.setEnabled(False)
def cb_statistics(self, statistics): self.label_messages_from_brick.setText(str(statistics.messages_from_brick)) self.label_messages_from_bricklet.setText(str(statistics.messages_from_bricklet)) try: name = infos.get_info(statistics.connected_bricklet_uid).plugin.device_class.DEVICE_DISPLAY_NAME except: name = None if statistics.connected_bricklet_uid != '' and name != None: self.label_isolated_bricklet.setText('<b>{0}</b> with UID "{1}"'.format(name, statistics.connected_bricklet_uid)) self.button_bricklet.setText('Open {0}'.format(name)) if self.last_connected != statistics.connected_bricklet_uid: self.last_connected = statistics.connected_bricklet_uid try: self.button_bricklet.clicked.disconnect() except: pass self.button_bricklet.clicked.connect(lambda: get_main_window().show_plugin(statistics.connected_bricklet_uid)) self.button_bricklet.setEnabled(True) else: self.label_isolated_bricklet.setText('Unknown Bricklet (Did you connect a Bricklet?)') self.button_bricklet.setText('Open Bricklet') self.button_bricklet.setEnabled(False)
def remove_device_info(self, uid): tab_id = self.tab_for_uid(uid) device_info = infos.get_info(uid) device_info.plugin.stop_plugin() device_info.plugin.destroy_plugin() if tab_id >= 0: self.tab_widget.removeTab(tab_id) # ensure that the widget gets correctly destroyed. otherwise QWidgets # tend to leak as Python is not able to collect their PyQt object tab_window = device_info.tab_window device_info.tab_window = None # If we reboot the RED Brick, the tab_window sometimes is # already None here if tab_window != None: tab_window.hide() tab_window.setParent(None) plugin = device_info.plugin device_info.plugin = None if plugin != None: plugin.hide() plugin.setParent(None) infos.remove_info(uid)
def show_plugin(self, uid): i = self.tab_for_uid(uid) tab_window = infos.get_info(uid).tab_window if i > 0 and self.tab_widget.isTabEnabled(i): self.tab_widget.setCurrentIndex(i) QApplication.setActiveWindow(tab_window) tab_window.show() tab_window.activateWindow() tab_window.raise_()
def update_addresses(self): self.update_address = 0 self.update_address_slave = 0 def get_rs485_address_async(address_async): self.update_address = address_async self.update_generator.next() def get_rs485_slave_address_async(update_address_slave_async): self.update_address_slave = update_address_slave_async self.update_generator.next() async_call(self.master.get_rs485_address, None, get_rs485_address_async, self.parent.increase_error_count) yield address_slave = [] for i in range(32): async_call(self.master.get_rs485_slave_address, i, get_rs485_slave_address_async, self.parent.increase_error_count) yield if self.update_address_slave == 0: break else: address_slave.append(str(self.update_address_slave)) address_slave_text = ', '.join(address_slave) typ = 0 if self.update_address == 0: typ = 1 # trigger enumerate for rs485 slaves if infos.get_info( self.parent.uid ).enumeration_type == IPConnection.ENUMERATION_TYPE_CONNECTED: self.parent.ipcon.enumerate() self.lineedit_slave_addresses.setText(address_slave_text) self.address_spinbox.setValue(self.update_address) self.save_button.clicked.connect(self.save_clicked) self.rs485_type.currentIndexChanged.connect(self.rs485_type_changed) self.rs485_type.setCurrentIndex(typ) self.rs485_type_changed(typ)
def show_plugin(self, uid): device_info = infos.get_info(uid) if device_info == None: return index = self.tab_for_uid(uid) tab_window = device_info.tab_window if index > 0 and self.tab_widget.isTabEnabled(index): self.tab_widget.setCurrentIndex(index) QApplication.setActiveWindow(tab_window) tab_window.show() tab_window.activateWindow() tab_window.raise_()
def update_bricklets(self): try: bricklets = infos.get_info(self.uid).connections for i in range(8): port = chr(ord('a') + i) try: bricklet = bricklets[port] text = '{0} ({1})'.format(bricklet.name, bricklet.uid) if text != self.ports[i].text(): self.ports[i].setText(text) self.ports[ i].mousePressEvent = self.get_port_label_clicked_lambda( bricklet.uid) except: self.ports[i].setText('Not Connected') except: pass
def refresh_updates_clicked_second_step(self, is_update, items, protocol1_errors): protocol1_error_still_there = False # filter out false-positive protocol1 errors for device_uid in protocol1_errors: if infos.get_info(device_uid) != None: protocol1_error_still_there = True continue for i in range(len(items)): if items[i][0].data(Qt.UserRole) == device_uid: del items[i] break for item in items: self.update_tree_view_model.appendRow(item) self.update_tree_view.expandAll() self.update_tree_view.setColumnWidth(0, 260) self.update_tree_view.setColumnWidth(1, 75) self.update_tree_view.setColumnWidth(2, 75) self.update_tree_view.setColumnWidth(3, 75) self.update_tree_view.setSortingEnabled(True) self.update_tree_view.header().setSortIndicator(0, Qt.AscendingOrder) if is_update: self.update_button_bricklets.setEnabled(True) else: self.update_button_bricklets.setEnabled(False) self.brick_changed(self.combo_brick.currentIndex()) self.update_button_refresh.setDisabled(False) if protocol1_error_still_there: message = """ There was an error during the auto-detection of Bricklets with Protocol 1.0 plugins. Those cannot be updated automatically, but you can update them manually: - Disconnect the affected Bricklets from their Brick and restart the Brick without the Bricklets. - Ensure that the Brick shows up correctly. - Connect the Bricklet to the Brick again, while the Brick is already running. - Select the "Bricklet" tab and update the plugin manually. """ QMessageBox.critical(self, "Bricklet with Error", message, QMessageBox.Ok)
def update_addresses(self): self.update_address = 0 self.update_address_slave = 0 def get_rs485_address_async(address_async): self.update_address = address_async self.update_generator.next() def get_rs485_slave_address_async(update_address_slave_async): self.update_address_slave = update_address_slave_async self.update_generator.next() async_call(self.master.get_rs485_address, None, get_rs485_address_async, self.parent.increase_error_count) yield address_slave = [] for i in range(32): async_call(self.master.get_rs485_slave_address, i, get_rs485_slave_address_async, self.parent.increase_error_count) yield if self.update_address_slave == 0: break else: address_slave.append(str(self.update_address_slave)) address_slave_text = ', '.join(address_slave) typ = 0 if self.update_address == 0: typ = 1 # trigger enumerate for rs485 slaves if infos.get_info(self.parent.uid).enumeration_type == IPConnection.ENUMERATION_TYPE_CONNECTED: self.parent.ipcon.enumerate() self.lineedit_slave_addresses.setText(address_slave_text) self.address_spinbox.setValue(self.update_address) self.save_button.clicked.connect(self.save_clicked) self.rs485_type.currentIndexChanged.connect(self.rs485_type_changed) self.rs485_type.setCurrentIndex(typ) self.rs485_type_changed(typ)
def update_bricklets(self): info = infos.get_info(self.uid) if info == None: return for i in range(4): port = chr(ord('a') + i) try: bricklet = info.connections_get(port)[0] text = '{0} ({1})'.format(bricklet.name, bricklet.uid) if text != self.ports[i].text(): self.ports[i].setText(text) self.ports[i].setProperty('_bricklet_uid', bricklet.uid) self.ports[i].setEnabled(True) except: self.ports[i].setText('Not Connected') self.ports[i].setProperty('_bricklet_uid', None) self.ports[i].setEnabled(False)
def refresh_updates_clicked(self): if self.tab_widget.currentIndex() != 0: self.refresh_updates_pending = True return self.update_button_refresh.setDisabled(True) self.refresh_updates_pending = False url_part_proto1_map = { # 'name': 'url_part' 'Ambient Light Bricklet': 'ambient_light', 'Analog In Bricklet': 'analog_in', 'Analog Out Bricklet': 'analog_out', 'Barometer Bricklet': 'barometer', 'Current12 Bricklet': 'current12', 'Current25 Bricklet': 'current25', 'Distance IR Bricklet': 'distance_ir', 'Dual Relay Bricklet': 'dual_relay', 'GPS Bricklet': 'gps', 'Humidity Bricklet': 'humidity', 'Industrial Digital In 4 Bricklet': 'industrial_digital_in_4', 'Industrial Digital Out 4 Bricklet': 'industrial_digital_out_4', 'Industrial Quad Relay Bricklet': 'industrial_quad_relay', 'IO-16 Bricklet': 'io16', 'IO-4 Bricklet': 'io4', 'Joystick Bricklet': 'joystick', 'LCD 16x2 Bricklet': 'lcd_16x2', 'LCD 20x4 Bricklet': 'lcd_20x4_v11', 'Linear Poti Bricklet': 'linear_poti', 'Piezo Buzzer Bricklet': 'piezo_buzzer', 'Rotary Poti Bricklet': 'rotary_poti', 'Temperature Bricklet': 'temperature', 'Temperature-IR Bricklet': 'temperature_ir', 'Voltage Bricklet': 'voltage', 'Voltage/Current Bricklet': 'voltage_current', } progress = self.create_progress_bar('Discovering') okay = True try: urllib2.urlopen(FIRMWARE_URL, timeout=10).read() self.no_connection_label.hide() except urllib2.URLError: okay = False progress.cancel() self.no_connection_label.show() return if okay: self.refresh_latest_version_info(progress) def get_color_for_device(device): if device.firmware_version_installed >= device.firmware_version_latest: return None, False if device.firmware_version_installed[0] <= 1: return QBrush(Qt.red), True return QBrush(QColor(255, 160, 55)), True try: infos.get_info(infos.UID_BRICKV).firmware_version_latest = self.tool_infos['brickv'].firmware_version_latest except: infos.get_info(infos.UID_BRICKV).firmware_version_latest = (0, 0, 0) for device_info in infos.get_device_infos(): if device_info.type == 'brick': try: device_info.firmware_version_latest = self.firmware_infos[device_info.url_part].firmware_version_latest except: device_info.firmware_version_latest = (0, 0, 0) elif device_info.type == 'bricklet': try: device_info.firmware_version_latest = self.plugin_infos[device_info.url_part].firmware_version_latest except: device_info.firmware_version_latest = (0, 0, 0) progress.cancel() self.update_tree_view_model.clear() self.update_tree_view_model.setHorizontalHeaderLabels(self.update_tree_view_model_labels) is_update = False protocol1_errors = set() items = [] for device_info in infos.get_infos(): if device_info.type == 'brick': parent = [QStandardItem(device_info.name), QStandardItem(device_info.uid), QStandardItem(get_version_string(device_info.firmware_version_installed)), QStandardItem(get_version_string(device_info.firmware_version_latest))] color, update = get_color_for_device(device_info) if update: is_update = True for item in parent: item.setFlags(item.flags() & ~Qt.ItemIsEditable) item.setData(color, Qt.BackgroundRole) parent[0].setData(device_info.uid, Qt.UserRole) items.append(parent) for port in device_info.bricklets: if not device_info.bricklets[port] or device_info.bricklets[port].protocol_version == 1: try: protv, fw, name = device_info.plugin.device.get_protocol1_bricklet_name(port) except: protocol1_errors.add(device_info.uid) child = [QStandardItem(port.upper() + ': Protocol 1.0 Bricklet with Error'), QStandardItem(''), QStandardItem(''), QStandardItem('')] for item in child: item.setFlags(item.flags() & ~Qt.ItemIsEditable) item.setData(QBrush(Qt.magenta), Qt.BackgroundRole) parent[0].appendRow(child) continue if protv == 1: # Hack for LCD 20x4 Bricklet (name is not set early enough in firmware) if fw == (1, 1, 1) and name == '': name = 'LCD 20x4 Bricklet' bricklet_info = infos.BrickletInfo() bricklet_info.protocol_version = 1 bricklet_info.name = name bricklet_info.position = port bricklet_info.firmware_version_installed = tuple(fw) device_info.bricklets[port] = bricklet_info for key in url_part_proto1_map: if key in device_info.bricklets[port].name: bricklet_info.url_part = url_part_proto1_map[key] break try: bricklet_info.firmware_version_latest = self.plugin_infos[bricklet_info.url_part].firmware_version_latest except KeyError: pass if device_info.bricklets[port]: child = [QStandardItem(port.upper() + ': ' + device_info.bricklets[port].name), QStandardItem(device_info.bricklets[port].uid), QStandardItem(get_version_string(device_info.bricklets[port].firmware_version_installed)), QStandardItem(get_version_string(device_info.bricklets[port].firmware_version_latest))] color, update = get_color_for_device(device_info.bricklets[port]) if update: is_update = True for item in child: item.setFlags(item.flags() & ~Qt.ItemIsEditable) item.setData(color, Qt.BackgroundRole) parent[0].appendRow(child) elif device_info.type == 'tool' and 'Brick Viewer' in device_info.name: parent = [QStandardItem(device_info.name), QStandardItem(''), QStandardItem(get_version_string(device_info.firmware_version_installed)), QStandardItem(get_version_string(device_info.firmware_version_latest))] color, update = get_color_for_device(device_info) if update: self.update_tool_label.show() else: self.update_tool_label.hide() for item in parent: item.setFlags(item.flags() & ~Qt.ItemIsEditable) item.setData(color, Qt.BackgroundRole) items.append(parent) t = 0 if len(protocol1_errors) > 0: # if there were protocol1 errors give the enumerate callback a # chance to update the infos to have correct information to filter # out false-positive protocol1 errors that were detected due to # fast USB unplug t = 200 QTimer.singleShot(t, lambda: self.refresh_updates_clicked_second_step(is_update, items, protocol1_errors))
def cb_enumerate(self, uid, connected_uid, position, hardware_version, firmware_version, device_identifier, enumeration_type): if self.ipcon.get_connection_state( ) != IPConnection.CONNECTION_STATE_CONNECTED: # ignore enumerate callbacks that arrived after the connection got closed return if enumeration_type in [ IPConnection.ENUMERATION_TYPE_AVAILABLE, IPConnection.ENUMERATION_TYPE_CONNECTED ]: device_info = infos.get_info(uid) something_changed_ref = [False] if device_info == None: if device_identifier == BrickMaster.DEVICE_IDENTIFIER: device_info = infos.BrickMasterInfo() elif device_identifier == BrickRED.DEVICE_IDENTIFIER: device_info = infos.BrickREDInfo() elif position in ('a', 'b', 'c', 'd', 'A', 'B', 'C', 'D'): position = position.lower() device_info = infos.BrickletInfo() else: device_info = infos.BrickInfo() something_changed_ref[0] = True def set_device_info_value(name, value): if getattr(device_info, name) != value: setattr(device_info, name, value) something_changed_ref[0] = True set_device_info_value('uid', uid) set_device_info_value('connected_uid', connected_uid) set_device_info_value('position', position) set_device_info_value('hardware_version', hardware_version) set_device_info_value('firmware_version_installed', firmware_version) set_device_info_value('device_identifier', device_identifier) set_device_info_value('protocol_version', 2) set_device_info_value('enumeration_type', enumeration_type) if device_info.type == 'bricklet': for brick_info in infos.get_brick_infos(): if brick_info.uid == device_info.connected_uid: if brick_info.bricklets[position] != device_info: brick_info.bricklets[position] = device_info something_changed_ref[0] = True elif device_info.type == 'brick': for bricklet_info in infos.get_bricklet_infos(): if bricklet_info.connected_uid == device_info.uid: if device_info.bricklets[ bricklet_info.position] != bricklet_info: device_info.bricklets[ bricklet_info.position] = bricklet_info something_changed_ref[0] = True if device_info.plugin == None: self.plugin_manager.create_plugin_instance( device_identifier, self.ipcon, device_info) device_info.tab_window = self.create_tab_window(device_info) device_info.tab_window.setWindowFlags(Qt.Widget) device_info.tab_window.tab() infos.add_info(device_info) something_changed_ref[0] = True if something_changed_ref[0]: self.update_tree_view() elif enumeration_type == IPConnection.ENUMERATION_TYPE_DISCONNECTED: for device_info in infos.get_device_infos(): if device_info.uid == uid: self.tab_widget.setCurrentIndex(0) self.remove_device_info(device_info.uid) if device_info.type == 'brick': for port in device_info.bricklets: if device_info.bricklets[ port] and device_info.bricklets[ port].uid == uid: device_info.bricklets[port] = None self.update_tree_view()
def cb_enumerate(self, uid, connected_uid, position, hardware_version, firmware_version, device_identifier, enumeration_type): if self.ipcon.get_connection_state() != IPConnection.CONNECTION_STATE_CONNECTED: # ignore enumerate callbacks that arrived after the connection got closed return if enumeration_type in [IPConnection.ENUMERATION_TYPE_AVAILABLE, IPConnection.ENUMERATION_TYPE_CONNECTED]: device_info = infos.get_info(uid) something_changed_ref = [False] if device_info == None: if device_identifier == BrickMaster.DEVICE_IDENTIFIER: device_info = infos.BrickMasterInfo() elif device_identifier == BrickRED.DEVICE_IDENTIFIER: device_info = infos.BrickREDInfo() elif position in ('a', 'b', 'c', 'd', 'A', 'B', 'C', 'D'): position = position.lower() device_info = infos.BrickletInfo() else: device_info = infos.BrickInfo() something_changed_ref[0] = True def set_device_info_value(name, value): if getattr(device_info, name) != value: setattr(device_info, name, value) something_changed_ref[0] = True set_device_info_value('uid', uid) set_device_info_value('connected_uid', connected_uid) set_device_info_value('position', position) set_device_info_value('hardware_version', hardware_version) set_device_info_value('firmware_version_installed', firmware_version) set_device_info_value('device_identifier', device_identifier) set_device_info_value('protocol_version', 2) set_device_info_value('enumeration_type', enumeration_type) if device_info.type == 'bricklet': for brick_info in infos.get_brick_infos(): if brick_info.uid == device_info.connected_uid: if brick_info.bricklets[position] != device_info: brick_info.bricklets[position] = device_info something_changed_ref[0] = True elif device_info.type == 'brick': for bricklet_info in infos.get_bricklet_infos(): if bricklet_info.connected_uid == device_info.uid: if device_info.bricklets[bricklet_info.position] != bricklet_info: device_info.bricklets[bricklet_info.position] = bricklet_info something_changed_ref[0] = True if device_info.plugin == None: plugin = self.plugin_manager.get_plugin(device_identifier, self.ipcon, uid, hardware_version, firmware_version) device_info.plugin = plugin device_info.name = plugin.name device_info.url_part = plugin.get_url_part() infos.add_info(device_info) device_info.tab_window = self.create_tab_window(device_info, connected_uid, position) device_info.tab_window.setWindowFlags(Qt.Widget) device_info.tab_window.tab() something_changed_ref[0] = True if something_changed_ref[0]: self.update_tree_view() elif enumeration_type == IPConnection.ENUMERATION_TYPE_DISCONNECTED: for device_info in infos.get_device_infos(): if device_info.uid == uid: self.tab_widget.setCurrentIndex(0) self.remove_device_info(device_info.uid) if device_info.type == 'brick': for port in device_info.bricklets: if device_info.bricklets[port] and device_info.bricklets[port].uid == uid: device_info.bricklets[port] = None self.update_tree_view()
def init_update(self): self.update_address = 0 self.update_chibi_slave_address = 0 self.update_chibi_master_address = 0 self.update_chibi_frequency = 0 self.update_chibi_channel = 0 def get_chibi_address_async(address_async): self.update_address = address_async self.update_generator.next() def get_chibi_slave_address_async(chibi_slave_address_async): self.update_chibi_slave_address = chibi_slave_address_async self.update_generator.next() def get_chibi_master_address_async(chibi_master_address_async): self.update_chibi_master_address = chibi_master_address_async self.update_generator.next() def get_chibi_frequency_async(chibi_frequency_async): self.update_chibi_frequency = chibi_frequency_async self.update_generator.next() def get_chibi_channel_async(chibi_channel_async): self.update_chibi_channel = chibi_channel_async self.update_generator.next() async_call(self.master.get_chibi_address, None, get_chibi_address_async, self.parent.increase_error_count) yield address_slave = [] for i in range(32): async_call(self.master.get_chibi_slave_address, i, get_chibi_slave_address_async, self.parent.increase_error_count) yield if self.update_chibi_slave_address == 0: break else: address_slave.append(str(self.update_chibi_slave_address)) address_slave_text = ', '.join(address_slave) async_call(self.master.get_chibi_master_address, None, get_chibi_master_address_async, self.parent.increase_error_count) yield async_call(self.master.get_chibi_frequency, None, get_chibi_frequency_async, self.parent.increase_error_count) yield async_call(self.master.get_chibi_channel, None, get_chibi_channel_async, self.parent.increase_error_count) yield typ = 0 if self.update_address == self.update_chibi_master_address: typ = 1 # trigger enumerate for chibi slaves if infos.get_info(self.parent.uid).enumeration_type == IPConnection.ENUMERATION_TYPE_CONNECTED: self.parent.ipcon.enumerate() self.lineedit_slave_address.setText(address_slave_text) self.address_spinbox.setValue(self.update_address) self.master_address_spinbox.setValue(self.update_chibi_master_address) self.chibi_frequency.setCurrentIndex(self.update_chibi_frequency) self.chibi_channel.setCurrentIndex(self.update_chibi_channel) self.save_button.clicked.connect(self.save_clicked) self.chibi_type.currentIndexChanged.connect(self.chibi_type_changed) self.chibi_frequency.currentIndexChanged.connect(self.chibi_frequency_changed) self.chibi_channel.currentIndexChanged.connect(self.chibi_channel_changed) self.chibi_type.setCurrentIndex(typ) self.chibi_type_changed(typ) self.new_max_count()
def update_red_brick_version(self, uid): if not isinstance(infos.get_info(uid), infos.BrickREDInfo): return self.update_tree_view()
def cb_enumerate(self, uid, connected_uid, position, hardware_version, firmware_version, device_identifier, enumeration_type): if self.ipcon.get_connection_state() != IPConnection.CONNECTION_STATE_CONNECTED: # ignore enumerate callbacks that arrived after the connection got closed return if enumeration_type in [IPConnection.ENUMERATION_TYPE_AVAILABLE, IPConnection.ENUMERATION_TYPE_CONNECTED]: device_info = infos.get_info(uid) something_changed_ref = [False] # If the enum_type is CONNECTED, the bricklet was restarted externally. # The plugin could now be in an inconsistent state. if enumeration_type == IPConnection.ENUMERATION_TYPE_CONNECTED and device_info is not None: if device_info.connected_uid != connected_uid: # Fix connections if bricklet was connected to another brick. parent_info = infos.get_info(device_info.connected_uid) if parent_info is not None: parent_info.connections.remove((device_info.position, device_info)) self.show_status("Hot plugging is not supported! Please reset the brick {} and restart brick viewer.".format(device_info.connected_uid)) device_info.reverse_connection = connected_uid elif device_info.position != position: # Bricklet was connected to the same brick, but to another port self.show_status("Hot plugging is not supported! Please reset the brick {} and restart brick viewer.".format(device_info.connected_uid)) # If the plugin is not running, pause will do nothing, so it is always save to call it. # The plugin will be (unconditionally) resumed later, as resume also only does something # if it was paused before (e.g. here). if device_info.plugin is not None: device_info.plugin.pause_plugin() if device_info == None: if device_identifier == BrickMaster.DEVICE_IDENTIFIER: device_info = infos.BrickMasterInfo() elif device_identifier == BrickRED.DEVICE_IDENTIFIER: device_info = infos.BrickREDInfo() elif hat_brick_supported and device_identifier == BrickHAT.DEVICE_IDENTIFIER: device_info = infos.BrickHATInfo() elif hat_zero_brick_supported and device_identifier == BrickHATZero.DEVICE_IDENTIFIER: device_info = infos.BrickHATZeroInfo() elif device_identifier == BrickletIsolator.DEVICE_IDENTIFIER: device_info = infos.BrickletIsolatorInfo() elif '0' <= position <= '9': device_info = infos.BrickInfo() something_changed_ref[0] = True else: device_info = infos.BrickletInfo() position = position.lower() def set_device_info_value(name, value): if getattr(device_info, name) != value: setattr(device_info, name, value) something_changed_ref[0] = True infos.get_infos_changed_signal().emit(device_info.uid) set_device_info_value('uid', uid) set_device_info_value('connected_uid', connected_uid) set_device_info_value('position', position) set_device_info_value('hardware_version', hardware_version) if device_identifier != BrickRED.DEVICE_IDENTIFIER: set_device_info_value('firmware_version_installed', firmware_version) set_device_info_value('device_identifier', device_identifier) set_device_info_value('enumeration_type', enumeration_type) # Update connections and reverse_connection with new device for info in infos.get_device_infos(): if info == device_info: continue def add_to_connections(info_to_add, connected_info): connected_info.connections.append((info_to_add.position, info_to_add)) info_to_add.reverse_connection = connected_info something_changed_ref[0] = True infos.get_infos_changed_signal().emit(connected_info.uid) if info.uid != '' and info.uid == device_info.connected_uid: if device_info in info.connections_values(): #Device was already connected, but to another port info.connections = [(pos, i) for pos, i in info.connections if i.uid != device_info.uid] if device_info not in info.connections_get(device_info.position): add_to_connections(device_info, info) if info.connected_uid != '' and info.connected_uid == device_info.uid: if info in device_info.connections_values(): #Device was already connected, but to another port device_info.connections = [(pos, i) for pos, i in device_info.connections if i.uid != info.uid] if info not in device_info.connections_get(info.position): add_to_connections(info, device_info) if device_info.plugin == None: plugin = self.plugin_manager.create_plugin_instance(device_identifier, self.ipcon, device_info) device_info.tab_window = self.create_tab_window(device_info, self.ipcon) device_info.tab_window.setWindowFlags(Qt.Widget) device_info.tab_window.tab() infos.add_info(device_info) something_changed_ref[0] = True if device_identifier == BrickRED.DEVICE_IDENTIFIER and isinstance(plugin, RED): plugin.get_image_version_async() plugin.get_bindings_versions_async() # The plugin was paused before if it was reconnected. device_info.plugin.resume_plugin() if something_changed_ref[0]: self.update_tree_view() elif enumeration_type == IPConnection.ENUMERATION_TYPE_DISCONNECTED: self.remove_device_tab(uid)