Unable to set fparity member of DCB structure using SetCommState()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • asadjahangir
    New Member
    • Mar 2008
    • 1

    Unable to set fparity member of DCB structure using SetCommState()

    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 = ODDPARITY; // 0-4=no,odd,even,m ark,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
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Sorry this question has been overlooked, you would have been better off asking it in C/C++.

    Anyway, in the code you posted you never set the value of dcb.DCBlength which needs to be set to the size of the structure dcb.

    Comment

    Working...