分享

DCB(串口的DCB结构)

 筱肆 2014-03-13

DCB(串口的DCB结构)  

2010-03-29 15:04:08|  分类: wince |举报 |字号 订阅

串口通讯中的DCB结构

typedef struct _DCB {// dcb

DWORD DCBlength; // sizeof(DCB)

DORD BaudRate; // current baud rate 指定当前的波特率

DWORD fBinary: 1; // binary mode, no EOF check 指定是否允许二进制模式WIN95中须为TRUE

DWORD fParity: 1; // enable parity checking 指定奇偶校验是否允许

DWORD fOutxCtsFlow:1; // CTS output flow control 指定CTS是否用于检测发送控制。当为TRUE时CTS为
// OFF,发送将被挂起。(发送清楚)
DWORD fOutxDsrFlow:1; // DSR output flow control 指定CTS是否用于检测发送控制。
//(数据装备好) 当为TRUE是CTS为OFF,发送将被挂起。
DWORD fDtrControl:2; // DTR flow control type
//DTR_CONTROL_DISABLE值将DTR置为OFF, //DTR_CONTROL_ENABLE值将DTR置为ON, DTR_CONTROL_HANDSHAKE 允许DTR"握手",
DWORD fDsrSensitivity:1;
// DSR sensitivity 当该值为TRUE时DSR为OFF时接收的字节被忽略
DWORD fTXContinueOnXoff:1; // XOFF continues Tx
指定当接收缓冲区已满,并且驱动程序已经发送出XoffChar字符时发送是否停止。
TRUE时,在接收缓冲区接收到缓冲区已满的字节XoffLim且驱动程序已经发送出XoffChar字 符中止接收字节之后,发送继续进行。
FALSE时,在接收缓冲区接收到代表缓冲区已空的字节XonChar且驱动程序已经发送出恢复 发送的XonChar之后,发送继续进行。
DWORD fOutX: 1; // XON/XOFF out flow control TRUE时,接收到XoffChar之后便停止发送
接收到XonChar之后将重新开始

DWORD fInX: 1; // XON/XOFF in flow control
TRUE时,接收缓冲区接收到代表缓冲区满的XoffLim之后,XoffChar发送出去
接收缓冲区接收到代表缓冲区空的XonLim之后,XonChar发送出去
DWORD fErrorChar: 1; // enable error replacement
该值为TRUE且fParity为TRUE时,用ErrorChar 成员指定的字符代替奇偶校验错误的接收字符
DWORD fNull: 1; // enable null stripping  TRUE时,接收时去掉空(0值)字节

DWORD fRtsControl:2; // RTS flow control

DWORD fAbortOnError:1; // abort reads/writes on error  TRUE时,有错误发生时中止读和写操作
RTS_CONTROL_DISABLE时,RTS置为OFF
RTS_CONTROL_ENABLE时, RTS置为ON
RTS_CONTROL_HANDSHAKE时,
当接收缓冲区小于半满时RTS为ON
当接收缓冲区超过四分之三满时RTS为OFF
RTS_CONTROL_TOGGLE时,
当接收缓冲区仍有剩余字节时RTS为ON ,否则缺省为OFF
DWORD fDummy2:17; // reserved  未使用

WORD wReserved; // not currently used  未使用,必须为0

WORD XonLim; // transmit XON threshold
指定在XON字符发送这前接收缓冲区中可允许的最小字节数
WORD XoffLim; // transmit XOFF threshold
指定在XOFF字符发送这前接收缓冲区中可允许的最小字节数
BYTE ByteSize; // number of bits/byte, 4-8  指定端口当前使用的数据位

BYTE Parity; // 0-4=no,odd,even,mark,space 指定端口当前使用的奇偶校验方法,可能为:
EVENPARITY,MARKPARITY,NOPARITY,ODDPARITY BYTE StopBits; 0,1,2 = 1, 1.5, 2   指定端口当前使用的停止位数,可能为:
ONESTOPBIT,ONE5STOPBITS,TWOSTOPBITS
char XonChar; // Tx and Rx XON character  指定用于发送和接收字符XON的值

char XoffChar; // Tx and Rx XOFF character  指定用于发送和接收字符XOFF值

char ErrorChar; // error replacement character本字符用来代替接收到的奇偶校验发生错误时的值

char EofChar; // end of input character 当没有使用二进制模式时,本字符可用来指示数据的结束

char EvtChar; // received event character 当接收到此字符时,会产生一个事件

WORD wReserved1; // reserved; do not use 未使用

} DCB;



--------------------------------------

DCB

The DCB structure defines the control setting for a serial communications device.
typedef struct _DCB { // dcb DWORD DCBlength; // sizeof(DCB) DWORD BaudRate; // current baud rate DWORD fBinary: 1; // binary mode, no EOF check DWORD fParity: 1; // enable parity checking DWORD fOutxCtsFlow:1; // CTS output flow control DWORD fOutxDsrFlow:1; // DSR output flow control DWORD fDtrControl:2; // DTR flow control type DWORD fDsrSensitivity:1; // DSR sensitivity DWORD fTXContinueOnXoff:1; // XOFF continues Tx DWORD fOutX: 1; // XON/XOFF out flow control DWORD fInX: 1; // XON/XOFF in flow control DWORD fErrorChar: 1; // enable error replacement DWORD fNull: 1; // enable null stripping DWORD fRtsControl:2; // RTS flow control DWORD fAbortOnError:1; // abort reads/writes on error DWORD fDummy2:17; // reserved WORD wReserved; // not currently used WORD XonLim; // transmit XON threshold WORD XoffLim; // transmit XOFF threshold BYTE ByteSize; // number of bits/byte, 4-8 BYTE Parity; // 0-4=no,odd,even,mark,space BYTE StopBits; // 0,1,2 = 1, 1.5, 2 char XonChar; // Tx and Rx XON character char XoffChar; // Tx and Rx XOFF character char ErrorChar; // error replacement character char EofChar; // end of input character char EvtChar; // received event character WORD wReserved1; // reserved; do not use } DCB;
Members
DCBlength
Specifies the length, in bytes, of the DCB structure.
BaudRate
Specifies the baud rate at which the communications device operates. This member can be an actual baud rate value, or one of the following baud rate indexes: CBR_110 CBR_19200
CBR_300 CBR_38400
CBR_600 CBR_56000
CBR_1200 CBR_57600
CBR_2400 CBR_115200
CBR_4800 CBR_128000
CBR_9600 CBR_256000
CBR_14400


fBinary
Specifies whether binary mode is enabled. The Win32 API does not support nonbinary mode transfers, so this member must be TRUE. Using FALSE will not work.
fParity
Specifies whether parity checking is enabled. If this member is TRUE, parity checking is performed and errors are reported.
fOutxCtsFlow
Specifies whether the CTS (clear-to-send) signal is monitored for output flow control. If this member is TRUE and CTS is turned off, output is suspended until CTS is sent again.
fOutxDsrFlow
Specifies whether the DSR (data-set-ready) signal is monitored for output flow control. If this member is TRUE and DSR is turned off, output is suspended until DSR is sent again.
fDtrControl
Specifies the DTR (data-terminal-ready) flow control. This member can be one of the following values: Value Meaning
DTR_CONTROL_DISABLE Disables the DTR line when the device is opened and leaves it disabled.
DTR_CONTROL_ENABLE Enables the DTR line when the device is opened and leaves it on.
DTR_CONTROL_HANDSHAKE Enables DTR handshaking. If handshaking is enabled, it is an error for the application to adjust the line by using the EscapeCommFunction function.


fDsrSensitivity
Specifies whether the communications driver is sensitive to the state of the DSR signal. If this member is TRUE, the driver ignores any bytes received, unless the DSR modem input line is high.
fTXContinueOnXoff
Specifies whether transmission stops when the input buffer is full and the driver has transmitted the XoffChar character. If this member is TRUE, transmission continues after the input buffer has come within XoffLim bytes of being full and the driver has transmitted the XoffChar character to stop receiving bytes. If this member is FALSE, transmission does not continue until the input buffer is within XonLim bytes of being empty and the driver has transmitted the XonChar character to resume reception.
fOutX
Specifies whether XON/XOFF flow control is used during transmission. If this member is TRUE, transmission stops when the XoffChar character is received and starts again when the XonChar character is received.
fInX
Specifies whether XON/XOFF flow control is used during reception. If this member is TRUE, the XoffChar character is sent when the input buffer comes within XoffLim bytes of being full, and the XonChar character is sent when the input buffer comes within XonLim bytes of being empty.
fErrorChar
Specifies whether bytes received with parity errors are replaced with the character specified by the ErrorChar member. If this member is TRUE and the fParity member is TRUE, replacement occurs.
fNull
Specifies whether null bytes are discarded. If this member is TRUE, null bytes are discarded when received.
fRtsControl
Specifies the RTS (request-to-send) flow control. If this value is zero, the default is RTS_CONTROL_HANDSHAKE. This member can be one of the following values: Value Meaning
RTS_CONTROL_DISABLE Disables the RTS line when the device is opened and leaves it disabled.
RTS_CONTROL_ENABLE Enables the RTS line when the device is opened and leaves it on.
RTS_CONTROL_HANDSHAKE Enables RTS handshaking. The driver raises the RTS line when the "type-ahead" (input) buffer is less than one-half full and lowers the RTS line when the buffer is more than three-quarters full. If handshaking is enabled, it is an error for the application to adjust the line by using the EscapeCommFunction function.
RTS_CONTROL_TOGGLE Specifies that the RTS line will be high if bytes are available for transmission. After all buffered bytes have been sent, the RTS line will be low.


fAbortOnError
Specifies whether read and write operations are terminated if an error occurs. If this member is TRUE, the driver terminates all read and write operations with an error status if an error occurs. The driver will not accept any further communications operations until the application has acknowledged the error by calling the ClearCommError function.
fDummy2
Reserved; do not use.
wReserved
Not used; must be set to zero.
XonLim
Specifies the minimum number of bytes allowed in the input buffer before the XON character is sent.
XoffLim
Specifies the maximum number of bytes allowed in the input buffer before the XOFF character is sent. The maximum number of bytes allowed is calculated by subtracting this value from the size, in bytes, of the input buffer.
ByteSize
Specifies the number of bits in the bytes transmitted and received.
Parity
Specifies the parity scheme to be used. This member can be one of the following values: Value Meaning
EVENPARITY Even
MARKPARITY Mark
NOPARITY No parity
ODDPARITY Odd
SPACEPARITY Space


StopBits
Specifies the number of stop bits to be used. This member can be one of the following values: Value Meaning
ONESTOPBIT 1 stop bit
ONE5STOPBITS 1.5 stop bits
TWOSTOPBITS 2 stop bits


XonChar
Specifies the value of the XON character for both transmission and reception.
XoffChar
Specifies the value of the XOFF character for both transmission and reception.
ErrorChar
Specifies the value of the character used to replace bytes received with a parity error.
EofChar
Specifies the value of the character used to signal the end of data.
EvtChar
Specifies the value of the character used to signal an event.
wReserved1
Reserved; do not use.
Remarks

When a DCB structure is used to configure the 8250, the following restrictions apply to the values specified for the ByteSize and StopBits members:
The number of data bits must be 5 to 8 bits.
The use of 5 data bits with 2 stop bits is an invalid combination, as is 6, 7, or 8 data bits with 1.5 stop bits.
QuickInfo

Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in winbase.h.
See Also

Communications Overview, Communication Structures, BuildCommDCB, ClearCommError, EscapeCommFunction, GetCommState, SetCommState
阅读(1080)| 评论(1)
|      
推荐 转载

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多