Serial communication in windows - ClearCommError finds no data in read buffer
I want to send data from a laptop (windows 7, processor 2.60GHz) to a desktop (windows xp, processor 3.10GHz) using serial communication (using a USB to RS232 convertor). The WriteFile function is able to send the data from the laptop (NumberOfBytesWritten is correct). But on the desktop side, ClearCommError detects no data in the read buffer.
This is the relevant code in my desktop:
while(1) {
ClearCommError(hPort,&dwErrors,&commStatus);
if (commStatus.cbInQue != 0) ReadFile(hPort,&data,1,&dwBytesRead,NULL);
Sleep(10);
}
The if condition is never satisfied. The baudrate and other parameters in the DCB struct are the same on both sides.
The same code works when I write and read in the same system by shorting the RX and TX pins in the RS232 connector.
Re: Serial communication in windows - ClearCommError finds no data in read buffer
Have you got the RS232 cable wired correctly at both ends? Do you need straight through or do you need to switch rx/tx? Do you just need 3 wire RS232 or does it need hardware handshaking as well? On the desktop side, open HyperTerminal and make sure you are receiving what the laptop is transmitting. If Hyperterminal on the desktop shows what the laptop is sending then the problem is with your receive code. If it doesn't display then try opening Hyperterminal on both machines and see if you can talk to each other. If you still can't then the problem is likely to be hardware related.
Re: Serial communication in windows - ClearCommError finds no data in read buffer
RS232 to RS232 direct (without modems) would need a crossover cable (also known as null-modem cable (full crossover) or link cable (3-wire cross over))
for pure transfer, 3 wires will do.
If you need additional flow control, you'll need a full crossover.
Like 2kaud said, try in a terminal program.