import serial
# 创建serial实例
serialport = serial.Serial()
serialport.port
= 'COM1'
serialport.baudrate
= 9600
serialport.parity
= 'N'
serialport.bytesize
= 8
serialport.stopbits
= 1
serialport.timeout
= 0.6
try:
serialport.open()
serialport.setDTR(True)
serialport.setRTS(True)
except Exception, ex:
print ex
# 发送数据
serialport.write(raw_data)
# 根据项目要求,可以开一个线程扫描接收数据