Windows API ReadFile 丢弃空字符(串行端口) [英] Windows API ReadFile Drops Null Characters (Serial Port)

查看:31
本文介绍了Windows API ReadFile 丢弃空字符(串行端口)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ReadFile 读取空字符0x00",但它看不到它.

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

如果我向我的程序发送0x01 0x02 0x00 0x03".它将收到0x01 0x02 0x03".我知道我的发送方正在发送空字符(我使用范围来查看数据).

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).

我已经检查了 DCB 结构并将 fNull 设置为 false.(这应该允许接收空字节而不是丢弃)

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)

这是从 GetCommState 显示的 DCB 的配置:

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?

推荐答案

您已启用 XON/XOFF 流控制并指定 null 作为 XON/XOFF 字符.这就是为什么您没有看到空数据字节的原因.您需要将 fOutXfInX 字段设置为 0 而不是 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.

这篇关于Windows API ReadFile 丢弃空字符(串行端口)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆