Skip to content Skip to sidebar Skip to footer

Pyserial When It Is The End Of The Line Stop The While Loop

import serial arduino = serial.Serial('COM12', 9600, timeout = .1) arduino_data = [] # declare a list while True: data = arduino.readline() if data: arduino_data.

Solution 1:

Wait for it to timeout without any data, then you know it is done.

For example:

import serial

arduino = serial.Serial('COM12', 9600, timeout = .1)
while True:
    data = arduino.readline()
    ifdata:
        arduino_data.append(data) # Append a data to your declared list
        print(arduino_data)
    else:
        break

Post a Comment for "Pyserial When It Is The End Of The Line Stop The While Loop"