Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6752753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:04:54+00:00 2026-05-26T13:04:54+00:00

I am using a device driver that occasionaly misses an interrupt from hardware. To

  • 0

I am using a device driver that occasionaly misses an interrupt from hardware.

To read data from the device, I use the function

  BOOL WINAPI ReadFile(
   __in         HANDLE hFile,
   __out        LPVOID lpBuffer,
   __in         DWORD nNumberOfBytesToRead,
   __out_opt    LPDWORD lpNumberOfBytesRead,
   __inout_opt  LPOVERLAPPED lpOverlapped
  ); 

This function blocks forever when the device driver misses an interrupt. This results in the program stalling, and one has to restart windows to resolve it.

To fix this, I want to use a timeout-limit when calling Readfile(). But when I use

  BOOL WINAPI SetCommTimeouts(
   __in  HANDLE hFile,
   __in  LPCOMMTIMEOUTS lpCommTimeouts
  );

it fails with error code 87 (invalid parameters). Apparently, I can’t use this timeout stuff on a device driver handle. How can I fix this? Is there some other way to set a timeout limit on a device driver?

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:04:55+00:00Added an answer on May 26, 2026 at 1:04 pm

    You need to switch to asynchronous I/O. Open the device driver supplying the FILE_FLAG_OVERLAPPED flag to CreateFile and then pass an overlapped structure when you call ReadFile. The handle will be signaled when the i/o completes so you can use WaitForSingleObject where you supply the Handle passed to ReadFile and a timeout.

    Not all device drivers support asynch I/O so this may not actually work for you. If this is the case, the ReadFile will still block and not return “ERROR_PENDING_IO”.

    If you timeout, you should also call CancelIO to kill the ReadFile before the overlapped structure goes out of scope. Otherwise, if it happens to finish later, it’ll try to write the memory the overlapped structure used to live in.

    Asynch i/o is a bit tricky to get right so read the docs carefully.

    Update: An alternative occurred to me that you can call CancelIEx from a watchdog thread. Being a newer API, it may not be present on the platforms you have to support.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get data from a DMA enabled, PCIe hardware device into user-space
I was wondering how I could check if a device driver is loaded using
I'm using a device that's got GPRS media to connect to a PC running
I need to communicate with a hardware device using TCP and with Windows I
I have a .mbm file that I copy to my device using this line
I need to write a kernel module that is not a device driver. That
I have a Linux device driver that interfaces to a device that, in theory,
I'm implementing a ioctl in a Windows CE device driver that takes a pointer
I'm writing some software that automatically connects a Bluetooth device using the Windows Bluetooth
I'm writing a simple USB driver for our device using UMDF over WinUsb. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.