def __init__(self, serial_instance): import sys #Miniterm.__init__(self, serial_instance, filters=['debug']) orig_output = sys.stdout print("orig_output", orig_output) Miniterm.__init__(self, serial_instance) self.console.output = ConsoleOut(orig_output)
def connect_miniterm(port): try: return 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") elif e.errno == 13: print("Found micro:bit, but could not connect.".format(port), file=sys.stderr) print(e, file=sys.stderr) print('On linux, try adding yourself to the "dialout" group', file=sys.stderr) print('sudo usermod -a -G dialout <your-username>', file=sys.stderr) 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)
def connect_miniterm(port): try: ser = Serial(port, BAUDRATE, parity=PARITY, rtscts=False, xonxoff=False) return Miniterm(ser, echo=False) except SerialException as e: if e.errno == errno.ENOENT: sys.stderr.write("Device %r not found. Check your " "MicroPython device path settings.\n" % port) elif e.errno == errno.EBUSY: # Device is busy. Explain what to do. sys.stderr.write("Found the device, but it 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") elif e.errno == errno.EACCES: sys.stderr.write( "Found the device, but could not connect.\n".format(port)) sys.stderr.write('%s\n' % (str(e), )) sys.stderr.write( 'On linux, try adding yourself to the "dialout" group:\n') sys.stderr.write('sudo usermod -a -G dialout <your-username>\n') else: # Try to be as helpful as possible. sys.stderr.write("Found the device, but could not connect via" + " port %r: %s\n" % (port, e)) sys.stderr.write("I'm not sure what to suggest. :-(\n") input("Press ENTER to continue") sys.exit(1)
def ttymode(self, dev=None): if dev is None: dev = self.dev tout = dev.timeout self.tty_enable = True dev.timeout = None term = Miniterm(dev, eol='cr') term.exit_character = chr(0x1d) # GS/CTRL+] term.menu_character = chr(0x14) # Menu: CTRL+T term.raw = True term.set_rx_encoding('UTF-8') term.set_tx_encoding('UTF-8') print('--- TTY mode | Quit: CTRL+] | Menu: CTRL+T ---') term.start() try: term.join(True) except KeyboardInterrupt: pass print('--- Exit TTY mode ---') term.join() term.close() dev.timeout = tout self.tty_enable = False
from serial.tools.miniterm import Miniterm from umano import settings from umano.adam.models import emg_sensors_serial, OSCConsole if __name__ == "__main__": ser = emg_sensors_serial() ser.open() terminal = Miniterm(ser) terminal.console = OSCConsole(host=settings.ADAM_OSC_RECEIVER_HOST, port=settings.ADAM_OSC_RECEIVER_PORT, address=settings.ADAM_OSC_PRESSURE_ADDRESS) terminal.set_rx_encoding(settings.ADAM_SERIAL_ENCODING) terminal.start()
def main (args): port = serial.Serial (args.port, 57600, timeout = args.timeout) print ('Press device reset button...') sys.stdout.flush () reset (port) timeout = time.time () + args.timeout while True: if port.readline ().strip ().endswith ('READY'): break if time.time () >= timeout: raise IOError ('Sync timeout') port.write ('config\r\n') timeout = time.time () + args.timeout while True: l = port.readline () if l.startswith ('MultiOSD'): print ('Connected. Type "help" for commands list. Press Ctrl+D to exit.') print () print (l.strip ()) break if time.time () >= timeout: raise IOError ('Sync timeout') sys.stdout.flush () term = Miniterm (port, echo = False, eol = 'crlf', filters = ['default'], ) term.exit_character = chr (0x04) term.menu_character = chr (0x14) term.raw = True term.set_rx_encoding ('Latin1') term.set_tx_encoding ('Latin1') term.start () try: term.join (True) except KeyboardInterrupt: pass term.join () print () port.write ('exit\r\n')
import serial from serial.tools.miniterm import Miniterm from settings import Settings ser = serial.serial_for_url(Settings.LOPY_SERIAL, 115200) xterm = Miniterm(ser, echo=False) xterm.join()
def upload(self, firmware, console=True, reset=True): import argparse parser = argparse.ArgumentParser() parser.add_argument("-l", "--list", action="store_true") parser.add_argument("-v", "--verbose", action="store_true") args = parser.parse_args() if args.list: log.info("Listing information") print(firmware.fw.reg.show()) print(firmware.fw.code()) print(firmware.hex_blob) else: if reset: log.info("Reset device") self.ser.open() # warmboot self.toggle(4) self.hex_blob = firmware.hex_blob # self.ser.readall() # clear out the buffer # self.ser.write(4) # wait for the pll to settle time.sleep(0.2) counter = 0 log.info("Upload Firmware") for i in grouper(self.hex_blob, 4): data = "".join(i).encode() # print(data) # counter += 1 # if counter % 4 == 0: # print('.',end="") self.ser.write(data) # a = self.ser.readall() # print(a) if console: log.info("Create Terminal") term = Miniterm(self.ser) term.set_rx_encoding("utf-8") term.set_tx_encoding("utf-8") term.exit_character = "\x1d" log.info("Attach Terminal") term.start() term.join(True)
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()
import serial from serial.tools.miniterm import Miniterm, unichr import colorama colorama.init(True) serial_instance = serial.serial_for_url('/dev/ttyUSB0', 115200, do_not_open=True) miniterm = Miniterm(serial_instance, filters=['colorize']) miniterm.exit_character = unichr(29) miniterm.menu_character = unichr(20) miniterm.start() try: miniterm.join(True) except KeyboardInterrupt: pass