Re: Need advice from Apro Users



use datapackets
and define what you expect
then you'll receive an event when that datapacket has arrived
so no more getting the bytes yourselves
and it is way faster also...
cu
marc

"edbored" <edwardbNONO@xxxxxxxxxxxx> wrote in message news:45b9beeb$1@xxxxxxxxxxxxxxxxxxxxxxxxx
I'm using D7 Ent and Apro 4.06.

I'm controlling (monitoring) a serial device - basically punch out 20 chars
that define a request for data from any of a bunch of registers within the
serial device.

I can sent the 20 chars out to device very easily, but I have to wait for a
20 char return string before sending a data request again.

If I do something like:

procedure InfiniteMonitorLoop;
var
ItWorked: boolean;
begin
ItWorked:=true;
while ItWorked do begin
ItWorked := Send20CharsToApdComPort;

if ItWorked then
ItWorked:=WaitFor20CharsWithTimeout(aString, 36);

if ItWorked then
DoSomethingWith(aString);
end;

function WaitFor20CharsWithTimeout(var aString: string, TicksTO: integer):
boolean;
var
ET : EventTimer;
finished: Boolean;
begin
result:=false;
aString:='';
NewTimer(ET, TicksTO);
finished:=false;
repeat
if ApdComPort1.CharReady then begin
aString := sSting + ApdComPort1.GetChar;
if length(aString)=20 then begin
finished:=True;
Result:=True;
end;
end;
if not finished then
finished:=TimerExpired(ET);
// application.processmessages;
until finished;
end;


In the above, the only time this actually works is if
"application.processmessages" is NOT
commented out.

If it IS commented, I get timeouts, sometimes get data - very weird.

Can anyone suggest a way for me to send data and wait (blocking) with a
timeout?

Many thanks.

EdB



.