Exemplo n.º 1
0
        /// <summary>
        /// Opens this instance.
        /// </summary>
        public void Open()
        {
            if (_isOpen)
            {
                throw new InvalidOperationException("Port is already open");
            }

            _stream = new SerialPortStream(_portName, _baudRate, _dataBits, _parity, _stopBits, _dtrEnable,
                                           _rtsEnable, _handshake, _readTimeout, _writeTimeout, _readBufferSize, _writeBufferSize);

            _isOpen = true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing">
        ///   <c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected void Dispose(bool disposing)
        {
            if (!_isOpen)
            {
                return;
            }

            _isOpen = false;
            // Do not close the base stream when the finalizer is run; the managed code can still hold a reference to it.
            if (disposing)
            {
                _stream.Close();
            }
            _stream = null;
        }