Re: Async Pro for serial communications
- From: "John Herbster" <herb-sci1_AT_sbcglobal.net>
- Date: Fri, 11 Jul 2008 10:26:25 -0500
"Godfrey" <none> wrote
I poll the pumps and depending on what pump I am addressing
in the loop, that pump responds. The pump will only respond
if it is addressed otherwise it just stays idle.
For either point-to-point or multi-drop, I would
prefer to use event driven reception of the chars
and with timeouts to detect lost packets.
I am looking for more detailed examples using triggers and
timeouts, do you have any?
Here is a sophisticated example:
_Inside-out programming for serial ports_
http://cc.codegear.com/Item/23954
Here below is the beginning of a simple example with a ComPort1
and a Timer1.
HTH, JohnH
Timer1 is not Enabled.
Define port state type maybe like this:
Type tPortState =
(psIdle, psXmitting, psWaitingResp, psReceiving);
procedure SetupAndStartTransmittingRequest:
If State <> psIdle then raise Error.
ClearReceiverBuffer;
Prep request string.
Set State to psXmitting; Start timer to wait for response in 200 milliseconds.
StartComportTransmission;
Exit;
end;
procedure Timer1.Timer();
Timer1.Enabled := false;
Case State of
psIdle: {nothing};
psXmitting: Log transmiting timeout;
psWaitingResp: Log no reception;
psReceiving:Log receiving timeout;
end;
end;
procedure Comport1.OnTransmitBufEmpty;
Set State to psWaitingResp; Start timer to wait for response in 300 milliseconds
end;
procedure Comport1.OnReceivedChars
For each received char:
Case State of
psXmitting, psWaitingResp:
If char signals beginning of message from pump
then State := psReceiving;
Set received buffer to first char.
psReceiving:
If char signals end of message from pump
then begin
Timer1.Enabled := false;
State := psIdle;
Process received message.
end
else accumulate char to received buffer.
end;
end;
.
- References:
- Async Pro for serial communications
- From: Godfrey
- Re: Async Pro for serial communications
- From: Charles Collins
- Re: Async Pro for serial communications
- From: Godfrey
- Re: Async Pro for serial communications
- From: John Herbster
- Re: Async Pro for serial communications
- From: Godfrey
- Async Pro for serial communications
- Prev by Date: Re: Async Pro for serial communications
- Next by Date: Re: Async Pro for serial communications
- Previous by thread: Re: Async Pro for serial communications
- Next by thread: Re: Async Pro for serial communications
- Index(es):
Relevant Pages
|