Am trying to establish automated serial connection with a bluetooth device.
For ex . the device is paired with a comport number 20 (Outgoing port) .The problem in this device is once the device is turned off ,it disconnects the bluetooth connection resulting the comport in some inaccessible state.(ie. when i try to open the create
file handle returns 0x79 -ERROR_SEM_TIMEOUT).
So i tried polling for the comport connection as shown below in main thread ,
{
......
do
{
hSerial = CreateFileA(pcomport,
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
IO_ATTRIBUTE,
0);
if (hSerial == INVALID_HANDLE_VALUE)
{
result = GetLastError();
if (ERROR_FILE_NOT_FOUND == result)
{
//serial port does not exist. Inform user and exit for now...
printf("spc [OpenSerialPort]:unable to detect COM port: %s\n", pcomport);
return hSerial;
}
//some other error occurred. Inform user.
printf("spc [OpenSerialPort]:unknown error 0x%08x at %s\n", result, pcomport);
CloseHandle(hSerial);
//return hSerial;
}
} while (hSerial == INVALID_HANDLE_VALUE);
....
}
This seems to work fine .But the problem am facing is while this program is running aside ,when i run another program which opened some other device (different comport num - Incoming port) where bluetooth connection is maintained ,the Readfile method
couldnt read the data sent by the device .it fails .
When i stop this polling code,i can get the data from other device (which uses the Createfile followed by Readfile without polling) .
To be clear why Reading a comport fails , while using Createfile continuously with another comport ?
may be because of polling with CreateFile() ?!
I couldnt find any method in msdn to detect the Serial port connection is established. ?
Any help would be appreciated .thanks.
EDIT: Sorry i have updated my question in detail .