Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread OT: How to idle properly
Mon, Nov 20 2006 7:26 PMPermanent Link

Jim Margarit
I'm sending a command to a device over rs232 and waiting for the reply.
If I do...

while length(replyString) < fixedReplyLen do
  application.processMessages;

It uses up 90% of the cpu cycles.

How should I be doing this to reduce the load?

Thanks,

Jim Margarit
Mon, Nov 20 2006 7:34 PMPermanent Link

"Adam H."
Hi Jim,

> I'm sending a command to a device over rs232 and waiting for the reply.
> If I do...
>
> while length(replyString) < fixedReplyLen do
>   application.processMessages;
>
> It uses up 90% of the cpu cycles.

Not tested - but by placing a sleep command in the application - it should
slow down the processing. ie:

while length(replyString) < fixedReplyLen do
begin
 application.processMessages;
 sleep(30);
end;

Best Regards

Adam.

Mon, Nov 20 2006 8:24 PMPermanent Link

"Malcolm"
Jim

I guess you are not using a serial comms component as it
would provide you with the methods and events to do this
without 'freezing' the system.

If you are doing more than trivial communications I suggest
you look at a component.  There are several around,
including free ones.

I think the general idea is that you fire off your command,
set a timeout (TTimer or built-in property) then forget it.

Your component will fire an event when the full reply is
received (assuming you can define this, STX/EOT) and if it
proves to be a valid reply you stop the timer and process
the message.

If the timer fires you do whatever you need to do - like
retries and error messages.

Malcolm
Tue, Nov 21 2006 4:30 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Jim


I'll go with Malcolm - and recommend Synapse

Roy Lambert
Tue, Nov 21 2006 10:03 AMPermanent Link

Jim Margarit
Hi,

Seems like I tried sleep the first time around with the same results but
it has been a while. I'll try it again and see since it's such a simple
replacement. Thanks

Jim

> Hi Jim,
>
>> I'm sending a command to a device over rs232 and waiting for the reply.
>> If I do...
>>
>> while length(replyString) < fixedReplyLen do
>>   application.processMessages;
>>
>> It uses up 90% of the cpu cycles.
>
> Not tested - but by placing a sleep command in the application - it should
> slow down the processing. ie:
>
> while length(replyString) < fixedReplyLen do
>  begin
>   application.processMessages;
>   sleep(30);
>  end;
>
> Best Regards
>
> Adam.
>
>
Image