Click to See Complete Forum and Search --> : Unable to set fparity member of DCB structure using SetCommState()


AsadJahangir
March 17th, 2008, 03:20 AM
Dear ,


I need ur help regarding Serial communication in Win32.

The problem, i m having is quite strange. It is related to fParity member of DCB structure

After setting the fparity=True with SetCommState(), when i get DCB structure with GetCommState(), i always find fparity=FALSE.


I have tested it on 3 machine all running windows xp sp2 and standard COM driver but having the same problem.

Its looks as SetCommState is unable to set fparity member of DCB structure.

Plz see the code snippet

// Get the default port setting information.
GetCommState (hPort, &PortDCB);

PortDCB.fParity = TRUE; // Enable parity checking
PortDCB.Parity = NOPARITY; // 0-4=no,odd,even,mark,space
// Configure the port according to the specifications of the DCB
// structure.
if (!SetCommState (hPort, &PortDCB))
{
// Could not configure the serial port.
DWORD dwError = GetLastError ();
return FALSE;
}
::GetCommState(hPort, &PortDCB);
//At this place, i found PortDCB.fparity=FALSE


regards,


Asad Jahangir

olivthill
March 17th, 2008, 09:01 AM
PortDCB.fParity = TRUE; // Enable parity checking
PortDCB.Parity = NOPARITY; // 0-4=no,odd,even,mark,space The second line is cancelling the effect of the first line.
Try with PortDCB.Parity = EVENPARITY;orPortDCB.Parity = ODDPARITY;See http://www.koders.com/cpp/fidAD4D4820B4D1E1744A145926B5315721E4A6198A.aspx

AsadJahangir
March 18th, 2008, 02:42 AM
I've already tried it. It still does not work.