Writing a Serial Communication Library for Windows - DWORD BaudRate, Parity
(Page 4 of 6 )
DWORD BaudRate
It represents the Baud rate for communication supported by external device. For example, you can give this parameter as 9600 or CBR_9600 for a BaudRate of 9600. The available Standard Baud rates supported as defined in Winbase.h are:
CBR_110
CBR_300
CBR_600
CBR_1200
CBR_2400
CBR_4800
CBR_9600
CBR_14400
CBR_19200
CBR_38400
CBR_56000
CBR_57600
CBR_115200
CBR_128000
CBR_256000
BYTE ByteSize
This represents the number of bits in the bytes transmitted and received. Standard values are 8 or 4.
DWORD fParity
Specifies whether parity checking is enabled. If this parameter is TRUE<code>, parity checking is performed and errors are reported. If <code>FALSE no parity checking is performed.
BYTE Parity
Specifies the parity scheme to be used. This member can be one of the following values:
EVENPARITY
MARKPARITY
NOPARITY
ODDPARITY
SPACEPARITY
BYTE StopBits
Specifies the number of stop bits to be used. This member can be one of the following values:
ONESTOPBIT
ONE5STOPBITS
TWOSTOPBITS
NOTE
The ConfigurePort() function is written on the assumption that the communication flow control is completely controlled on the basis of the protocol supported by the external device. It transmits and receives data without checking CTS/RTS and Xon/Xoff hardware flow control. You can modify this to your requirements by changing the values of the members of DCB which are responsible for it, in the implementation of ConfigurePort() in SerialComm.cpp.
ConfigurePort(CBR_9600, 8, true, EVENPARITY , ONESTOPBIT )
BOOL CSerialComm::SetCommunicationTimeouts(DWORD ReadIntervalTimeout,
DWORD ReadTotalTimeoutMultiplier,
DWORD ReadTotalTimeoutConstant,
DWORD WriteTotalTimeoutMultiplier,
DWORD WriteTotalTimeoutConstant)
{
if((m_bPortReady = GetCommTimeouts (m_hComm, &m_CommTimeouts))==0)
{
return FALSE;
}
m_CommTimeouts.ReadIntervalTimeout =ReadIntervalTimeout;
m_CommTimeouts.ReadTotalTimeoutConstant =ReadTotalTimeoutConstant;
m_CommTimeouts.ReadTotalTimeoutMultiplier =ReadTotalTimeoutMultiplier;
m_CommTimeouts.WriteTotalTimeoutConstant = WriteTotalTimeoutConstant;
m_CommTimeouts.WriteTotalTimeoutMultiplier =WriteTotalTimeoutMultiplier;
m_bPortReady = SetCommTimeouts (m_hComm, &m_CommTimeouts);
if(m_bPortReady ==0)
{
::MessageBox(NULL,_T("SetCommTimeouts function failed"),_T("Com Port Error"),MB_OK | MB_ICONERROR);
CloseHandle(m_hComm);
return FALSE;
}
return TRUE;
}
The SetCommunicationTimeouts() member function sets the write and read timeouts for data transmission. The parameters to be passed to this function are given next.
Next: Write and Read Timeouts >>
More Code Examples Articles
More By Digvijay Chauhan