////////////////////////////////////////////////////////////////////////// // Private Methods // // NOTE: These private properties and methods are generally NOT // thread-safe -- call these methods within "lock (m_lock)" or an // equivalent. // /// <summary> /// Opens the serial port, if it's not open yet. /// </summary> /// void OpenSerialPort() { // do nothing if OpenSerialPort() was already called if (m_serialPort != null) return; // create and initialize <m_serialPort> m_serialPort = new DnSerialPort(new DnSerialPortStringResources(), m_serialPortName, 4800, Parity.None, 8, StopBits.One); m_serialPort.DataReceived += new SerialDataReceivedEventHandler( m_serialPort_DataReceived); m_serialPort.ErrorReceived += new SerialErrorReceivedEventHandler( m_serialPort_ErrorReceived); m_serialPort.Open(); }
/// <summary> /// Closes the serial port, if it's open. /// </summary> /// void CloseSerialPort() { if (m_serialPort != null) { m_serialPort.Purge(); m_serialPort.Close(); m_serialPort = null; } }