/**
         * Sets the new parameters of the serial port as
         * {@code SerialPortParameters}.
         *
         * @param parameters The new serial port parameters.
         *
         * @throws ConnectionException if any error occurs when setting the serial
         *                             port parameters.
         * @throws InvalidConfigurationException if the configuration is invalid.
         * @throws ArgumentNullException if {@code parameters == null}.
         *
         * @see #getPortParameters()
         * @see #setPortParameters(int, int, int, int, int)
         * @see SerialPortParameters
         */
        public void SetPortParameters(SerialPortParameters parameters)         /*throws InvalidConfigurationException, ConnectionException*/
        {
            Contract.Requires <ArgumentNullException>(parameters != null, "Serial port parameters cannot be null.");

            baudRate        = parameters.BaudRate;
            this.parameters = parameters;
            if (SerialPort.IsOpen)
            {
                SerialPort.Close();
                SerialPort.Open();
            }
        }
        /**
         * Class constructor. Instantiates a new {@code AbstractSerialPort} object
         * with the given parameters.
         *
         * @param port COM port name to use.
         * @param parameters Serial port connection parameters.
         * @param receiveTimeout Serial connection receive timeout in milliseconds.
         *
         * @throws ArgumentException if {@code receiveTimeout < 0}.
         * @throws ArgumentNullException if {@code port == null} or
         *                              if {@code parameters == null}.
         *
         * @see #AbstractSerialPort(String, int)
         * @see #AbstractSerialPort(String, int, int)
         * @see #AbstractSerialPort(String, SerialPortParameters)
         * @see SerialPortParameters
         */
        public MySerialPort(String port, SerialPortParameters parameters, int receiveTimeout)
        {
            Contract.Requires <ArgumentNullException>(port != null, "Serial port cannot be null");
            Contract.Requires <ArgumentNullException>(parameters != null, "SerialPortParameters cannot be null");
            Contract.Requires <ArgumentOutOfRangeException>(receiveTimeout >= 0, "Receive timeout cannot be less than 0");

            this.port           = port;
            this.baudRate       = parameters.BaudRate;
            this.receiveTimeout = receiveTimeout;
            this.parameters     = parameters;
            this._logger        = LogManager.GetLogger <MySerialPort>();

            SerialPort          = new SerialPort(port, baudRate);
            SerialPort.DataBits = parameters.DataBits;
            SerialPort.StopBits = parameters.StopBits;
            SerialPort.Parity   = parameters.Parity;

            SerialPort.Handshake = parameters.FlowControl;

            SerialPort.ReadTimeout   = receiveTimeout;
            SerialPort.DataReceived += SerialPort_DataReceived;
        }
 /**
  * Class constructor. Instantiates a new {@code AbstractSerialPort} object
  * with the given parameters.
  *
  * @param port COM port name to use.
  * @param parameters Serial port connection parameters.
  *
  * @throws ArgumentNullException if {@code port == null} or
  *                              if {@code parameters == null}.
  *
  * @see #AbstractSerialPort(String, int)
  * @see #AbstractSerialPort(String, int, int)
  * @see #AbstractSerialPort(String, SerialPortParameters, int)
  * @see SerialPortParameters
  */
 public MySerialPort(String port, SerialPortParameters parameters)
     : this(port, parameters, DEFAULT_PORT_TIMEOUT)
 {
 }
        /**
         * Sets the new parameters of the serial port.
         *
         * @param baudRate The new value of baud rate.
         * @param dataBits The new value of data bits.
         * @param stopBits The new value of stop bits.
         * @param parity The new value of parity.
         * @param flowControl The new value of flow control.
         *
         * @throws ConnectionException if any error occurs when setting the serial
         *                             port parameters
         * @throws ArgumentException if {@code baudRate < 0} or
         *                                  if {@code dataBits < 0} or
         *                                  if {@code stopBits < 0} or
         *                                  if {@code parity < 0} or
         *                                  if {@code flowControl < 0}.
         * @throws InvalidConfigurationException if the configuration is invalid.
         *
         * @see #getPortParameters()
         * @see #setPortParameters(SerialPortParameters)
         */
        public void SetPortParameters(int baudRate, int dataBits, StopBits stopBits, Parity parity, Handshake flowControl)         /*throws InvalidConfigurationException, ConnectionException*/
        {
            SerialPortParameters parameters = new SerialPortParameters(baudRate, dataBits, stopBits, parity, flowControl);

            SetPortParameters(parameters);
        }