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. Windows API
  4. EvtChar and overlapped Readfile(serialport....

EvtChar and overlapped Readfile(serialport....

Scheduled Pinned Locked Moved Windows API
helptutorialquestion
4 Posts 2 Posters 36 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.
  • S Offline
    S Offline
    stefan dimitrov
    wrote on last edited by
    #1

    Hello, I'm trying to use serial port in asynchronous mode,using overlapped structures and event handlers. Function ReadFile(porthandle,buffer, BytesToReceive....) signals waiting thread ,when received bytes counts to "BytesToReceive. Ok. But i dont know how many bytes will come. One solution is to set BytesToReceive=1. Its not elegant. Other way is to use timeouts. Then ReadFile signals to waiting thread. Other -3th- way is to use EvtChar, in my case i know every received packet ends with known character. I settled event structures and received notification on EV_RXLAG . But how to handle properly? When this event happens, there are ,let say 10 received bytes, but ReadFile is called with BytesToreceive=100. I didnt find explanation how to cancel ReadFile and get these 10 bytes. Any help is welcome!

    L 1 Reply Last reply
    0
    • S stefan dimitrov

      Hello, I'm trying to use serial port in asynchronous mode,using overlapped structures and event handlers. Function ReadFile(porthandle,buffer, BytesToReceive....) signals waiting thread ,when received bytes counts to "BytesToReceive. Ok. But i dont know how many bytes will come. One solution is to set BytesToReceive=1. Its not elegant. Other way is to use timeouts. Then ReadFile signals to waiting thread. Other -3th- way is to use EvtChar, in my case i know every received packet ends with known character. I settled event structures and received notification on EV_RXLAG . But how to handle properly? When this event happens, there are ,let say 10 received bytes, but ReadFile is called with BytesToreceive=100. I didnt find explanation how to cancel ReadFile and get these 10 bytes. Any help is welcome!

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You should use the default value of 1 so that you get signalled on every byte received. You then transfer each byte to some data buffer which you later process when you have received a minimum number of bytes or when you are able to recognise that a complete message has been received.

      S 1 Reply Last reply
      0
      • L Lost User

        You should use the default value of 1 so that you get signalled on every byte received. You then transfer each byte to some data buffer which you later process when you have received a minimum number of bytes or when you are able to recognise that a complete message has been received.

        S Offline
        S Offline
        stefan dimitrov
        wrote on last edited by
        #3

        Richard, thank You for post! I understand this method, but it seems to me non-elegant. My question was a little different.

        L 1 Reply Last reply
        0
        • S stefan dimitrov

          Richard, thank You for post! I understand this method, but it seems to me non-elegant. My question was a little different.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          See Canceling Pending I/O Operations (Windows)[^].

          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