Windows平台python操作串口示

发布时间:2019-09-05 07:07:48编辑:auto阅读(1856)

    windows中,使用Python进行串口编程需要安装一个Serial模块pyserial

    下载地址:https://pypi.python.org/pypi/pyserial下载完成后得到一个pyserial-3.2.1-py2.py3-none-any.whl文件,下面进行安装


    编程测试程序

    import serial
    import serial.tools.list_ports
    
    plist = list(serial.tools.list_ports.comports())
    if len(plist) <= 0:
        print("the serial port can't find")
    else:
        plist_0 = list(plist[0])
        serialName = plist_0[0]
        serialFd = serial.Serial(serialName, 9600, timeout=60)
        print("check which[%s] port was really used>" % serialFd.name)
    while True:
        data = serialFd.read()
        print(data)
    


关键字