Bird
0
0

Which of the following is the correct way to open a serial port using pyserial in Python?

easy📝 Syntax Q12 of 15
Raspberry Pi - Serial UART Communication
Which of the following is the correct way to open a serial port using pyserial in Python?
Aserial.Open(port='/dev/ttyUSB0', speed=9600)
Bserial.connect('/dev/ttyUSB0', 9600)
Cserial.Serial(port='/dev/ttyUSB0', baudrate=9600, timeout=1)
Dserial.start(port='/dev/ttyUSB0', baud=9600)
Step-by-Step Solution
Solution:
  1. Step 1: Recall pyserial syntax for opening ports

    The correct method is to create a Serial object with parameters: port, baudrate, and optionally timeout.
  2. Step 2: Check each option's method and parameters

    Only serial.Serial(port='/dev/ttyUSB0', baudrate=9600, timeout=1) uses serial.Serial() with correct parameter names and values.
  3. Final Answer:

    serial.Serial(port='/dev/ttyUSB0', baudrate=9600, timeout=1) -> Option C
  4. Quick Check:

    Use serial.Serial() with port and baudrate [OK]
Quick Trick: Use serial.Serial() with port and baudrate [OK]
Common Mistakes:
MISTAKES
  • Using incorrect method names like Open or connect
  • Using wrong parameter names like speed or baud
  • Omitting required parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes