Article View: borland.public.cppbuilder.nativeapi
Article #6222Re: Please help, Parity does Not Working Again........
From: Ramy
Date: Sat, 04 Jun 2005 11:21
Date: Sat, 04 Jun 2005 11:21
110 lines
3532 bytes
3532 bytes
>So...One of these:
>
>my_DCB.BaudRate = SystemInfo.ComInfo.BaudRate;
>my_DCB.ByteSize = 8;
>my_DCB.Parity = (char)SystemInfo.ComInfo.Parity;
> . . . etc . . .
>SetCommState
>
> - - Or - -
>
>BuildCommDCB( "COM1:9600,S,8,1", &my_DCB )
>my_DCB.fBinary = true;
>my_DCB.fParity = 1;
>(whatever else you need setting that BuildCommDCB didn't set for you )
>SetCommState
-- -- -- >
Sorry Bob but it's just NOT working. I opened a new project
just for a test, and this is it's full code -
//-------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//-------------------------------------------------------------
__fastcall TForm1::TForm1( TComponent *Owner ) : TForm( Owner )
{
}
//-------------------------------------------------------------
int InitCommunication( void )
{
char ComName[30] = "COM1";
HANDLE ComHndl = NULL;
DCB my_DCB;
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.BaudRate = 19200;
my_DCB.fBinary = true;
my_DCB.ByteSize = 8;
my_DCB.fBinary = true;
my_DCB.fParity = 1;
my_DCB.Parity = MARKPARITY;
my_DCB.StopBits = 1;
if ( !BuildCommDCB( "COM1:19200, M, 8, 1", &my_DCB ) )
return 0;
if ( !SetCommState( ComHndl, &my_DCB ) )
return 0;
if ( GetCommState( ComHndl, &my_DCB ) )
{
int k = 0;
k = k;
}
return 1;
}
//-------------------------------------------------------------
void __fastcall TForm1::FormActivate( TObject *Sender )
{
InitCommunication();
}
//-------------------------------------------------------------
As it is, it's works and return '1' ( = PASS ), BUT if i try
to do what you told me, that is to remove the lines -
if ( !BuildCommDCB( "COM1:19200, M, 8, 1", &my_DCB ) )
return 0;
from the code OR to put them right above the line -
my_DCB.DCBlength = sizeof( my_DCB );
then the SetCommState() function FAILS !!
Also, if i try to put the line -
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 ?
Thanks Very Much,
Ramy.
Technical Details
Message-ID:
<42a18eb9$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.superfeed.net!caladan.landsraad.net!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>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,499887f6c1e08a34 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Ramy" <Ramy@NoMail.com> Sender: "Ramy" <Ramy@NoMail.com> Reply-To: "Ramy" <Ramy@NoMail.com> Subject: Re: Please help, Parity does Not Working Again........ Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 85.250.51.75 References: <429ddcd0$1@newsgroups.borland.com> <hlrr9117ici0n26ua1vmn2odmbri4mornt@4ax.com> <429ebbbf$1@newsgroups.borland.com> <429ebe00$1@newsgroups.borland.com> <gmdu911tosvsi52h9nhjg5s59406ea2q50@4ax.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <42a18eb9$1@newsgroups.borland.com> Date: 4 Jun 2005 04:21:29 -0700 X-Trace: newsgroups.borland.com 1117884089 207.105.83.66 (4 Jun 2005 04:21:29 -0700) Lines: 112 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.superfeed.net!caladan.landsraad.net!newsgroups.borland.com!not-for-mail