Serial operation
import serial, time
import serial.tools.list_ports

port_list = list(serial.tools.list_ports.comports())
for port in port_list:
    print(port)


with serial.Serial(
    port='COM3', baudrate=115200,
    bytesize=serial.EIGHTBITS,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE) as ser:
	
    while True:
        command = str(input('>>> '))
        if 'exit' == command.lower():
            break
        
        if ser.is_open:
            #print("is open")
            cmd = (command+'\r\n').encode('ascii')
            #print(cmd)
            ser.reset_input_buffer()
            num_of_wirte = ser.write(cmd)
            #print(num_of_wirte)
            
        s = b''
        time.sleep(0.5)
        while ser.in_waiting > 0:
            s += ser.read(ser.in_waiting)

        lines = s.decode().split('\r\n')
        print(lines)
        for line in lines:
            if command != line and '>>> ' != line:
                print(line)
        
        ser.reset_output_buffer()
        
    ser.close()