​import serial #COM port number, BaudRate, timeout, parity, rtscts, stopbits, xonxoff=0 #Open serial port ser = serial.Serial('COM4', 9600, timeout=0,parity='N', rtscts=1,stopbits=1,xonxoff=0 )  #Send your device/instrument command inside write function  ser.write(b'hello')     #Read serial outputs line = ser.read() line = ser.readline() print(line) ​# check which port was really used print(ser.name)         # close port ser.close()