logger.py 文件源码

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

项目:muxrplot 作者: sirmo 项目源码 文件源码
def log(options):
    # configure the serial connections (the parameters differs on the device you are connecting to)
    ser = serial.Serial(
        port=options.device,
        baudrate=9600,
        parity=serial.PARITY_ODD,
        stopbits=serial.STOPBITS_TWO,
        bytesize=serial.SEVENBITS
    )

    prog = Progress()

    with open(options.outfile, 'w') as the_file:
        the_file.write('timestamp;value\n')
        while True:
            # \r\n is for device terminators set to CR LF
            ser.write((':FETCh?\r\n'))

            # wait one second before reading output.
            time.sleep(options.interval)
            out = ''
            while ser.inWaiting() > 0:
                out += ser.read(1)
            if out != '':
                out = out.rstrip()
                res = "%s;%s\n" % (time.time(), float(out))
                the_file.write(res)
                the_file.flush()
                prog.show()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号