Article View: borland.public.cppbuilder.nativeapi
Article #10361Serial comms and cotrolling the RTS line
From: JoeBlack
Date: Tue, 20 Apr 2004 15:03
Date: Tue, 20 Apr 2004 15:03
60 lines
2388 bytes
2388 bytes
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:
<40853bbf@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,29200a53fdd311dc,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-04-20 08:10:39 PST From: "JoeBlack" <no.one@no.where> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Serial comms and cotrolling the RTS line Date: Tue, 20 Apr 2004 16:03:26 +0100 Lines: 62 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 80.177.44.179 Message-ID: <40853bbf@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1082473407 80.177.44.179 (20 Apr 2004 08:03:27 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail