pyboard.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:rshell 作者: dhylands 项目源码 文件源码
def __init__(self, device, baudrate=115200, user='micro', password='python', wait=0):
        if device and device[0].isdigit() and device[-1].isdigit() and device.count('.') == 3:
            # device looks like an IP address
            self.serial = TelnetToSerial(device, user, password, read_timeout=10)
        else:
            import serial
            delayed = False
            for attempt in range(wait + 1):
                try:
                    if serial.VERSION == '3.0':
                        self.serial = serial.Serial(device, baudrate=baudrate, inter_byte_timeout=1)
                    else:
                        self.serial = serial.Serial(device, baudrate=baudrate, interCharTimeout=1)
                    break
                except (OSError, IOError): # Py2 and Py3 have different errors
                    if wait == 0:
                        continue
                    if attempt == 0:
                        sys.stdout.write('Waiting {} seconds for pyboard '.format(wait))
                        delayed = True
                time.sleep(1)
                sys.stdout.write('.')
                sys.stdout.flush()
            else:
                if delayed:
                    print('')
                raise PyboardError('failed to access ' + device)
            if delayed:
                print('')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号