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,