Bird
0
0

You want to log GPS data continuously on Raspberry Pi and handle connection loss gracefully. Which code structure best achieves this?

hard🚀 Application Q9 of 15
Raspberry Pi - Serial UART Communication
You want to log GPS data continuously on Raspberry Pi and handle connection loss gracefully. Which code structure best achieves this?
AUse a try-except loop around serial reading with reconnect logic on failure
BOpen serial port once and read without error handling
CRead GPS data once and exit program
DUse a blocking read without timeout and no exception handling
Step-by-Step Solution
Solution:
  1. Step 1: Understand continuous reading needs

    Continuous GPS logging requires a loop that reads data repeatedly.
  2. Step 2: Handle connection loss

    Try-except with reconnect logic ensures program recovers from serial port errors.
  3. Final Answer:

    Use a try-except loop around serial reading with reconnect logic on failure -> Option A
  4. Quick Check:

    Robust GPS logging = try-except with reconnect [OK]
Quick Trick: Wrap serial reads in try-except to handle disconnects [OK]
Common Mistakes:
MISTAKES
  • Ignoring exceptions causing crashes
  • Reading once then exiting
  • Using blocking reads without timeout

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes