getserial.py 665 B

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