How to use serialio - 5 common examples

To help you get started, we’ve selected a few serialio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github q3k / m16c-interface / host / main.py View on Github external
fmt = '%(message)s'
    if args.timestamps:
        fmt = '%(asctime)-15s %(levelname)s %(message)s'
    if args.verbose:
        logging.basicConfig(level=logging.DEBUG, format=fmt)
    else:
        logging.basicConfig(level=logging.INFO, format=fmt)

    adapter_logger, protocol_logger = None, None
    if args.debug_adapter:
        adapter_logger = logging
    if args.debug_protocol:
        protocol_logger = logging

    a = adapter.Adapter(args.port, logger=adapter_logger)
    s = serialio.SerialIO(a, logger=protocol_logger)
    s.adapter.connect()
    logging.info("Connected to adapter version {}".format(s.adapter.version()))
    s.connect()
    logging.info("Connected to target version {}".format(s.version()))

    sys.exit(args.func(args, s) or 0)
github twpayne / flightrecorder / flightrecorder / ascent.py View on Github external
return block

    def read_track_logs(self, flight_number):
        self.io.write(struct.pack('>BBH', 3, 5, flight_number))
        try:
            while True:
                self.buf += self.io.read()
        except TimeoutError:
            pass
        return self.buf


if __name__ == '__main__':
    from serialio import SerialIO
    logging.basicConfig(level=logging.DEBUG)
    s = SerialIO('/dev/cu.usbmodem641')
    a = Ascent(s)
    if True:
        print repr(a.dev_drv_status_res())
    if True:
        for block in a.dev_drv_list_tracks():
            print repr(block)
github twpayne / flightrecorder / flightrecorder / flightrecorder.py View on Github external
def __new__(self, device=None, model=None):
        if device:
            devices = (device,)
        else:
            device_globs = DEVICE_GLOBS.get(os.uname()[0], ())
            devices = list(filename for device_glob in device_globs for filename in sorted(glob(device_glob)))
        if model is not None and model not in FlightRecorder.SUPPORTED_MODELS:
            raise RuntimeError  # FIXME
        for device in devices:
            try:
                io = SerialIO(device)
            except IOError:
                continue
            if model in Fifty20.SUPPORTED_MODELS:
                return Fifty20(io)
            elif model in Flymaster.SUPPORTED_MODELS:
                return Flymaster(io)
            elif model in Sixty15.SUPPORTED_MODELS:
                return Sixty15(io)
            elif model is None:
                try:
                    try:
                        line = 'PBRSNP,'.encode('nmea_sentence')
                        logger.info('write %r' % line)
                        io.write(line)
                        line = io.read(0.2)
                        while line.find('\x11' if line[0] == '\x13' else '\n') == -1:
github twpayne / flightrecorder / flightrecorder / ascent.py View on Github external
def read_track_logs(self, flight_number):
        self.io.write(struct.pack('>BBH', 3, 5, flight_number))
        try:
            while True:
                self.buf += self.io.read()
        except TimeoutError:
            pass
        return self.buf
github q3k / m16c-interface / host / main.py View on Github external
s.adapter.set_tclk(0)
    # Run target serial clock at 1.5MHz
    s.adapter.set_sclk(127)

    try:
        code = args.code.decode('hex')
    except TypeError:
        logging.fatal("Code must be in hexadecimal format.")
        return
    if len(code) != 7:
        logging.fatal("Code must be 7 bytes long.")
        return

    s.unlock(code)
    status = s.unlock_status()
    if status != serialio.UNLOCK_SUCCESSFUL:
        logging.fatal("Target did not unlock.")
        return
    logging.info("Target unlocked.")

    start = 0x0e00
    end = 0x0fff

    with open(args.output, 'w') as f:
        logging.info("Writing pages {:x}-{:x} to {}...".format(start, end,
                                                               args.output))
        for page in range(start, end+1):
            logging.debug("Dumping {:x}00-{:x}ff...".format(page, page))
            data = s.read_page(page)
            f.write(data)

serialio

Concurrency agnostic serialio API

GPL-3.0
Latest version published 4 years ago

Package Health Score

54 / 100
Full package analysis