当前位置: 首页>>代码示例>>Python>>正文


Python serial.serialutil方法代码示例

本文整理汇总了Python中serial.serialutil方法的典型用法代码示例。如果您正苦于以下问题:Python serial.serialutil方法的具体用法?Python serial.serialutil怎么用?Python serial.serialutil使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在serial的用法示例。


在下文中一共展示了serial.serialutil方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: dump_cortex

# 需要导入模块: import serial [as 别名]
# 或者: from serial import serialutil [as 别名]
def dump_cortex(port, file, verbose=False):
    if not os.path.isfile(file):
        click.echo('Failed to download... file does not exist')
        return False
    port = prosflasher.ports.create_serial(port)
    if not port:
        click.echo('Failed to download: port not found')
        return
    try:
        reset_cortex(port)
        sys_info = ask_sys_info(port)
        if sys_info is None:
            click.echo('Failed to get system info... Try again', err=True)
            click.get_current_context().abort()
            sys.exit(1)
        click.echo(repr(sys_info))
        stop_user_code(port)
        if sys_info.connection_type == ConnectionType.serial_vexnet2:
            # need to send to download channel
            if not send_to_download_channel(port):
                return False
        if not expose_bootloader(port):
            return False
        if not prosflasher.bootloader.prepare_bootloader(port):
            return False
        if not prosflasher.bootloader.erase_flash(port):
            return False

        with open(file, 'wb') as f:
            address = 0x08000000
            data = prosflasher.bootloader.read_memory(port, address, 256)
            while len(data) > 0:
                f.write(data)
                address += 0x100

    except serial.serialutil.SerialException as e:
        click.echo('Failed to download code! ' + str(e))
    finally:
        port.close()
    click.echo("Download complete!")
    pass 
开发者ID:purduesigbots,项目名称:pros-cli2,代码行数:43,代码来源:upload.py

示例2: __init__

# 需要导入模块: import serial [as 别名]
# 或者: from serial import serialutil [as 别名]
def __init__(self, port, baudrate, skip_reader=False):
        import serial
        from serial.serialutil import SerialException

        super().__init__()

        try:
            self._serial = serial.Serial(port, baudrate=baudrate, timeout=None)
        except SerialException as error:
            err_str = str(error)
            if "FileNotFoundError" in err_str:
                err_str = "port not found"
            message = "Unable to connect to " + port + ": " + err_str

            # TODO: check if these error codes also apply to Linux and Mac
            if error.errno == 13 and platform.system() == "Linux":
                # TODO: check if user already has this group
                message += "\n\n" + dedent(
                    """\
                Try adding yourself to the 'dialout' group:
                > sudo usermod -a -G dialout <username>
                (NB! This needs to be followed by reboot or logging out and logging in again!)"""
                )

            elif "PermissionError" in message:
                message += "\n\n" + dedent(
                    """\
                If you have serial connection to the device from another program,
                then disconnect it there."""
                )

            elif error.errno == 16:
                message += "\n\n" + "Try restarting the device."

            raise ConnectionFailedException(message)

        if skip_reader:
            self._reading_thread = None
        else:
            self._reading_thread = threading.Thread(target=self._listen_serial, daemon=True)
            self._reading_thread.start() 
开发者ID:thonny,项目名称:thonny,代码行数:43,代码来源:serial_connection.py


注:本文中的serial.serialutil方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。