import os,sys,termios,time,select
fd=os.open('/dev/ttyACM0',os.O_RDWR|os.O_NOCTTY|os.O_NONBLOCK)
a=termios.tcgetattr(fd)
a[0]=0;a[1]=0;a[2]=termios.CS8|termios.CREAD|termios.CLOCAL;a[3]=0;a[4]=a[5]=termios.B115200
termios.tcsetattr(fd,termios.TCSANOW,a)
end=time.time()+float(sys.argv[1])
while time.time()<end:
    r,_,_=select.select([fd],[],[],0.5)
    if r:
        try: d=os.read(fd,4096)
        except BlockingIOError: continue
        sys.stdout.buffer.write(d); sys.stdout.flush()
