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 / C++ / MFC
  4. Doubt in Serial communication

Doubt in Serial communication

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 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.
  • K Offline
    K Offline
    kuttiam
    wrote on last edited by
    #1

    Hi All, I have a doubt in serial communication. I am using non-overlapped io serial communication inside a thread in my application. So while coomunicating with the instrument, the thread gets blocked without blocking the application. Now what is the difference between the above scenario and overlapped io communication? Thanks for your reply :) .

    C B 3 Replies Last reply
    0
    • K kuttiam

      Hi All, I have a doubt in serial communication. I am using non-overlapped io serial communication inside a thread in my application. So while coomunicating with the instrument, the thread gets blocked without blocking the application. Now what is the difference between the above scenario and overlapped io communication? Thanks for your reply :) .

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      In overlapped IO, the system will signal an event when the operation complete (read or write for example). But you still have to wait for that before processing your data (sure, you can't process your data if it is not available yet...). So, in general you still have to use a thread to wait on the event. The big difference is that using this technique, you'll be able to wait for multiple events. With a blocking call, you can't do anything but wait until the function returns.

      Cédric Moonen Software developer
      Charting control [v1.4]

      K 1 Reply Last reply
      0
      • C Cedric Moonen

        In overlapped IO, the system will signal an event when the operation complete (read or write for example). But you still have to wait for that before processing your data (sure, you can't process your data if it is not available yet...). So, in general you still have to use a thread to wait on the event. The big difference is that using this technique, you'll be able to wait for multiple events. With a blocking call, you can't do anything but wait until the function returns.

        Cédric Moonen Software developer
        Charting control [v1.4]

        K Offline
        K Offline
        kuttiam
        wrote on last edited by
        #3

        Hi Cedric, Thanks for your reply. If i place the blocking call in a thread, then the application will bot be blocked. In this scenario what is the difference between the two types of communication?

        C 1 Reply Last reply
        0
        • K kuttiam

          Hi Cedric, Thanks for your reply. If i place the blocking call in a thread, then the application will bot be blocked. In this scenario what is the difference between the two types of communication?

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          No, your application won't be blocked but you can't wait for other events in the same thread. Another point I made: by using overlapped IO, you will in general wait for the event to be signaled (so the read operation to finish for example). To do that, you will block the thread which is calling WaitForSingleObject. So, in general, even when I use overlapped IO I handle that in a separate thread. The difference, as I said before, is that you can wait for multiple events to happen instead of just one. For example you could be reading two serial ports in the same thread.

          Cédric Moonen Software developer
          Charting control [v1.4]

          1 Reply Last reply
          0
          • K kuttiam

            Hi All, I have a doubt in serial communication. I am using non-overlapped io serial communication inside a thread in my application. So while coomunicating with the instrument, the thread gets blocked without blocking the application. Now what is the difference between the above scenario and overlapped io communication? Thanks for your reply :) .

            B Offline
            B Offline
            buntyrolln
            wrote on last edited by
            #5

            Communications events can occur at any time in the course of using a communications port. The two steps involved in receiving notification of communications events are as follows: * SetCommMask sets the desired events that cause a notification. * WaitCommEvent issues a status check. The status check can be an overlapped or nonoverlapped operation, just as the read and write operations can be. There are two interesting side effects of SetCommMask and WaitCommEvent. First, if the communications port is open for nonoverlapped operation, WaitCommEvent will be blocked until an event occurs. If another thread calls SetCommMask to set a new event mask, that thread will be blocked on the call to SetCommMask. The reason is that the original call to WaitCommEvent in the first thread is still executing. The call to SetCommMask blocks the thread until the WaitCommEvent function returns in the first thread. This side effect is universal for ports open for nonoverlapped I/O. If a thread is blocked on any communications function and another thread calls a communications function, the second thread is blocked until the communications function returns in the first thread. The second interesting note about these functions is their use on a port open for overlapped operation. If SetCommMask sets a new event mask, any pending WaitCommEvent will complete successfully, and the event mask produced by the operation is NULL. For more details you can refer link given below: http://msdn.microsoft.com/en-us/library/ms810467.aspx[^]

            buntyrolln

            1 Reply Last reply
            0
            • K kuttiam

              Hi All, I have a doubt in serial communication. I am using non-overlapped io serial communication inside a thread in my application. So while coomunicating with the instrument, the thread gets blocked without blocking the application. Now what is the difference between the above scenario and overlapped io communication? Thanks for your reply :) .

              B Offline
              B Offline
              buntyrolln
              wrote on last edited by
              #6

              Continuation of above reply .... you can use overlapped-IO operation for communication with serial com port. Read code snippet for overlapped-IO is given below: DWORD dwRead; BOOL fWaitingOnRead = FALSE; OVERLAPPED osReader = {0}; // Create the overlapped event. Must be closed before exiting // to avoid a handle leak. osReader.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if (osReader.hEvent == NULL) // Error creating overlapped event; abort. if (!fWaitingOnRead) { // Issue read operation. if (!ReadFile(hComm, lpBuf, READ_BUF_SIZE, &dwRead, &osReader)) { if (GetLastError() != ERROR_IO_PENDING) // read not delayed? // Error in communications; report it. else fWaitingOnRead = TRUE; } else { // read completed immediately HandleASuccessfulRead(lpBuf, dwRead); } }

              buntyrolln

              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