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). 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()
所有评论(0)