(self, reset=True, delay_after_reset_s=1)
Connect to the USB adapter, reset its state and start a background
        receiver thread.

        reset - Reset the device if True.
        delay_after_reset_s - If reset is true, delay this number of seconds
            before attempting to open the device after a reset.
Connect to the USB adapter, reset its state and start a background
        receiver thread.
Connect to the USB adapter reset its state and start a background receiver thread .
def start(self, reset=True, delay_after_reset_s=1):
        """
        Connect to the USB adapter, reset its state and start a background
        receiver thread.

        reset - Reset the device if True.
        delay_after_reset_s - If reset is true, delay this number of seconds
            before attempting to open the device after a reset.
        """
        if self._running and self._running.is_set():
            self.stop()

        # Fail immediately if no device is attached
        self._detect_device_port()

        # Blow everything away and start anew.
        # Only way to be sure is to burn it down and start again.
        # (Aka reset remote state machine)

        # The zero param just means we want to do a normal restart instead of
        # starting a firmware update restart.
        if reset:
            log.info(
                "Resetting and reconnecting to device for a clean environment")
            self._open_serial_port()
            self.send_command(CommandBuilder.system_reset(0))
            self._ser.close()

            # The USB device does not re-appear instantly
            time.sleep(delay_after_reset_s)

        self._open_serial_port()
        self._receiver = threading.Thread(target=self._receive)
        self._receiver.daemon = True

        self._running = threading.Event()
        self._running.set()
        self._receiver.start()

        self.disable_advertising()
        self.set_bondable(False)

        # Stop any ongoing procedure
        log.debug("Stopping any outstanding GAP procedure")
        self.send_command(CommandBuilder.gap_end_procedure())
        try:
            self.expect(ResponsePacketType.gap_end_procedure)
        except BGAPIError:
            # Ignore any errors if there was no GAP procedure running
            pass
def start ( self , reset = True , delay_after_reset_s = 1 ) : if self . _running and self . _running . is_set ( ) : self . stop ( ) # Fail immediately if no device is attached self . _detect_device_port ( ) # Blow everything away and start anew. # Only way to be sure is to burn it down and start again. # (Aka reset remote state machine) # The zero param just means we want to do a normal restart instead of # starting a firmware update restart. if reset : log . info ( "Resetting and reconnecting to device for a clean environment" ) self . _open_serial_port ( ) self . send_command ( CommandBuilder . system_reset ( 0 ) ) self . _ser . close ( ) # The USB device does not re-appear instantly time . sleep ( delay_after_reset_s ) self . _open_serial_port ( ) self . _receiver = threading . Thread ( target = self . _receive ) self . _receiver . daemon = True self . _running = threading . Event ( ) self . _running . set ( ) self . _receiver . start ( ) self . disable_advertising ( ) self . set_bondable ( False ) # Stop any ongoing procedure log . debug ( "Stopping any outstanding GAP procedure" ) self . send_command ( CommandBuilder . gap_end_procedure ( ) ) try : self . expect ( ResponsePacketType . gap_end_procedure ) except BGAPIError : # Ignore any errors if there was no GAP procedure running pass