Article View: borland.public.cppbuilder.nativeapi
Article #14719Re: Serial port communication
From: Vladimir Afanasyev
Date: Mon, 04 Aug 2003 06:51
Date: Mon, 04 Aug 2003 06:51
53 lines
2427 bytes
2427 bytes
Hi,
"ScOe" <sven.savic@zg.hinet.hr> wrote:
>I've saw specifications for my mobile phone, and there is bunch of AT
>commands that response to.
>I'm trying to send them to mobile phone like this:
>
>String gszPort;
>gszPort = "COM2";
>HANDLE hComm;
>hComm = CreateFile( gszPort.c_str (),
> GENERIC_READ | GENERIC_WRITE,
> 0,
> 0,
> OPEN_EXISTING,
> FILE_FLAG_OVERLAPPED,
> 0);
>if (hComm == INVALID_HANDLE_VALUE) {
> ShowMessage ("Gre�ka: INVALID_HANDLE_VALUE");
> return;
> }
>DWORD dwToWrite;
>if (WriteABuffer ("AT^SMSO", 10, hComm) == FALSE)
> ShowMessage ("Gre�ka prilikom slanja");
>
>CloseHandle (hComm);
>
>BOOL TForm1::WriteABuffer(char * lpBuf, DWORD dwToWrite, HANDLE hComm)
>{
>....
> if (!WriteFile(hComm, lpBuf, dwToWrite, &dwWritten, &osWrite)) {
> if (GetLastError() != ERROR_IO_PENDING) {
> fRes = FALSE;
> }
> }
>
>what am i doing wrong ?
>
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.
See my TPortControl in codecentral, serial com samples on
www.bcbdev.com,
and make search "Jonathan Arnold Serial Communications" on
http://www.tamaracka.com/search.htm.
Vladimir.
Technical Details
Message-ID:
<3f2e026e@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<3f2ce3e3@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 10cc67,96d3ffb2702fb4bb X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-08-04 00:00:10 PST From: "Vladimir Afanasyev" <avv@systema.kiev.ua> Sender: "Vladimir Afanasyev" <avv@systema.kiev.ua> Reply-To: "Vladimir Afanasyev" <avv@systema.kiev.ua> Subject: Re: Serial port communication Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 212.82.216.226 212.82.216.226 X-Forwarded-For: 192.168.0.147 References: <3f2ce3e3@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.65 Message-ID: <3f2e026e@newsgroups.borland.com> Date: 3 Aug 2003 23:51:26 -0700 X-Trace: newsgroups.borland.com 1059979886 207.105.83.65 (3 Aug 2003 23:51:26 -0700) Lines: 53 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail