Article View: borland.public.cppbuilder.nativeapi
Article #6226Re: Please help, Parity does Not Working Again........
From: Bob Gonder
Date: Sat, 04 Jun 2005 17:31
Date: Sat, 04 Jun 2005 17:31
77 lines
3275 bytes
3275 bytes
Ramy wrote:
>int InitCommunication( void )
>{
> char ComName[30] = "COM1";
> HANDLE ComHndl = NULL;
> DCB my_DCB;
DCB my_DCB = {sizeof(DCB),0};
> ComHndl = CreateFile( ComName, GENERIC_WRITE + GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
>
> if ( ComHndl == INVALID_HANDLE_VALUE )
> return 0;
>
> my_DCB.DCBlength = sizeof( my_DCB );
// my_DCB.DCBlength = sizeof( my_DCB ); set in declaration
move this here:
> if ( !BuildCommDCB( "COM1:19200, M, 8, 1", &my_DCB ) )
> return 0;
Stop the program here in the debugger and inspect my_DCB
See which fields have been set and which have not.
Don't set again the fields that have been properly set.
Set any fields that don't have the proper settings.
> my_DCB.BaudRate = 19200;
// my_DCB.BaudRate = 19200; set by build
> my_DCB.fBinary = true;
> my_DCB.ByteSize = 8;
// my_DCB.ByteSize = 8; set by build
> my_DCB.fBinary = true;
// my_DCB.fBinary = true; you already did that
> my_DCB.fParity = 1;
> my_DCB.Parity = MARKPARITY;
// my_DCB.Parity = MARKPARITY; should have been set by build
> my_DCB.StopBits = 1;
// my_DCB.StopBits = 1; set by build
>
> if ( !SetCommState( ComHndl, &my_DCB ) )
> return 0;
Stop the program here and see if my_DCB has changed.
> if ( GetCommState( ComHndl, &my_DCB ) )
You are saying that here it has changed.
Try GetCommMask() and see if EV_ERR is set.
DWORD mask;
GetCommMask( ComHndl, &mask );
if( EV_ERR == ( mask & EV_ERR ) )
{ printf( "Parity Errors Enabled");
}else{ printf( "Parity Errors Disabled");
};
Maybe fParity reflects the state of the handler.
> return 1;
>}
>then the SetCommState() function FAILS !!
What is the value of GetLastError when if fails?
>my_DCB.fParity = 1;
>
>right above the SetCommState() function, then if i check it's
>value after the sucess call for GetCommState() i see that it's
>value is '0' AGAIN !
>
>How can it be? WHAT am i doing wrong here ?
Does it really matter?
It is supposed to indicate whether or not parity errors are reported
to you.
Technical Details
Message-ID:
<29n3a15oqdll7ma4t0jorm8og5nfqu3ttt@4ax.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<429ddcd0$1@newsgroups.borland.com> <hlrr9117ici0n26ua1vmn2odmbri4mornt@4ax.com> <429ebbbf$1@newsgroups.borland.com> <429ebe00$1@newsgroups.borland.com> <gmdu911tosvsi52h9nhjg5s59406ea2q50@4ax.com> <42a18eb9$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,499887f6c1e08a34 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: Bob Gonder <notbg@notmindspring.invalid> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Please help, Parity does Not Working Again........ Date: Sat, 04 Jun 2005 10:31:06 -0700 Organization: MindSpring Enterprises, Inc. Reply-To: notbg@notmindspring.invalid Message-ID: <29n3a15oqdll7ma4t0jorm8og5nfqu3ttt@4ax.com> References: <429ddcd0$1@newsgroups.borland.com> <hlrr9117ici0n26ua1vmn2odmbri4mornt@4ax.com> <429ebbbf$1@newsgroups.borland.com> <429ebe00$1@newsgroups.borland.com> <gmdu911tosvsi52h9nhjg5s59406ea2q50@4ax.com> <42a18eb9$1@newsgroups.borland.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 67.77.36.213 X-Trace: newsgroups.borland.com 1117906264 67.77.36.213 (4 Jun 2005 10:31:04 -0700) Lines: 80 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail