Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
While loop doesn't exit
#1
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
Reply
#2
likely the received '%' has framing of some sort.
try:
while indata.strip() != "%":
Reply
#3
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")
Reply
#4
Does serRead return str or some other type like bytes or bytearray?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python difference between sys.exit and exit() mg24 1 1,843 Nov-12-2022, 01:37 PM
Last Post: deanhystad
  For Loop Works Fine But Append For Pandas Doesn't Work knight2000 2 2,021 Dec-18-2021, 02:38 AM
Last Post: knight2000
  Exit Function - loop Tetsuo30 2 2,066 Sep-17-2020, 09:58 AM
Last Post: Tetsuo30
  Struggling to exit this while loop fatherted99 5 2,482 Feb-08-2020, 07:46 PM
Last Post: fatherted99
  While loop doesn't end when False Kanashi 2 2,569 Nov-21-2019, 02:38 AM
Last Post: Kanashi
  For loop in my __init__ doesn't work as expected Jessy 2 2,364 Nov-18-2019, 10:07 AM
Last Post: buran
  Why doesn't my loop work correctly? (problem with a break statement) steckinreinhart619 2 3,211 Jun-11-2019, 10:02 AM
Last Post: steckinreinhart619
  won't exit a loop, please help hobbyprogrammer 9 4,392 Oct-22-2018, 05:22 PM
Last Post: hobbyprogrammer
  Code doesn't loop after first RFID scan BadgerHack 5 4,291 May-01-2018, 11:07 AM
Last Post: BadgerHack
  Using break to exit a loop help JJG 4 4,196 Dec-09-2017, 03:02 AM
Last Post: JJG

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020