def connect_to_aeroquad(self): self._ui.status.setText("Connecting...") self._ui.buttonDisconnect.setEnabled(True) self._ui.buttonConnect.setEnabled(False) self._ui.comPort.setEnabled(False) self._ui.baudRate.setEnabled(False) self._app.processEvents() bootupDelay = float(self._xml.find("./Settings/BootUpDelay").text) commTimeOut = float(self._xml.find("./Settings/CommTimeOut").text) try: self._communicator.connect(str(self._ui.comPort.currentText()), int(self._ui.baudRate.currentText()), bootupDelay, commTimeOut) protocol_handler = ProtocolHandler(self._communicator, self._vehicle_event_dispatcher) version = protocol_handler.get_flight_software_version() if version != "": self.save_COM_port_selection() self._ui.status.setText("Connected to AeroQuad Flight Software v" + version) if version == '3.2' : self._protocol_handler = AQV32ProtocolHandler(self._communicator, self._vehicle_event_dispatcher) elif version == '4.0' : self._protocol_handler = AQV4ProtocolHandler(self._communicator, self._vehicle_event_dispatcher) else : logging.error("Flight software version " + version + " unsuported") self.disconnectBoard() self._ui.status.setText("Not connected to the AeroQuad") return False self._ui_event_dispatcher.dispatch_event(UIEventDispatcher.CONNECTION_STATE_CHANGED_EVENT, True) self._vehicle_event_dispatcher.dispatch_event(VehicleEventDispatcher.SOFTWARE_VERSION_EVENT, version) self._protocol_handler.request_board_configuration() self._ui_event_dispatcher.dispatch_event(UIEventDispatcher.PROTOCOL_HANDLER_EVENT,self._protocol_handler) self._ui_event_dispatcher.dispatch_event(UIEventDispatcher.DISPLAY_PANEL_EVENT,PanelsContextBuilder.VEHICLE_INFORMATION_PANEL_ID) return True else: self.disconnect_from_aeroquad() self._ui.status.setText("Not connected to the AeroQuad") # if self.manualConnect: QtGui.QMessageBox.information(self, "Connection Error", "Unable to connect to the AeroQuad. Verify the board is plugged in.\n\nIf it is, try increasing the Boot Up Delay.\nThis is found under File->Preferences->Boot Up Delay.") return False except SerialException: self._ui.buttonDisconnect.setEnabled(False) self._ui.buttonConnect.setEnabled(True) self._ui.comPort.setEnabled(True) self._ui.baudRate.setEnabled(True) self._ui.status.setText("Connection Failed") return False
def connect_to_aeroquad(self): self._ui.status.setText("Connecting...") self._ui.buttonDisconnect.setEnabled(True) self._ui.buttonConnect.setEnabled(False) self._ui.comPort.setEnabled(False) self._ui.baudRate.setEnabled(False) self._app.processEvents() bootupDelay = float(self._xml.find("./Settings/BootUpDelay").text) commTimeOut = float(self._xml.find("./Settings/CommTimeOut").text) try: self._communicator.connect(str(self._ui.comPort.currentText()), int(self._ui.baudRate.currentText()), bootupDelay, commTimeOut) protocol_handler = ProtocolHandler(self._communicator, self._vehicle_event_dispatcher) version = protocol_handler.get_flight_software_version() if version != "": self.save_COM_port_selection() self._ui.status.setText( "Connected to AeroQuad Flight Software v" + version) if version == '3.2': self._protocol_handler = AQV32ProtocolHandler( self._communicator, self._vehicle_event_dispatcher) elif version == '4.0': self._protocol_handler = AQV4ProtocolHandler( self._communicator, self._vehicle_event_dispatcher) else: logging.error("Flight software version " + version + " unsuported") self.disconnectBoard() self._ui.status.setText("Not connected to the AeroQuad") return False self._ui_event_dispatcher.dispatch_event( UIEventDispatcher.CONNECTION_STATE_CHANGED_EVENT, True) self._vehicle_event_dispatcher.dispatch_event( VehicleEventDispatcher.SOFTWARE_VERSION_EVENT, version) self._protocol_handler.request_board_configuration() self._ui_event_dispatcher.dispatch_event( UIEventDispatcher.PROTOCOL_HANDLER_EVENT, self._protocol_handler) self._ui_event_dispatcher.dispatch_event( UIEventDispatcher.DISPLAY_PANEL_EVENT, PanelsContextBuilder.VEHICLE_INFORMATION_PANEL_ID) return True else: self.disconnect_from_aeroquad() self._ui.status.setText("Not connected to the AeroQuad") # if self.manualConnect: QtGui.QMessageBox.information( self, "Connection Error", "Unable to connect to the AeroQuad. Verify the board is plugged in.\n\nIf it is, try increasing the Boot Up Delay.\nThis is found under File->Preferences->Boot Up Delay." ) return False except SerialException: self._ui.buttonDisconnect.setEnabled(False) self._ui.buttonConnect.setEnabled(True) self._ui.comPort.setEnabled(True) self._ui.baudRate.setEnabled(True) self._ui.status.setText("Connection Failed") return False
def __init__(self, communicator, vehicle_event_dispatcher): ProtocolHandler.__init__(self, communicator, vehicle_event_dispatcher) self._motor_command = ''