To: Andreas Kanthak
From: Paul Breneman
Newsgroup: turbocontrol.apro.general
 
04-Mar-2005

Re: Error with TApdWinsockPort

Andreas,

> yes, i am using loops to process incoming data. Just like
> 
> 
> FCom.Putblock()
> repeat
>   application.processmessages;
> until Allreceived or timeout;
> 
> What can I do then, to get it work correctly?

I would just like to make a few comments about using a loop in your 
application.  When I first started using AsyncPro I put a lot of similar 
loops into my applications.  It is the natural way to handle things but 
it is not the Windows event-oriented way.  I'd like to give you two 
alternatives to consider.

If your program is simple then you could use a state variable inside of the events where data is received (data packets or OnTriggerAvail) and also timeout events. But in my experience if the protocol or sequence of commands is complex then the code ends up being very hard to maintain and understand.
With most of the applications I've written, I want the application to be unresponsive (at least in prevention of further device commands) while I'm communicating with the external device. To me this is similar to an email program where I do "Get Mail" and I either wait for that process to complete or else I need to do "Stop".
The ExBlock and ExThread examples on this page demonstrate my basic approach:    http://www.turbocontrol.com/APro.htm
In my experience writing blocking function calls as those examples demonstrate has several advantages: 1) In the main application you just have the blocking function calls in sequence. It is very easy to see your control loops and error recovery steps. 2) It is easy to isolate the communication engine in separate units so it can be reused in other programs. 3) A single blocking function call can be extended to handle retries and other error recovery in the engine itself, so the main application does not need to be concerned.
When I need the application to be responsive while continuous communication is occurring, I'll usually add another "script" thread, and my blocking function calls will be made from that thread.
-- Regards, Paul Breneman http://www.TurboControl.com http://www.turbocontrol.com/TPSupport.htm - TurboPower support links
 
Originally created by
Tamarack Associates
Thu, 28 Mar 2024 09:55:24 UTC
Copyright © 2009-2024
HREF Tools Corp.