Article View: borland.public.cppbuilder.nativeapi
Article #4511Re: Serial comm problem
From: Marc Bertens
Date: Thu, 19 Jan 2006 15:36
Date: Thu, 19 Jan 2006 15:36
117 lines
4372 bytes
4372 bytes
Hi Bogdan,
I use the following code, and it words just fine, this took me several times
to perfect......
dcbCommPort.DCBlength = sizeof( DCB );
if ( !GetCommState( hCommHandle, &dcbCommPort ) )
{
CloseHandle( hCommHandle );
return ( FALSE );
}
dcbCommPort.fParity = TRUE;
dcbCommPort.fBinary = TRUE;
dcbCommPort.fDtrControl = DTR_CONTROL_DISABLE; // Hardware flow
control
dcbCommPort.fRtsControl = DTR_CONTROL_DISABLE;
dcbCommPort.fInX = FALSE; // NO software flow control
dcbCommPort.fOutX = FALSE;
dcbCommPort.fAbortOnError = 0;
dcbCommPort.XonChar = 11;
dcbCommPort.XoffChar = 13;
dcbCommPort.ErrorChar = 0;
dcbCommPort.EofChar = 0;
dcbCommPort.EvtChar = 0;
// other various settings
dcbCommPort.fOutxCtsFlow = FALSE; // CTS output flow control
dcbCommPort.fOutxDsrFlow = FALSE; // DSR output flow control
dcbCommPort.fDsrSensitivity = FALSE; // DSR sensitivity
dcbCommPort.BaudRate = ulSpeed;
dcbCommPort.ByteSize = bData;
switch ( bStop )
{
case 2:
dcbCommPort.StopBits = TWOSTOPBITS;
break;
case 1:
dcbCommPort.StopBits = ONESTOPBIT;
break;
}
switch ( bParity )
{
case SERIAL_PARITY_NO:
dcbCommPort.Parity = NOPARITY;
dcbCommPort.fParity = FALSE;
break;
case SERIAL_PARITY_EVEN:
dcbCommPort.Parity = EVENPARITY;
dcbCommPort.fParity = TRUE;
break;
case SERIAL_PARITY_ODD:
dcbCommPort.Parity = ODDPARITY;
dcbCommPort.fParity = TRUE;
break;
case SERIAL_PARITY_MARK:
dcbCommPort.Parity = MARKPARITY;
dcbCommPort.fParity = TRUE;
break;
}
if ( !SetCommState( hCommHandle, &dcbCommPort ) )
{
CloseHandle( hCommHandle );
return ( FALSE );
}
Hopefully you solve your problem with it.
Regards,
Marc Bertens
"Bogdan" <boprea@xnet.ro> schreef in bericht
news:43c15835$1@newsgroups.borland.com...
> Hello,
>
> I'm trying to communicate between 2 PCs using a serial cable(null modem).
> I've written a dll where I export the functions I need to initialize,
> read/write and
> shutdown a serial port.The problem is that I only tested it on a single
PC,
> by
> connecting a cable between the 2 COM ports.When i tried the app between 2
> different PC-s it didn' t work anymore.
> I suspect I do something wrong with the DCB structure used to set up the
> port, but
> i don't know what.This is the code used to init the DCB :
>
> ZeroMemory(&PortDCB,sizeof(DCB));
> PortDCB.DCBlength = sizeof(DCB);
>
> GetCommState(COMPort,&PortDCB);
>
> PortDCB.fOutxCtsFlow = FALSE;
> PortDCB.fOutxDsrFlow = FALSE;
> PortDCB.fDtrControl = DTR_CONTROL_DISABLE;
> PortDCB.fRtsControl = RTS_CONTROL_DISABLE;
> PortDCB.fOutX = TRUE;//FALSE;
> PortDCB.fInX = TRUE;//FALSE;
> //PortDCB.fDsrSensitivity = FALSE;
> //PortDCB.fTXContinueOnXoff = TRUE;
> //PortDCB.fErrorChar = FALSE;
> //PortDCB.fNull = FALSE;
> //PortDCB.fAbortOnError = FALSE;
>
> PortDCB.BaudRate = Speed;
> PortDCB.fBinary = TRUE;
> PortDCB.fParity = TRUE;
> PortDCB.ByteSize = 8;
> PortDCB.Parity = NOPARITY;
> PortDCB.StopBits = ONESTOPBIT;
>
> Bogdan
>
>
Technical Details
Message-ID:
<43cfb09c$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<43c15835$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,b5848264f1b0dfff X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Marc Bertens" <m.bertens@etl-systems.nl> Newsgroups: borland.public.cppbuilder.nativeapi References: <43c15835$1@newsgroups.borland.com> Subject: Re: Serial comm problem Date: Thu, 19 Jan 2006 16:36:07 +0100 Lines: 119 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1506 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 NNTP-Posting-Host: 80.127.0.91 Message-ID: <43cfb09c$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1137684636 80.127.0.91 (19 Jan 2006 07:30:36 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail