Article View: borland.public.cppbuilder.deployment
Article #160THREAD with SERIAL COMM
From: Anon
Date: Thu, 08 Sep 2005 15:43
Date: Thu, 08 Sep 2005 15:43
52 lines
2206 bytes
2206 bytes
Hi to all.
I have to realize a small app that receive data through a serial port.
My idea is to build a Thread and poll the serial port for data.
I have realized this solution but the thread use all resource and when
thread start my up is blocked (combo, buttons, etc).
This is a portion of the code (objSerial is a object from the Synaser
class that I used for serial comm):
void __fastcall thrSerialReader::Execute()
{
SetName();
FreeOnTerminate = false;
//---- Place thread code here ----
if (objSerial != NULL)
{
while ((!this->Terminated) && (objSerial->InstanceActive))
{
if (this->CanReceive) Synchronize(ReceiveData);
}
}
Terminate();
}
void __fastcall thrSerialReader::ReceiveData()
{
Byte chRead;
do
{
chRead = objSerial->RecvByte(5);
if (chRead > 0) this->strRecvMessage = this->strRecvMessage +
AnsiString((char)chRead);
}
while ((objSerial->LastError == 0) && (chRead != END_MESSAGE));
// If no data is present objSerial->LastError is != 0
if ((objSerial->LastError == 0) && (chRead > 0))
// No error and data present
{
...here the code to manage the data received
}
}
Any suggestions ? I'm are newer to the thread programming.
Some links to get documentation about threads in c++ builder ?
Thanks.
Fabio.
Technical Details
Message-ID:
<43205bc7@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!cyclone.bc.net!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.superfeed.net!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: f8e54,5fc7742ce46e9625,start X-Google-Attributes: gidf8e54,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Thu, 08 Sep 2005 17:43:00 +0200 From: \"@t <""fabio(\"@t)techside.it"> User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.deployment Subject: THREAD with SERIAL COMM Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 82.56.190.253 Message-ID: <43205bc7@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1126194119 82.56.190.253 (8 Sep 2005 08:41:59 -0700) Lines: 52 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!cyclone.bc.net!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.superfeed.net!caladan.landsraad.net!newsgroups.borland.com!not-for-mail