• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1664
  • Last Modified:

Non-blocking ReadFile()?

Hi guys,

I'm writing an app in C/++ which implements some serial communication over Bluetooth.

Firstly, when a serial connection is established between two devices using (virtual) Com port COM4: I use the CreateFile() function to obtain a handle. I then use the WriteFile() function to write a custom packet of 64 bytes to the com port. This works fine, and the data is received at the other end. The other device then responds with a 64 byte packet. This also works fine BUT only when the 2nd device responds. If the 2nd device does not respond (it may not have the serial app software running) then the ReadFile() function halts the program on the 1st device - there is no data to be read.

What is the easiest way to allow my program to skip ReadFile() if no data is waiting to be read?
Maybe allowing for a slight delay in communication so an active device has time to send data to the ReadFile() function?

I have been looking at a number of ways e.g. ReadFileEx, Overlapping and creating a new threads - but I'm not having much success.

Any help will be gratefully received,

Rich
0
tr309
Asked:
tr309
  • 2
1 Solution
 
tr309Author Commented:
Fantastic. I would never have found this. I wish I could give you more points but I need to start answering questions before I can do that.
0
 
jhshuklaCommented:
no prob. that wasn't much of work for me. experience counts. and yeah, thanks for points.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now