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(): """ 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')
def main(port, hexFile): bl = Bootloader(port) print('Using port', bl.port.name) bl.set_break(True) input('Reset PIC if not in bootloader mode, then press Enter...') bl.set_break(False) print('Connecting...') bl.connect() print('Found device ' + bl.dev_info[2] + ', bootloader v.' + str(bl.bl_info['version_major']) + '.' + str(bl.bl_info['version_minor'])) if hexFile is None: print('No hex file given, exiting.') return 0 bl.load_hex_file(hexFile) print('Writing...') bl.write() print('Verifying...') bl.verify() print('Running...') bl.run() print('Launching serial terminal...') # run serial.tools.miniterm (some code copied from miniterm's main function) bl.port.baudrate = 19200 # reuse our port without closing and reopening it # define our own filter to display non-printable chars as '<nn>' hexadecimal class MyFilter(serial.tools.miniterm.Transform): def rx(self, text): r = '' for c in text: if ' ' <= c < '\x7f' or c in '\r\n\b\t': r += c else: r += '<' + '{:02x}'.format(ord(c)) + '>' return r echo = rx # add it to miniterm's table serial.tools.miniterm.TRANSFORMATIONS['my_filter'] = MyFilter miniterm = serial.tools.miniterm.Miniterm(bl.port, filters=('my_filter', ), eol='lf') miniterm.exit_character = serial.tools.miniterm.unichr(0x03) # CTRL-C miniterm.menu_character = serial.tools.miniterm.unichr(0x14) # CTRL-T miniterm.set_rx_encoding('ascii') miniterm.set_tx_encoding('ascii') sys.stderr.write( '--- Miniterm 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( serial.tools.miniterm.key_description(miniterm.exit_character), serial.tools.miniterm.key_description(miniterm.menu_character), serial.tools.miniterm.key_description(miniterm.menu_character), serial.tools.miniterm.key_description('\x08'))) miniterm.start() try: miniterm.join(True) except KeyboardInterrupt: pass sys.stderr.write("\n--- exit ---\n") miniterm.join() miniterm.close()
"COM4", 115200, do_not_open = True) 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.open() miniterm = ESPMiniterm( serial_instance, echo=False, eol='crlf', filters=["espstackdecoder"]) miniterm.exit_character = chr(0x03) #unichr(0x1d) miniterm.menu_character = chr(0x14) miniterm.raw = False miniterm.set_rx_encoding('UTF-8') miniterm.set_tx_encoding('UTF-8') miniterm.start() try: miniterm.join(True) except KeyboardInterrupt: pass sys.stderr.write("\n--- exit ---\n") miniterm.join() miniterm.close()