Hi,

the Recvstring function with a timeout of 1 second should eliminate any
infinate loops using too much CPU. Perhaps try to comment out some functions
inside the loop until the culprit is found?

Regards,

W

On Tue, Sep 8, 2009 at 2:05 PM, lloyd thomas <[email protected]>wrote:

> Spoke too soon, Just realised I am getting horrendous CPU usage. This is
> what I have at the moment. Any Ideas? I suspect a problem with the loop.
> Think I need to put a sleep in somewhere but not sure where.
>
> procedure TServerSerial.Execute;
> begin
> {*************************************
> Get settings from database
> *************************************}
>      conn5 := TZConnection.Create(nil);
>      query5 := TZQuery.Create(nil);
>      query5.Connection := conn5;
>      try
>           try
>              conn5.Protocol := DBType;
>              conn5.HostName := '';
>              conn5.Database := DBName;
>              conn5.User := DBUser;
>              conn5.Password := DBPass;
>              conn5.Connect;
>              query5.SQL.Clear;
>              query5.SQL.Text := 'SELECT col_sys_id, col_site_id FROM
> sys_col WHERE col_active = 1 AND col_id = 1';
>              query5.Open;
>              query5.Last;
>                        sysType5 :=
> query5.FieldByName('col_sys_id').AsString;
>                        SiteID5 :=
> query5.FieldByName('col_site_id').AsString;
>
>              //query1.SQL.Clear;
>              query5.SQL.Text := 'SELECT * from sys_par where sys_id =
> '+sysType5;
>              query5.Open;
>              query5.Last;
>                        PhoneSysID5 :=
> query5.FieldByName('sys_id').AsString;
>                        RegExpStr5 :=
> query5.FieldByName('start_str').AsString;
>                        RegExpEnd5 :=
> query5.FieldByName('end_str').AsString;
>              query5.Close;
>              finally
>              query5.Free;
>              conn5.Free;
>              DataParse5 := TdataParse.Create(PhoneSysID5, SiteID5,
> RegExpStr5, RegExpEnd5);
>              DataParse5.Resume;
>          end;
>         except
>         on E: Exception do
>         Log(E.message);
>      end;
>
>
>    with Fser do
>     begin
>     RaiseExcept:=false;
>       if active = true then begin
>       Log('Serial Port used is '+PortNo);
>       Connect(PortNo);
>       Config(Baud,databits,parity,stopbits ,softwarefl,hardwarefl);
>         try
>         repeat
>         LCMD := Recvstring(1000);
>           if (LastError = 0) and (LCMD <> '') then //Data was received
> without any issues
>           begin
>           myconverterfunc5:=...@callconv5;
>           myconverterfunc5(LCMD);
>           end
>           else if LastError <> ErrTimeOut then //No data was received and
> it was not a timeout, so something else is wrong
>          break; //break and try to rebind and the continue with loop
>         until terminated;
>         except
>         on E: Exception do
>         log(E.message);  //write error
>         end;
>         if LastError<> 0 then log(GetErrorDesc(LastError));
>       end;
>     end;
> end;
>
>
>
> 2009/7/2 Werner Hauptfleisch <[email protected]>
>
>>  Good to hear!
>>
>> On Wed, Jul 1, 2009 at 11:24 PM, lloyd thomas 
>> <[email protected]>wrote:
>>
>>> Thanks Guys, your solution seems to have worked. left it a month and
>>> still going strong.
>>>
>>> Lloydie T
>>>
>>> 2009/5/27 lloyd thomas <[email protected]>
>>>
>>> Thanks Guys,
>>>>                     I will give the previous solution a go to see if
>>>> it resolves my problem. It will take a couple of days though to get a
>>>> definative answer though.
>>>>
>>>> Lloydie T
>>>>
>>>> 2009/5/27 Werner Hauptfleisch <[email protected]>:
>>>> > Hi,
>>>> >
>>>> > Please see original post to this thread by Lloyd Thomas on my 23rd
>>>> (source
>>>> > code located at http://pastebin.com/m5e3de129)
>>>> >
>>>> > This code can be reflected or altered in lines 223 onwards :). I do
>>>> not
>>>> > think it is necessary to exit the thread, but simply reconnect to the
>>>> port
>>>> > again (off course, the thread could be restarted if required...really
>>>> up to
>>>> > Lloyd to see if he can use it and solve his problem)
>>>> >
>>>> > Cheers!
>>>> >
>>>> > On Wed, May 27, 2009 at 4:26 PM, Markku Uttula <
>>>> [email protected]>
>>>> > wrote:
>>>> >>
>>>> >> Werner Hauptfleisch wrote:
>>>> >> > You are right - sorry sucked that out of my thumb as a quick
>>>> indication
>>>> >> > to a possible solution, maybe this will work:
>>>> >> >
>>>> >> > repeat
>>>> >> >      LCMD := Recvstring(1000);
>>>> >> >      if (LastError = 0) and (LCMD <> '') then //Data was received
>>>> >> > without any issues
>>>> >> >      begin
>>>> >> >          myconverterfunc1:=...@callconv1;
>>>> >> >          myconverterfunc1(LCMD);
>>>> >> >      end
>>>> >> >      else if LastError <> ErrTimeOut then //No data was received
>>>> and it
>>>> >> > was not a timeout, so something else is wrong
>>>> >> >          break; //break and try to rebind and the continue with
>>>> loop
>>>> >> > until terminated;
>>>> >>
>>>> >> Does "break" set the "terminated"? As I don't know what goes on
>>>> around
>>>> >> this loop (whether terminated is a local, global, or system provided
>>>> >> variable) I can't know :)
>>>> >>
>>>> >> If it does, quickly that looks like it could work. I need to say that
>>>> I
>>>> >> don't have Delphi here, so I'm only guessing - my comments are not
>>>> based
>>>> >> on any kind of testing on my behalf.
>>>> >>
>>>> >> --
>>>> >> Markku Uttula
>>>> >>
>>>> >>
>>>> >>
>>>> ------------------------------------------------------------------------------
>>>> >> Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
>>>> >> is a gathering of tech-side developers & brand creativity
>>>> professionals.
>>>> >> Meet
>>>> >> the minds behind Google Creative Lab, Visual Complexity, Processing,
>>>> &
>>>> >> iPhoneDevCamp as they present alongside digital heavyweights like
>>>> >> Barbarian
>>>> >> Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com
>>>> >> _______________________________________________
>>>> >> synalist-public mailing list
>>>> >> [email protected]
>>>> >> https://lists.sourceforge.net/lists/listinfo/synalist-public
>>>> >
>>>> >
>>>> >
>>>> ------------------------------------------------------------------------------
>>>> > Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
>>>> > is a gathering of tech-side developers & brand creativity
>>>> professionals.
>>>> > Meet
>>>> > the minds behind Google Creative Lab, Visual Complexity, Processing, &
>>>> > iPhoneDevCamp as they present alongside digital heavyweights like
>>>> Barbarian
>>>> > Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com
>>>> > _______________________________________________
>>>> > synalist-public mailing list
>>>> > [email protected]
>>>> > https://lists.sourceforge.net/lists/listinfo/synalist-public
>>>> >
>>>> >
>>>>
>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> synalist-public mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/synalist-public
>>>
>>>
>>
>>
>> ------------------------------------------------------------------------------
>>
>> _______________________________________________
>> synalist-public mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/synalist-public
>>
>>
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus
> on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> synalist-public mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/synalist-public
>
>
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
synalist-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synalist-public

Reply via email to