Page 1 of 1

How to set baudrate for serial communication in Visual C++

Posted: Fri Dec 02, 2011 12:53 am
by Saman
Here is the way to setup serial parameters for serial communication is Visual C++.

Code: Select all

DCB dcbSerialParams = {0};
dcbSerial.DCBlength=sizeof(dcbSerialParams);
if (!GetCommState(hSerial, &dcbSerialParams)) {
	//error getting state
}

dcbSerialParams.BaudRate=CBR_19200;
dcbSerialParams.ByteSize=8;
dcbSerialParams.StopBits=ONESTOPBIT;
dcbSerialParams.Parity=NOPARITY;
if(!SetCommState(hSerial, &dcbSerialParams)){
	//error setting serial port state
}

Re: How to set baudrate for serial communication in Visual C++

Posted: Sat Dec 01, 2012 11:26 am
by SukhdeepMankoo
You can choose mscomm too.