anthony-n
anthony-n

Reputation: 70

Windows API ReadFile Drops Null Characters (Serial Port)

I am using ReadFile to read a null character '0x00', but it is not able to see it.

If I send "0x01 0x02 0x00 0x03" to my program. It will receive "0x01 0x02 0x03". I know for a fact that my sending side is sending the null character (I used a scope to see the data).

I have checked the DCB structure and have fNull set to false. (which is supposed to allow for null bytes to be received and not discarded)

This is the configuration of the DCB shown from GetCommState:

    DCBlength   28
    BaudRate    9600
    fBinary 1   
    fParity 0
    fOutxCtsFlow    0   
    fOutxDsrFlow    0   
    fDtrControl 0   
    fDsrSensitivity 0   
    fTXContinueOnXoff   0   
    fOutX   1
    fInX    1   
    fErrorChar  0
    fNull   0
    fRtsControl 0
    fAbortOnError   0
    fDummy2 0
    wReserved   0
    XonLim  2048
    XoffLim 512 
    ByteSize    7
    Parity  0
    StopBits    2
    XonChar 0 '\0'  
    XoffChar    0 '\0'  
    ErrorChar   0 '\0'  
    EofChar 0 '\0'
    EvtChar 0 '\0'
    wReserved1  0

Am I missing something in the structure that might be blocking the null character as well? or is it possible it's a driver configuration or registry configuration that I need to change?

Upvotes: 0

Views: 724

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 598134

You have XON/XOFF flow control enabled and have specified null as the XON/XOFF characters. That is why you are not seeing null data bytes. You need to set the fOutX and fInX fields to 0 instead of 1.

Upvotes: 1

Related Questions