Ejemplo n.º 1
0
    def _check_connection(self, port):
        proxy = get_runner().get_backend_proxy()
        if isinstance(proxy, BareMetalMicroPythonProxy):
            # Most likely it is using the same port
            proxy.disconnect()
            time.sleep(1.5)

        # Maybe another program is connected
        # or the user doesn't have sufficient permissions?
        try:
            conn = SerialConnection(port, 115200, skip_reader=True)
            conn.close()

            return True
        except Exception as e:
            messagebox.showerror("Can't connect", str(e), master=self)
            return False
Ejemplo n.º 2
0
    try:
        if args["port"] is None:
            # remain busy
            while True:
                time.sleep(1000)
        elif args["port"] == "webrepl":

            connection = WebReplConnection(args["url"], args["password"])
        else:
            from thonny.plugins.micropython.serial_connection import (
                DifficultSerialConnection,
                SerialConnection,
            )

            connection = SerialConnection(args["port"], BAUDRATE)
            # connection = DifficultSerialConnection(args["port"], BAUDRATE)

        if "circuitpython" in args.get("proxy_class", "").lower():
            from thonny.plugins.circuitpython.cp_backend import CircuitPythonBackend

            backend = CircuitPythonBackend(connection,
                                           clean=args["clean"],
                                           args=args)
        else:
            backend = BareMetalMicroPythonBackend(connection,
                                                  clean=args["clean"],
                                                  args=args)

    except ConnectionFailedException as e:
        text = "\n" + str(e) + "\n"
Ejemplo n.º 3
0
    try:
        if args["port"] is None:
            # remain busy
            while True:
                time.sleep(1000)
        elif args["port"] == "webrepl":
            connection = WebReplConnection(args["url"], args["password"])
        else:
            from thonny.plugins.micropython.serial_connection import (
                DifficultSerialConnection,
                SerialConnection,
            )

            connection = SerialConnection(
                args["port"], BAUDRATE, dtr=args.get("dtr"), rts=args.get("rts")
            )
            # connection = DifficultSerialConnection(args["port"], BAUDRATE)

        if "circuitpython" in args.get("proxy_class", "").lower():
            from thonny.plugins.circuitpython.cp_backend import CircuitPythonBackend

            backend = CircuitPythonBackend(connection, clean=args["clean"], args=args)
        else:
            backend = BareMetalMicroPythonBackend(connection, clean=args["clean"], args=args)

    except ConnectionFailedException as e:
        text = "\n" + str(e) + "\n"
        msg = BackendEvent(event_type="ProgramOutput", stream_name="stderr", data=text)
        sys.stdout.write(serialize_message(msg) + "\n")
        sys.stdout.flush()
Ejemplo n.º 4
0
    parser.add_argument("--password", type=str)
    parser.add_argument("--api_stubs_path", type=str)
    args = parser.parse_args()

    port = None if args.port == "None" else args.port
    try:
        if port is None:
            # remain busy
            while True:
                time.sleep(1000)
        elif port == "webrepl":
            from thonny.plugins.micropython.webrepl_connection import WebReplConnection

            connection = WebReplConnection(args.url, args.password)
        else:
            from thonny.plugins.micropython.serial_connection import SerialConnection

            connection = SerialConnection(port, BAUDRATE)

        vm = MicroPythonBackend(connection,
                                clean=args.clean,
                                api_stubs_path=args.api_stubs_path)

    except ConnectionFailedException as e:
        text = "\n" + str(e) + "\n"
        msg = BackendEvent(event_type="ProgramOutput",
                           stream_name="stderr",
                           data=text)
        sys.stdout.write(serialize_message(msg) + "\n")
        sys.stdout.flush()