def cmd(cmd, serial):
    out = ''
prev = '101001011'
serial.flushInput()
serial.flushOutput()
serial.write(cmd + '\r')
while True:
    out += str(serial.read(1))
if prev == out:
    return out
prev = out
return out
Using PySerial is it possble to wait for data?