Serial DCB Parameter Meaning--WIN32 API Serial Port

Keywords: Linux IoT stm32

DCB structure must be used when programming serial port with WIN32 API.

First, first, the DCB structure

typedef struct _DCB {  
        DWORD DCBlength;           
        DWORD BaudRate;            
        DWORD fBinary: 1;          
        DWORD fParity: 1;          
        DWORD fOutxCtsFlow:1;      
        DWORD fOutxDsrFlow:1;      
        DWORD fDtrControl:2;       
        DWORD fDsrSensitivity:1;  
        DWORD fTXContinueOnXoff:1; 
        DWORD fOutX: 1;            
        DWORD fInX: 1;             
        DWORD fErrorChar: 1;       
        DWORD fNull: 1;            
        DWORD fRtsControl:2;       
        DWORD fAbortOnError:1;     
        DWORD fDummy2:17;         
        WORD wReserved;                    
        WORD XonLim;               
        WORD XoffLim;              
        BYTE ByteSize;             
        BYTE Parity;               
        BYTE StopBits;             
        char XonChar;              
        char XoffChar;             
        char ErrorChar;            
        char EofChar;              
        char EvtChar;              
        WORD wReserved1;        
    } DCB; 
2. flow control(Flow Control) Settings for
     Flow control is divided into hardware flow control and software flow control, while hardware flow control is divided into RTS/CTS and DTR/DSR Two. Software flow control is Xon/Xoff.  
     DTR/DSR Hardware Flow Control:
     1) DWORD fOutxDsrFlow:1;            TRUE When supported DSR Flow control. DSR by OFF Stop sending when.
     2) DWORD fDtrControl:2;                DTR Settings. (Set Height)/Set low...)   
     3) DWORD fDsrSensitivity:1;           TRUE When DSR by OFF,Then the receiver ignores all characters.  

     RTS/CTS Hardware Flow Control:
     4) DWORD fOutxCtsFlow:1;            TRUE When supported CTS Flow control. CTS by OFF Stop sending when.
     5) DWORD fRtsControl:2;               RTS Settings. (Set Height)/Set low...)   

     Xon/Xoff Software Flow Control:
     6) DWORD fOutX: 1;                       Sender side support Xon/Xoff. 
     7) DWORD fInX: 1;                         Receiver Support Xon/Xoff. 
     8) WORD XonLim;                          When receiving Buffer Less characters in XonLim Send the specified number of characters Xon Character, let the other party continue to send.
     9) WORD XoffLim;                          Receive Buffer Achieve XoffLim Send the specified number of characters Xoff Character to stop the other party from sending.
     10)char XonChar;                          Xon Character.
     11)char XoffChar;                          Xoff Character.
     12)DWORD fTXContinueOnXoff:1; TRUE Whether or not the receiver is Xoff, Our sender keeps sending. (That is, our sender and our receiver) Xon/Xoff Is independent of each other. False When the receiver buffer Achieve XoffLim When the sender finishes sending Xoff After the character, stop sending.
                   
3.  Error Situation handling
     1) DWORD fErrorChar: 1;              TRUE When, if fParity by TRUE, Then use ErrorChar replace Parity Check Wrong character.
     2) DWORD fAbortOnError:1;          TRUE Stop reading and writing when an error occurs.
     3) char ErrorChar;                         Parity Check Replaced characters in case of error.
         
4. Other parameters
     1) DWORD DCBlength;                  DCB Length of structure in bytes
     2) DWORD fBinary: 1;                   Binary mode.(Must be 1 )
     3) DWORD fNull: 1;                       TRUE When receiving, remove empty bytes (0) x0)
     4) char EofChar;                           EOF Substitute Characters
     5) char EvtChar;                           Event Trigger Character
     6) DWORD fDummy2:17;              Retain
     7) WORD wReserved;                  Retain
     8) WORD wReserved1;                 Retain
--------
Copyright notice: This is CSDN Blogger「qq_20312079」Original articles, follow CC 4.0 BY-SA Copyright Agreement, please attach a link to the original source and this statement for reproducing.
Original Link: https://blog.csdn.net/qq_20312079/article/details/104668304

2. In this structure, there are 28 variables, and these members are classified into 4 categories.

1. Basic Settings of Serial Port

  1. DWORD BaudRate; Baud rate settings.
  2. BYTE ByteSize; data bit settings.
  3. DWORD fParity: 1; Parity check is supported when TRUE is used.
  4. BYTE Parity; setting of parity bits
  5. BYTE StopBits; setting of stop bits

2. Flow Control Settings
Flow control is divided into hardware flow control and software flow control. Hardware flow control is divided into RTS/CTS and DTR/DSR. Software flow control is Xon/Xoff.

DTR/DSR Hardware Flow Control:
1) DWORD fOutxDsrFlow:1;DSR flow control is supported when TRUE. When DSR is OFF, stop sending.
2) DWORD fDtrControl:2;DTR Settings. (Set High/Low...)
3) DWORD fDsrSensitivity:1; TRUE, when the DSR is OFF, the receiver ignores all characters.
RTS/CTS Hardware Flow Control:
4) DWORD fOutxCtsFlow:1; supports CTS flow control when TRUE. Stops sending when CTS is OFF.
5) DWORD fRtsControl:2; RTS settings. (Set high/low...)
Xon/Xoff Software Flow Control:
6) DWORD fOutX: 1; Xon/Xoff is supported on the sender.
7) DWORD fInX: 1; Xon/Xoff is supported on the receiving side.
8) WORD XonLim; when receiving a Buffer reduces the number of characters specified by the small XonLim, send the Xon character and let the other party continue sending.
9) WORD XoffLim; when receiving a Buffer up to the number of characters specified by XoffLim, send the Xoff character and ask the other party to stop sending it.
10)char XonChar; Xon characters.
11)char XoffChar; Xoff characters.
12)DWORD fTXContinueOnXoff:1; TRUE, the sender sends continuously regardless of whether the receiver is Xoff or not. (That is, the sender of this party is independent of the receiver Xon/Xoff). For False, when the receiver buffer reaches XoffLim, the sender stops sending Xoff characters.

3. Error case handling
1) DWORD fErrorChar: 1; when TRUE, if fParity is TRUE, replace the wrong character of Parity Check with ErrorChar.
2) DWORD fAbortOnError:1; when TRUE, stop reading and writing when an error occurs.
3) Char ErrorChar; Replaced characters when Parity Check is wrong.

4. Other parameters
1) DWORD DCBlength; length of DCB structure in bytes
2) DWORD fBinary: 1; Binary mode. (Must be 1)
3) DWORD fNull: 1; when TRUE is received, null bytes are removed (0x0)
4) char EofChar; EOF replacement characters
5) char EvtChar; event trigger character
6) DWORD fDummy2:17; reserved
7) WORD wReserved; reserved
8) WORD wReserved1; reserved

Original Link:https://blog.csdn.net/qq_20312079/article/details/104668304

Posted by roflpwnt on Wed, 15 Sep 2021 16:24:57 -0700