def term(serial_instance): encoding = 'Latin1' if not hasattr(serial_instance, 'cancel_read'): # enable timeout for alive flag polling if cancel_read is not available serial_instance.timeout = 1 serial_instance.write_timeout = None serial_instance.baudrate = 115200 miniterm = Miniterm(serial_instance, echo=False, eol='lf') miniterm.raw = True miniterm.set_rx_encoding(encoding) miniterm.set_tx_encoding(encoding) print( '--- Miniterm on {p.name} {p.baudrate},{p.bytesize},{p.parity},{p.stopbits} ---\n' .format(p=miniterm.serial)) print('--- Quit: {} | Menu: {} | Help: {} followed by {} ---\n'.format( key_description(miniterm.exit_character), key_description(miniterm.menu_character), key_description(miniterm.menu_character), key_description('\x08'))) miniterm.start() try: miniterm.join(True) except KeyboardInterrupt: pass print('\n--- exit ---\n') miniterm.join() miniterm.close()
def main(serial_instance): if not hasattr(serial_instance, 'cancel_read'): # enable timeout for alive flag polling if cancel_read is not available serial_instance.timeout = 1 miniterm = Miniterm( serial_instance, echo=False, filters=['direct']) miniterm.set_rx_encoding('utf-8') miniterm.set_tx_encoding('utf-8') sys.stderr.write('--- Patched Miniterm-MPY on {p.name} {p.baudrate},{p.bytesize},{p.parity},{p.stopbits} ---\n'.format( p=miniterm.serial)) sys.stderr.write('--- Quit: {} | Menu: {} | Help: {} followed by {} ---\n'.format( key_description(miniterm.exit_character), key_description(miniterm.menu_character), key_description(miniterm.menu_character), key_description('\x08'))) miniterm.start() try: miniterm.join(True) except KeyboardInterrupt: pass sys.stderr.write("\n--- exit ---\n") miniterm.join() miniterm.close()
def main(): """ The function that actually runs the REPL. """ port = find_microbit() print('port', port) if not port: sys.stderr.write('Could not find micro:bit. Is it plugged in?\n') sys.exit(0) serial.tools.miniterm.EXITCHARCTER = character(b'\x1d') miniterm = connect_miniterm(port) # Emit some helpful information about the program and MicroPython. shortcut_message = 'Quit: {} | Stop program: Ctrl+C | Reset: Ctrl+D\n' help_message = 'Type \'help()\' (without the quotes) then press ENTER.\n' exit_char = key_description(serial.tools.miniterm.EXITCHARCTER) sys.stderr.write(shortcut_message.format(exit_char)) sys.stderr.write(help_message) # Start everything. console.setup() miniterm.start() miniterm.serial.write(b'\x03') # Connecting stops the running program. try: miniterm.join(True) except KeyboardInterrupt: pass sys.stderr.write('\nEXIT - see you soon... :-)\n')
def main(): """ The function that actually runs the REPL. """ port = find_microbit() print('port', port) if not port: sys.stderr.write('Could not find micro:bit. Is it plugged in?\n') sys.exit(0) serial.tools.miniterm.EXITCHARCTER = character(b'\x1d') miniterm = connect_miniterm(port) # Emit some helpful information about the program and MicroPython. shortcut_message = 'Quit: {} | Stop program: Ctrl+C | Reset: Ctrl+D\n' help_message = 'Type \'help()\' (without the quotes) then press ENTER.\n' exit_char = key_description(serial.tools.miniterm.EXITCHARCTER) sys.stderr.write(shortcut_message.format(exit_char)) sys.stderr.write(help_message) # Start everything. console.setup() miniterm.set_rx_encoding('utf-8') miniterm.set_tx_encoding('utf-8') miniterm.start() miniterm.serial.write(b'\x03') # Connecting stops the running program. try: miniterm.join(True) except KeyboardInterrupt: pass sys.stderr.write('\nEXIT - see you soon... :-)\n')
def main(): """ The function that actually runs the REPL. """ if len(sys.argv) != 2: print("Usage: microrepl.py /path/to/device") port = sys.argv[1] print('Device path', port) serial.tools.miniterm.EXITCHARCTER = character(b'\x1d') miniterm = connect_miniterm(port) # Emit some helpful information about the program and MicroPython. shortcut_message = 'Quit: {} | Stop program: Ctrl+C | Reset: Ctrl+D\n' help_message = 'Type \'help()\' (without the quotes) then press ENTER.\n' exit_char = key_description(serial.tools.miniterm.EXITCHARCTER) sys.stderr.write(shortcut_message.format(exit_char)) sys.stderr.write(help_message) # Start everything. miniterm.set_rx_encoding('utf-8') miniterm.set_tx_encoding('utf-8') miniterm.start() sleep(0.5) miniterm.serial.write(b'\x03') # Connecting stops the running program. try: miniterm.join(True) except KeyboardInterrupt: pass sys.stderr.write('\nEXIT - see you soon... :-)\n')
def main(argv): import argparse parser = argparse.ArgumentParser(description="Piterm - A simple terminal program for the serial port.") parser.add_argument("port", help="serial port name") parser.add_argument("file", nargs="?", help="hex file to upload, default: %(default)s", default="bin/kernel7.hex") args = parser.parse_args(argv) try: # Create the serial instance, it automatically opens the port serial_instance = serial.Serial(args.port, 115200, 8, serial.PARITY_NONE, serial.STOPBITS_ONE) except serial.SerialException as e: sys.stderr.write('could not open port {}: {}\n'.format(repr(args.port), e)) sys.exit(1) # All these fields have to be set before Miniterm will work miniterm = MyMiniterm(serial_instance) miniterm.exit_character = chr(0x1d) miniterm.menu_character = chr(0x14) miniterm.raw = False miniterm.set_rx_encoding('UTF-8') miniterm.set_tx_encoding('UTF-8') # This is something we added to customize it miniterm.set_upload_file(args.file) # Print out helpful info to the user sys.stderr.write('--- Piterm on {p.name} {p.baudrate},{p.bytesize},{p.parity},{p.stopbits} ---\n'.format( p=miniterm.serial)) sys.stderr.write('--- Quit: {} | Menu: {} | Help: {} followed by {} ---\n'.format( key_description(miniterm.exit_character), key_description(miniterm.menu_character), key_description(miniterm.menu_character), key_description('\x08'))) sys.stderr.write('--- Upload file: Ctrl+T followed by Ctrl+S ---\n') # Actually start miniterm miniterm.start() try: miniterm.join(True) except KeyboardInterrupt: pass
def main(): """ The function that actually runs the REPL. """ port = find_microbit() if not port: sys.stderr.write('Could not find micro:bit. Is it plugged in?\n') sys.exit(0) serial.tools.miniterm.EXITCHARCTER = character(b'\x1d') try: miniterm = Miniterm( port, BAUDRATE, PARITY, rtscts=False, xonxoff=False, echo=False, convert_outgoing=2, repr_mode=0, ) except serial.SerialException as e: if e.errno == 16: # Device is busy. Explain what to do. sys.stderr.write("Found micro:bit, but the device is busy. " + "Wait up to 20 seconds, or " + "press the reset button on the " + "back of the device next to the yellow light; " + "then try again.\n") else: # Try to be as helpful as possible. sys.stderr.write("Found micro:bit, but could not connect via" + " port %r: %s\n" % (port, e)) sys.stderr.write("I'm not sure what to suggest. :-(\n") sys.exit(1) # Emit some helpful information about the program and MicroPython. shortcut_message = 'Quit: {} | Stop program: Ctrl+C | Reset: Ctrl+D\n' help_message = 'Type \'help()\' (without the quotes) then press ENTER.\n' exit_char = key_description(serial.tools.miniterm.EXITCHARCTER) sys.stderr.write(shortcut_message.format(exit_char)) sys.stderr.write(help_message) # Start everything. console.setup() miniterm.start() miniterm.serial.write(b'\x03') # Connecting stops the running program. try: miniterm.join(True) except KeyboardInterrupt: pass sys.stderr.write('\nEXIT - see you soon... :-)\n')
serial_instance.open() minit = miniterm.Miniterm(serial_instance, echo=False, eol="crlf", filters=[]) minit.exit_character = chr(0x1D) minit.menu_character = chr(0x14) minit.raw = True minit.set_rx_encoding("UTF-8") minit.set_tx_encoding("UTF-8") sys.stderr.write( "--- minit on {p.name} {p.baudrate},{p.bytesize},{p.parity},{p.stopbits} ---\n".format( p=minit.serial ) ) sys.stderr.write( "--- Quit: {} | Menu: {} | Help: {} followed by {} ---\n".format( miniterm.key_description(minit.exit_character), miniterm.key_description(minit.menu_character), miniterm.key_description(minit.menu_character), miniterm.key_description("\x08"), ) ) minit.start() try: minit.join(True) except KeyboardInterrupt: pass sys.stderr.write("\n--- exit ---\n") minit.join() minit.close()