import serial


def checkPort():
    """
    This function reads the serial port and writes it.
    """
    try:
        ser = serial.Serial(
            port=21,
            baudrate=9600,
            bytesize=serial.EIGHTBITS,
            parity=serial.PARITY_NONE,
            stopbits=serial.STOPBITS_ONE,
            timeout=10          
            )
       
        if ser.isOpen():     
            print "Port Open"

        else:           
           ser.close()
           print"port closed"
           
    except serial.serialutil.SerialException:
        print "Failed to open port"



checkPort()

