Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading Serial data
#2
perhaps the pi leaves the serial line down for short periods of time?.

I might suggest just wrapping the block in try/except and retrying. If that works okay, probably best you can do.

try:
    if (ser.inWaiting()>0): 
        data_str = ser.read(ser.inWaiting())
        print(data_str)
except OSError:
    # ignore or log...  Let the loop retry.
    pass
        
Reply


Messages In This Thread
Reading Serial data - by Moris526 - Dec-15-2020, 09:45 PM
RE: Reading Serial data - by bowlofred - Dec-15-2020, 11:40 PM
RE: Reading Serial data - by Moris526 - Dec-16-2020, 12:12 AM
RE: Reading Serial data - by bowlofred - Dec-16-2020, 12:59 AM
RE: Reading Serial data - by Moris526 - Dec-17-2020, 02:47 AM
RE: Reading Serial data - by bowlofred - Dec-17-2020, 02:56 AM
RE: Reading Serial data - by Moris526 - Dec-26-2020, 04:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pyserial/serial "has no attribute 'Serial' " gowb0w 9 4,168 Aug-24-2023, 07:56 AM
Last Post: gowb0w
Star Pyserial not reading serial.readline fast enough while using AccelStepper on Arduino MartyTinker 4 4,115 Mar-13-2023, 04:02 PM
Last Post: deanhystad
  Reading All The RAW Data Inside a PDF NBAComputerMan 4 1,361 Nov-30-2022, 10:54 PM
Last Post: Larz60+
  Reading Data from JSON tpolim008 2 1,100 Sep-27-2022, 06:34 PM
Last Post: Larz60+
  Help reading data from serial RS485 korenron 8 14,048 Nov-14-2021, 06:49 AM
Last Post: korenron
  Help with WebSocket reading data from anoter function korenron 0 1,345 Sep-19-2021, 11:08 AM
Last Post: korenron
  Fastest Way of Writing/Reading Data JamesA 1 2,207 Jul-27-2021, 03:52 PM
Last Post: Larz60+
  Reading data to python: turn into list or dataframe hhchenfx 2 5,401 Jun-01-2021, 10:28 AM
Last Post: Larz60+
  Reading data from mysql. stsxbel 2 2,228 May-23-2021, 06:56 PM
Last Post: stsxbel
  reading canbus data as hex korenron 9 6,303 Dec-30-2020, 01:52 PM
Last Post: korenron

Forum Jump:

User Panel Messages

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