seirial com with python and arduino. I can read a data from arduino.

I write the two type code of python to use the arduino with serial commnunication.
1st code is using the input with keyboard. 2nd is using the variable in the code withnout using a keyboard.
1st code works well. But 2nd doesn’t work.

< 1st >

import serial
import time

ARD = serial.Serial('COM14',115200)
time.sleep(1)

print("comport # :", ARD.name)
print("Enter r to get LED ON & n to get OFF & q to EXIT")


while (1):
    c = input()
    
    if (c == 'q'):
        break
    
    #print ("you entered", c)
    
    if (c == 'r' or c == 'n'):
        c = c.encode('utf-8')
        ARD.write(c)        
        
        a = ARD.readline()
        print("READ", a)
        
        if a == b'On\r\n' or a == b'Off\r\n':
            print("OK")
            
    else:
        print("NG")

< 2nd >

import serial
import time

ARD = serial.Serial('COM14',115200)
time.sleep(2)

print("comport # :", ARD.name)
print("Enter r to get LED ON & n to get OFF & q to EXIT")

while (True):
    
    c = 'r'
    print("input", c)

    c = c.encode('utf-8')
    ARD.write(c)
    
    time.sleep(6)

    a = ARD.readline()
    print("read", a)
    

    if a == b'On\r\n':
        print("OK")
        
    else:
        print("NG")

What do I miss???

leosis:
1st code works well. But 2nd doesn't work.

What do you mean by "doesn't work" - please describe in as much detail as possible.

Would it help if you move time.sleep(6) below the line a = ARD.readline()

...R