'Set communication parameters on opened port.'

def _reconfigure_port(self, force_update=False):

    if (self.fd is None):
        raise SerialException('Can    only    operate    on    a    valid    file    descriptor')
    custom_baud = None
    vmin = vtime = 0
    if (self._inter_byte_timeout is not None):
        vmin = 1
        vtime = int((self._inter_byte_timeout * 10))
    try:
        orig_attr = termios.tcgetattr(self.fd)
        (iflag, oflag, cflag, lflag, ispeed, ospeed, cc) = orig_attr
    except termios.error as msg:
        raise SerialException('Could    not    configure    port:    {}'.format(msg))
    cflag |= (termios.CLOCAL | termios.CREAD)
    lflag &= (~ ((((((termios.ICANON | termios.ECHO) | termios.ECHOE) | termios.ECHOK) | termios.ECHONL) | termios.ISIG) | termios.IEXTEN))
    for flag in ('ECHOCTL', 'ECHOKE'):
        if hasattr(termios, flag):
            lflag &= (~ getattr(termios, flag))
    oflag &= (~ ((termios.OPOST | termios.ONLCR) | termios.OCRNL))
    iflag &= (~ (((termios.INLCR | termios.IGNCR) | termios.ICRNL) | termios.IGNBRK))
    if hasattr(termios, 'IUCLC'):
        iflag &= (~ termios.IUCLC)
    if hasattr(termios, 'PARMRK'):
        iflag &= (~ termios.PARMRK)
    try:
        ispeed = ospeed = getattr(termios, 'B{}'.format(self._baudrate))
    except AttributeError:
        try:
            ispeed = ospeed = self.BAUDRATE_CONSTANTS[self._baudrate]
        except KeyError:
            ispeed = ospeed = getattr(termios, 'B38400')
            try:
                custom_baud = int(self._baudrate)
            except ValueError:
                raise ValueError('Invalid    baud    rate:    {!r}'.format(self._baudrate))
            else:
                if (custom_baud < 0):
                    raise ValueError('Invalid    baud    rate:    {!r}'.format(self._baudrate))
    cflag &= (~ termios.CSIZE)
    if (self._bytesize == 8):
        cflag |= termios.CS8
    elif (self._bytesize == 7):
        cflag |= termios.CS7
    elif (self._bytesize == 6):
        cflag |= termios.CS6
    elif (self._bytesize == 5):
        cflag |= termios.CS5
    else:
        raise ValueError('Invalid    char    len:    {!r}'.format(self._bytesize))
    if (self._stopbits == serial.STOPBITS_ONE):
        cflag &= (~ termios.CSTOPB)
    elif (self._stopbits == serial.STOPBITS_ONE_POINT_FIVE):
        cflag |= termios.CSTOPB
    elif (self._stopbits == serial.STOPBITS_TWO):
        cflag |= termios.CSTOPB
    else:
        raise ValueError('Invalid    stop    bit    specification:    {!r}'.format(self._stopbits))
    iflag &= (~ (termios.INPCK | termios.ISTRIP))
    if (self._parity == serial.PARITY_NONE):
        cflag &= (~ ((termios.PARENB | termios.PARODD) | CMSPAR))
    elif (self._parity == serial.PARITY_EVEN):
        cflag &= (~ (termios.PARODD | CMSPAR))
        cflag |= termios.PARENB
    elif (self._parity == serial.PARITY_ODD):
        cflag &= (~ CMSPAR)
        cflag |= (termios.PARENB | termios.PARODD)
    elif ((self._parity == serial.PARITY_MARK) and CMSPAR):
        cflag |= ((termios.PARENB | CMSPAR) | termios.PARODD)
    elif ((self._parity == serial.PARITY_SPACE) and CMSPAR):
        cflag |= (termios.PARENB | CMSPAR)
        cflag &= (~ termios.PARODD)
    else:
        raise ValueError('Invalid    parity:    {!r}'.format(self._parity))
    if hasattr(termios, 'IXANY'):
        if self._xonxoff:
            iflag |= (termios.IXON | termios.IXOFF)
        else:
            iflag &= (~ ((termios.IXON | termios.IXOFF) | termios.IXANY))
    elif self._xonxoff:
        iflag |= (termios.IXON | termios.IXOFF)
    else:
        iflag &= (~ (termios.IXON | termios.IXOFF))
    if hasattr(termios, 'CRTSCTS'):
        if self._rtscts:
            cflag |= termios.CRTSCTS
        else:
            cflag &= (~ termios.CRTSCTS)
    elif hasattr(termios, 'CNEW_RTSCTS'):
        if self._rtscts:
            cflag |= termios.CNEW_RTSCTS
        else:
            cflag &= (~ termios.CNEW_RTSCTS)
    if ((vmin < 0) or (vmin > 255)):
        raise ValueError('Invalid    vmin:    {!r}'.format(vmin))
    cc[termios.VMIN] = vmin
    if ((vtime < 0) or (vtime > 255)):
        raise ValueError('Invalid    vtime:    {!r}'.format(vtime))
    cc[termios.VTIME] = vtime
    if (force_update or ([iflag, oflag, cflag, lflag, ispeed, ospeed, cc] != orig_attr)):
        termios.tcsetattr(self.fd, termios.TCSANOW, [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])
    if (custom_baud is not None):
        self._set_special_baudrate(custom_baud)
    if (self._rs485_mode is not None):
        self._set_rs485_mode(self._rs485_mode)
