Python Forum

Full Version: While loop doesn't exit
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
while indata != "%":  
  indata = ser.read()
  print (indata)
  Counter = Counter + 1 
  if Counter > 20:
   sys.exit("Timed out waiting for Bootloader Active Character. Please try again")
Why does this always timeout even though a % is received?
Python 3.8 under linux
likely the received '%' has framing of some sort.
try:
while indata.strip() != "%":
Thanks for the suggestion but it still times out

#wait for % and then move on
indata = ""
Counter = 0
while indata.strip() != "%":
  indata = ser.read()
  print (indata.decode())  
  Counter = Counter + 1 
  if Counter > 20:
   sys.exit("Timed out waiting for Bootloader Active Character. Please try again")
Does serRead return str or some other type like bytes or bytearray?