Article View: borland.public.cppbuilder.nativeapi
Article #10364Re: Serial comms and cotrolling the RTS line
From: Jim Dodd
Date: Tue, 20 Apr 2004 18:05
Date: Tue, 20 Apr 2004 18:05
72 lines
3016 bytes
3016 bytes
WaitCommEvent() should return with a non-zero result if all went well.
Did you check to see if WaitCommEvent() returned with an error code of
0? You can then call GetLastError() to see the reason for the failure.
Regards,
Jim Dodd
Onset Computer Corp.
JoeBlack wrote:
> Hi all,
>
> Using BCB 6 & WIN2K
>
> I have created my own com port class and have had no problems transmitting
> and recieving data via my serial ports, but now I want to control the RTS
> line as a direction control pin for RS485 data. After checking the
> documentation I found that I should be able to use the following:
>
> void __fastcall TCommPort::SendData(String dta)
> {
> if (dta.Length() == 0)
> return;
>
> DWORD NOBW;
> SetCommMask(hComm,EV_TXEMPTY);
>
> if (RS485)
> Set485(true);
>
> WriteFile(hComm,dta.c_str(),static_cast<DWORD>(dta.Length()),&NOBW,NULL);
>
> DWORD evt;
> while (evt != EV_TXEMPTY)
> {
> WaitCommEvent(hComm,&evt,0);
> }
>
> if (RS485)
> Set485(false);
> }
>
> void __fastcall TCommPort::Set485(bool b)
> {
> RTS = b;
>
> if (IsOpen)
> {
> if (b)
> EscapeCommFunction(hComm,SETRTS);
> else EscapeCommFunction(hComm,CLRRTS);
> }
> }
>
>
> In the SendData function I set a comm event to fire when the tx buffer is
> empty, I then place the data into the queue in the serial port, and the wait
> for the TX buffer empty event to occur, when this happens I place the RTS
> line low again.
>
> Unfortunately, the WaitCommEventFunction returns immediately and the RTS
> line is dropped straight away, does anyone know what I've done wrong, or how
> to control the RTS another way so that it drops after my data is sent.
>
> I cant use the fRtsControl from the DCB structure as it drops the line upto
> 10 ms after the data has been sent and is not fast enough.
>
> TIA
>
> Joe
>
>
Technical Details
Message-ID:
<4085666c$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!fr.ip.ndsoftware.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40853bbf@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,29200a53fdd311dc X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-04-20 11:10:23 PST Date: Tue, 20 Apr 2004 14:05:48 -0400 From: Jim Dodd <bcbuilderboy@yahoo.com> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) Gecko/20031007 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Serial comms and cotrolling the RTS line References: <40853bbf@newsgroups.borland.com> In-Reply-To: <40853bbf@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 65.161.163.42 Message-ID: <4085666c$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1082484332 65.161.163.42 (20 Apr 2004 11:05:32 -0700) Lines: 73 Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!fr.ip.ndsoftware.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail