Serial communication in windows - ClearCommError finds no data in read buffer
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Serial communication in windows - ClearCommError finds no data in read buffer

  1. #1
    Join Date
    Dec 2013
    Posts
    1

    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.

  2. #2
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,455

    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.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,923

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center