Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Timeout exception when reading from serial port

Timeout exception when reading from serial port

Scheduled Pinned Locked Moved C#
tutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mmdullah
    wrote on last edited by
    #1

    Dear all, I got Timeout exception when reading from serial port. how to overcome? code: // ports boudRate =115200, readtimeout=300 and writetimeout=300 private void btnRead_Click(object sender, EventArgs e) { OpenPort(); string str; try { Thread.Sleep(1000); str = _serialPort.ReadLine(); // exception occurs here } catch (Exception ex) { str = ex.Message; } txtReadText.Text += string.Format("{0}{1}", "", str); ClosePort(); }

    P A 2 Replies Last reply
    0
    • M mmdullah

      Dear all, I got Timeout exception when reading from serial port. how to overcome? code: // ports boudRate =115200, readtimeout=300 and writetimeout=300 private void btnRead_Click(object sender, EventArgs e) { OpenPort(); string str; try { Thread.Sleep(1000); str = _serialPort.ReadLine(); // exception occurs here } catch (Exception ex) { str = ex.Message; } txtReadText.Text += string.Format("{0}{1}", "", str); ClosePort(); }

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Oh how lovely; we're so proud.

      M 1 Reply Last reply
      0
      • P PIEBALDconsult

        Oh how lovely; we're so proud.

        M Offline
        M Offline
        mmdullah
        wrote on last edited by
        #3

        courtesy is a small thing but enough to make a big difference

        1 Reply Last reply
        0
        • M mmdullah

          Dear all, I got Timeout exception when reading from serial port. how to overcome? code: // ports boudRate =115200, readtimeout=300 and writetimeout=300 private void btnRead_Click(object sender, EventArgs e) { OpenPort(); string str; try { Thread.Sleep(1000); str = _serialPort.ReadLine(); // exception occurs here } catch (Exception ex) { str = ex.Message; } txtReadText.Text += string.Format("{0}{1}", "", str); ClosePort(); }

          A Offline
          A Offline
          Alan N
          wrote on last edited by
          #4

          Hi, This is the expected behaviour. If _serialPort.ReadLine() is called and no data is available then the TimeoutException will be raised after 300ms. If you want ReadLine to block then don't set a timeout. Alan.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups