Click here to Skip to main content
15,921,716 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my VC++ code of serial communications,

I want to know how to set the values of DCB of configuration of serial ports.:

If I select a flow control value of 3 types :

1. Xon/Xoff
2. None
3. RTS/CTS

and then,

DCB.f.... = false or true...

Could you understand what I mean?

Thank you in advance.

What I have tried:

More 1 days wasted for this problem.
Posted
Updated 9-Jun-17 0:20am

 
Share this answer
 
Clear the DCB first and then set the required fields:
DCB dcb;
::ZeroMemory(&dcb, sizeof(dcb));
dcb.DCBlength = sizeof(dcb);
dcb.fBinary = TRUE; // must be always true

// Use your settings here (this is 9600 baud 8N1)
dcb.BaudRate = CBR_9600;
dcb.ByteSize = 8;
//dcb.Parity = NOPARITY; // (NOPARITY == 0)
dcb.StopBits = ONESTOPBIT;

// No flow control: Nothing to do

// RTS/CTS
dcb.fOutxCtsFlow = TRUE;
// EDIT: Must be off course RTS
//dcb.fDtrControl = DTR_CONTROL_HANDSHAKE;
dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;

// XON/XOFF
dcb.fOutX = dcb.fInX = TRUE;
dcb.XonChar = '\x11';
dcb.XoffChar = '\x13';
dcb.fTXContinueOnXoff = TRUE; // optional / depends

// These depend on the input buffer size (passed to SetupComm()). 
// Below are commonly used values (50 / 75 %).
dcb.XonLim = RxBufSize - (RxBufSize / 2);
dcb.XoffLim = RxBufSize - (RxBufSize / 4);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900