Article View: borland.public.cppbuilder.nativeapi
Article #14737Re: Serial port communication
From: ScOe
Date: Mon, 04 Aug 2003 11:07
Date: Mon, 04 Aug 2003 11:07
51 lines
2303 bytes
2303 bytes
"Vladimir Afanasyev" <avv@systema.kiev.ua> wrote in message
news:3f2e026e@newsgroups.borland.com...
>
> Hi,
>
> A lot wrong:
>
> 1)You did not set port parameters: speed, parity, stopbits...,
> for example:
> gszPort = "COM2:9600,N,8,1";
> 2)You also did not create DCB.
>
Ok, i have modifed my code. Now it looks like this, but still there is
something wrong
String gszPort;
gszPort = "COM1";
DWORD dwRead, dwWritten;
HANDLE hComm;
DCB dcb;
hComm = CreateFile( gszPort.c_str (),
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
if (hComm == INVALID_HANDLE_VALUE) {
return;
}
ZeroMemory(&dcb, sizeof(dcb));
dcb.DCBlength = sizeof (DCB);
GetCommState ( hComm, &dcb );
dcb.BaudRate = CBR_9600;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
if (!SetCommState ( hComm, &dcb)) {
return;
}
String szCommand = "AT^SMSO\r"; //Hayes code to turn off GSM device
if (!WriteFile( hComm, szCommand.c_str (), szCommand.Length (), &dwWritten,
NULL ))
WriteLog ("Error: "+String(GetLastError ()), 0);
CloseHandle (hComm);
i dont receive errors but nothing happend when executed
Technical Details
Message-ID:
<3f2e3f14@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3f2ce3e3@newsgroups.borland.com> <3f2e026e@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,96d3ffb2702fb4bb X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-08-04 04:40:08 PST From: "ScOe" <sven.savic@zg.hinet.hr> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f2ce3e3@newsgroups.borland.com> <3f2e026e@newsgroups.borland.com> Subject: Re: Serial port communication Date: Mon, 4 Aug 2003 13:07:47 +0200 Lines: 53 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2727.1300 NNTP-Posting-Host: 213.191.135.205 Message-ID: <3f2e3f14@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1059995412 213.191.135.205 (4 Aug 2003 04:10:12 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail