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. Cancelation of WriteFile WINAPI

Cancelation of WriteFile WINAPI

Scheduled Pinned Locked Moved C / C++ / MFC
2 Posts 2 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.
  • N Offline
    N Offline
    Natalie Katz
    wrote on last edited by
    #1

    Hi I'm using the WriteFile and ReadFile WINAPI to write/read from a COM port periodically. The protocol is : first wirte to a port and then read the response from a port (=device). The write operation occures every 50 msec at least. Every second attempt to call WriteFile fails and GetLastError returns ERROR_OPERATION_ABORTED. Then I use PurgeComm to clean a port after the failure. The next call to WriteFile succeedes, ReadFile succeedes, and the next try to write is cancelled and so on. Does anybody know what can cause this error? Thanks :(( Natalie

    T 1 Reply Last reply
    0
    • N Natalie Katz

      Hi I'm using the WriteFile and ReadFile WINAPI to write/read from a COM port periodically. The protocol is : first wirte to a port and then read the response from a port (=device). The write operation occures every 50 msec at least. Every second attempt to call WriteFile fails and GetLastError returns ERROR_OPERATION_ABORTED. Then I use PurgeComm to clean a port after the failure. The next call to WriteFile succeedes, ReadFile succeedes, and the next try to write is cancelled and so on. Does anybody know what can cause this error? Thanks :(( Natalie

      T Offline
      T Offline
      Tim Deveaux
      wrote on last edited by
      #2

      I don't have a direct answer as to the cause, but you might want to look into overlapped IO in a situation like this - creating a file with FILE_FLAG_OVERLAPPED allows simultaneous reads and writes, and gives you a more windows like async type of operation. Takes a little more work to set up - there's good stuff on codeproject to help - (pj naughter's class may use this approach, or both - not sure) - but once you get it going its nice - polling is soooo passe... And don't be scared by the docs - overlapped io is available for COM devices on win9x. Just a thought. :)

      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