Issue sending enter key through serial port in python

304 views Asked by At

I am having trouble connecting to a data acquisition box using a python3 script through a USB serial port. The box expects to receive an Enter Key to start responding and to get a username and password.

I have tried the following code to send the Enter key but I never receive anything from the serial port. Using a Terminal Emulator, it works just fine and after pressing enter I see the prompt waiting to log in.

import serial

ser = serial.Serial('COM5', 115200)

ser.write(str.encode('\r'))
ser.write(str.encode('\n'))
ser.writelines(str.encode('\r'))
ser.writelines(str.encode('\r\n'))
ser.write(bytes("\r",encoding='ascii'))

while True:
    s = ser.readline()
    print(s.decode('utf-8'))
    

Could someone kindly help?

0

There are 0 answers