壹個Python實現的串口Echo
import serial
import sys
try:
?ser = serial.Serial('/dev/ttyUSB0', 9600)
except Exception, e:
?print 'open serial failed.'
?exit(1)
print 'A Serial Echo Is Running...'
while True:
?# echo
?s = ser.read()
?ser.write(s)
?# write to stdout and flush it
?sys.stdout.write(s)
?sys.stdout.flush()