I am trying to write a script currently I am using ser.read() directly and printing values but I want to write a function where it waits for some time reads all char and than gets out of loop. Current loop prints all char but doesnt get out of the loop and I have to either edit and make it exit by keyboard click. But I want a script where it reads and exit and user doesnt need to do anything. Sorry if a noob question but new with Python and Pyserial
if(ser.isOpen()):
try:
def read():
ser.flushInput()
while 1:
try:
check = ser.read()
print check
except Exception:
print("Error")
else:
print("Port not open")