First, you should use
Hercules[
^] utility to check that the communication is OK.
If you can't comminucate with Hercules, then you probably have a problem with your device. Otherwise the problem comes from your code:
- Check that all the parameters are correct in your
DCB
struct.
- Check the return value from
ReadFile
and if it returns
FALSE
, call
GetLastError
to have extra information.
One last thing. How you open your port is strange to me. The safest way to open a COM port is:
int comNumber = 3;
char comName[10];
sprintf(comName, "\\\\.\\COM%d", comNumber);
comport = CreateFile(comName, ...);
If you don't use
"\\.\"
you may have problems for COM ports greater than COM9.
-----------
By the way, you should wait a little bit after the port is opened, just to give time for the data to arrive.
For example do a
Sleep(2000)
(wait 2 seconds) before calling
ReadFile
.