当前位置:首页 > Python教程 > python技巧

python3 读取串口数据

python3 读取串口数据 demo

        import serial
import time


ser = serial.Serial("COM3",115200,timeout = 5)
ser.flushInput()

def main():
    while True:
        count = ser.inWaiting()
        if count !=0 :
            recv = ser.read(ser.in_waiting).decode("gbk")
            print(time.time()," ---  recv --> ", recv)
        time.sleep(0.1)



if __name__ == '__main__':
    main()

    

原文:https://www.cnblogs.com/wjw1014/p/12101825.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!