GetCommState Doesn't Set fParity Flag

G

Guest

It seems that a call to GetCommState never sets the fParity flag to TRUE. I
have sample code to address this problem:

#include <iostream>
#include <windows.h>
int main (int argc, char **argv)
{
HANDLE h;
DCB settings;
bool status;
h = CreateFile ("COM1", GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, 0, NULL);
status = GetCommState (h, &settings);
if (!status)
{
std::cout << "Failed call to GetCommState" << std::endl;
return(1);
}
settings.Parity = EVENPARITY;
settings.fParity = TRUE;
status = SetCommState (h, &settings);
if (!status)
{
std::cout << "Failed call to SetCommState" << std::endl;
return(1);
}
// Reset the parity to ensure it was correctly set
settings.Parity = NOPARITY;
settings.fParity = FALSE;
status = GetCommState (h, &settings);
if (!status)
{
std::cout << "Failed call to GetCommState" << std::endl;
return(1);
}
if (settings.Parity == EVENPARITY)
{
std::cout << "Successfully set parity" << std::endl;
}
else
{
std::cout << "FAIL: Didn't set parity" << std::endl;
}
if (settings.fParity)
{
std::cout << "Parity is checked" << std::endl;
}
else
{
std::cout << "FAIL: Parity is NOT checked" << std::endl;
}
return 0;
}

I don't know yet if parity is actually checked or not. I'll run a test
later. Nevertheless I think fPairy should be set after the call to
GetCommState.

The test code fails on four different PCs. On one of them I am using the
command line compiler 'cl' version 12.00.8168 (MS VC++ version 6.0). I have
Windows XP professional SP2 (not embedded, but I couldn't find a more
appropriate forum). The COM port is on a Intel(R) 82801GB LPC Interface
Controller - 27B8. The driver is from Microsoft, dated 7/1/2001 version
5.1.2600.0. The Windows driver update software says this driver is the latest.

Thanks for you help!
Brian
 
S

Stuart Langley

If you are trying to do any serious RS232 programming, I think you'll find
that you'll need something a bit better than the standard serial driver.
Have a look at COMM/NT which we reviewed for a project a while back and
worked well.

Regards,

Stuart
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top