Windows API ReadFile Drops Null Characters (Serial Port)

ε祈祈猫儿з 提交于 2019-12-13 03:52:44

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/26152890/windows-api-readfile-drops-null-characters-serial-port

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!