示例#1
0
    def enter_raw_repl(self):
        """
        Enter the RAW repl mode. After the prompt character ('>') left in the buffer of the serial line.

        Returns:
        None
        """
        self.serial.write(
            b"\x03\x03")  # ctrl-C twice: interrupt any running program

        # flush input (without relying on serial.flushInput())
        n = self.serial.inWaiting()
        while n > 0:
            self.serial.read(n)
            n = self.serial.inWaiting()

        self.serial.write(b"\x01")  # ctrl-A: enter raw REPL
        data = self.read_until(1, b"raw REPL; CTRL-B to exit\r\n>")
        if not data.endswith(b"raw REPL; CTRL-B to exit\r\n>"):
            raise PyboardError("could not enter raw repl")

        self.serial.write(b"\r\x04")  # execute nothing
        data = self.serial.read(2)
        if data != b"OK":
            raise PyboardError("could not enter raw repl")
示例#2
0
    def exec_raw_no_follow(self, command):
        """
        Execute a the command 'command' on the card10.

        Parameters:
        command (bytes): Command or multiple commands

        Returns:
        None
        """

        if isinstance(command, bytes):
            command_bytes = command
        else:
            command_bytes = bytes(command, encoding="utf8")

        data = self.read_until(1, b">")
        if not data.endswith(b">"):
            raise PyboardError("card10 not in raw repl mode: (response: %r)" %
                               (data))

        # write command
        for i in range(0, len(command_bytes), 256):
            self.serial.write(command_bytes[i:min(i +
                                                  256, len(command_bytes))])
            time.sleep(0.01)

        self.serial.write(b"\x04")

        # check if we could exec command
        data = self.serial.read(2)
        if data != b"OK":
            raise PyboardError("could not exec command (response: %r)" % data)
示例#3
0
def soft_reset(args):
    pyb = get_pyb(args)
    print("trying to soft reboot badge")
    write_command(pyb, b'\x04')  # ctrl-D: soft reset
    #print("1")
    data = pyb.read_until(1, b'soft reboot\r\n')
    #print("2")
    if data.endswith(b'soft reboot\r\n'):
        print("Soft reboot was successful.")
    else:
        raise PyboardError('could not soft reboot')
示例#4
0
def soft_reset(args, verbose = True):
    pyb = get_pyb(args)
    if verbose:
        print("Soft reboot:", end="", flush=True)
    write_command(pyb, b'\x04') # ctrl-D: soft reset
    data = pyb.read_until(1, b'soft reboot\r\n')
    if data.endswith(b'soft reboot\r\n'):
        if verbose:
            print(" DONE")
    else:
        if verbose:
            print(" FAIL")
        raise PyboardError('could not soft reboot')