Windows平台python操作串口示

2023-01-31 05:01:06 操作 平台 串口

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)


相关文章