What is the equivalent of Serial.available() in pyserial?
Question: When I am trying to read multiple lines of serial data on an Arduino, I use
the following idiom:

    
    
    String message = "";
    while (Serial.available()){
        message = message + serial.read()
    }
    

In Arduino C, `Serial.available()` returns the number of bytes available to be
read from the serial buffer (See
[Docs](https://www.arduino.cc/en/Serial/Available)). _What is the equivalent
of`Serial.available()` in python?_

For example, if I need to read multiple lines of serial data I would expect to
ues the following code:

    
    
    import serial
    ser = serial.Serial('/dev/ttyACM0', 9600, timeout=0.050)
    ...
    while ser.available():
        print ser.readline()
    


Answer: The property
[`Serial.in_waiting`](https://pythonhosted.org/pyserial/pyserial_api.html#serial.Serial.in_waiting)
returns the "the number of bytes in the receive buffer".

This seems to be the equivalent of
[`Serial.available()`](https://www.arduino.cc/en/Serial/Available)'s
description: "the number of bytes ... that's already arrived and stored in the
serial receive buffer."

For versions prior to pyserial 3.0, use `.inWaiting()`.

Try:

    
    
    import serial
    ser = serial.Serial('/dev/ttyACM0', 9600, timeout=0.050)
    ...
    while ser.in_waiting:  # Or: while ser.inWaiting():
        print ser.readline()
    

