在windows中,使用python进行串口编程需要安装一个Serial模块 pyserial:
下载地址:https://pypi.python.org/pypi/pyserial 下载完成后得到一个xxx.whl文件,下面进行安装
pip install pyserial-3.1.1-py2.py3-none-any.whl
详细的使用信息可以阅读pySerial的文档http://pythonhosted.org/pyserial/
\#!/usr/bin/env python
\# -*- coding: utf-8 -*
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 port was really used >",serialFd.name