importserial
#創(chuàng)建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)
exceptException,ex:
printex
#發(fā)送數(shù)據(jù)
serialport.write(raw_data)
#根據(jù)項目要求,可以開一個線程掃描接收數(shù)據(jù)