这段代码需要调用serial模块,通过while循环不断读取串口数据
转自:http://www.yelinsky.com/
import time import serial ser = serial.Serial( #下面这些参数根据情况修改 port='COM1', baudrate=9600, parity=serial.PARITY_ODD, stopbits=serial.STOPBITS_TWO, bytesize=serial.SEVENBITS ) data = '' while ser.inWaiting() > 0: data += ser.read(1) if data != '': print data