1import serial 2import re 3import io 4from pyocd.core.target import Target 5 6lines = [] 7 8def read_stdout(target): 9 print("Waiting for serial") 10 lines = [] 11 12 with serial.Serial('COM6', 115200, timeout=1,parity=serial.PARITY_NONE) as ser: 13 sio = io.TextIOWrapper(ser) 14 DONE = False 15 target.reset() 16 while not DONE: 17 line = sio.readline() 18 if len(line)==0: 19 raise Exception('Timeout error') 20 if re.match(r'Stats',line): 21 DONE=True 22 else: 23 #print(line) 24 lines.append(line) 25 26 27 return(lines) 28