See the Win32 API COMMTIMEOUTS for details.
Exemple #1
0
 /// <summary>
 /// Sets the timeouts for the serial port communication.
 /// </summary>
 /// <param name="timeouts">Timeouts to be set.</param>
 public void SetTimeouts(SerialPortTimeouts timeouts)
 {
     if (!Win32Api.SetCommTimeouts(m_fileHandle, ref timeouts))
     {
         throw new Win32Exception(Win32Api.GetLastError(), "'SetCommTimeouts()' failed");
     }
 }
Exemple #2
0
 /// <summary>
 /// Sets the read timeouts to return only the contents in the buffer, returning immediatelly.
 /// </summary>
 public void SetDefaultTimeouts()
 {
     if (IsOpen)
     {
         SerialPortTimeouts timeouts = this.GetTimeouts();
         timeouts.ReadIntervalTimeout        = UInt32.MaxValue;
         timeouts.ReadTotalTimeoutConstant   = 0;
         timeouts.ReadTotalTimeoutMultiplier = 0;
         this.SetTimeouts(timeouts);
     }
 }
Exemple #3
0
        /// <summary>
        /// Gets the timeouts currently set for the serial port communication.
        /// </summary>
        /// <returns>The timeouts currently set.</returns>
        public SerialPortTimeouts GetTimeouts()
        {
            if (!IsOpen)
            {
                throw new InvalidOperationException("Port is not open.");
            }

            SerialPortTimeouts commTimeouts = new SerialPortTimeouts();

            if (!Win32Api.GetCommTimeouts(m_fileHandle, ref commTimeouts))
            {
                throw new Win32Exception(Win32Api.GetLastError(), "'GetCommTimeouts()' failed");
            }

            return(commTimeouts);
        }
 public static extern bool SetCommTimeouts(IntPtr hFile, [In] ref SerialPortTimeouts lpCommTimeouts);
        /// <summary>
        /// Gets the timeouts currently set for the serial port communication.
        /// </summary>
        /// <returns>The timeouts currently set.</returns>
        public SerialPortTimeouts GetTimeouts()
        {
            if (!IsOpen) throw new InvalidOperationException("Port is not open.");

            SerialPortTimeouts commTimeouts = new SerialPortTimeouts();
            if (!Win32Api.GetCommTimeouts(m_fileHandle, ref commTimeouts))
            {
                throw new Win32Exception(Win32Api.GetLastError(), "'GetCommTimeouts()' failed");
            }

            return commTimeouts;
        }
 /// <summary>
 /// Sets the timeouts for the serial port communication.
 /// </summary>
 /// <param name="timeouts">Timeouts to be set.</param>
 public void SetTimeouts(SerialPortTimeouts timeouts)
 {
     if (!Win32Api.SetCommTimeouts(m_fileHandle, ref timeouts))
     {
         throw new Win32Exception(Win32Api.GetLastError(), "'SetCommTimeouts()' failed");                
     }
 }