Discussion:
handling data outside of STX-ETX
(too old to reply)
ChickenCoder
2008-06-06 13:30:31 UTC
Permalink
For the last two years I have been using the following thread to receive
data. It has served me well. I am now in a situation where I have to
accept ACKs, NAKs, and EOTs. I am lost as to how to modify my code to do
this. I can't have multiple WaitFor's.
Can someone point me in the right direction?

Thanks


procedure TReadingInfinitiThread.Execute;
begin
while not Terminated do
begin
// read data
FConn.IOHandler.WaitFor(chr(2));
Buffer := FConn.IOHandler.ReadLn(chr(3));
If Not(Terminated) then
Begin
ProcessData
End;
end;
end;
Remy Lebeau (TeamB)
2008-06-06 16:38:18 UTC
Permalink
Post by ChickenCoder
For the last two years I have been using the following thread
to receive data. It has served me well. I am now in a situation
where I have to accept ACKs, NAKs, and EOTs. I am lost as
to how to modify my code to do this.
You will not be able to use WaitFor() anymore for what you are asking. You
will have to use ReadChar() or ReadByte() instead, ie:

procedure TReadingInfinitiThread.Execute;
begin
while not Terminated do
begin

case FConn.IOHandler.ReadByte of
$02: // STX
begin
Buffer := FConn.IOHandler.ReadLn(Chr(3));
If not Terminated then ProcessData;
end;

$04: // EOT
begin
// do something...
end;

$06: // ACK
begin
// do something...
end;

$15: // NAK
begin
// do something...
end;

else
begin
// unknown character, do something...
end;
end;
end;
end;


Gambit
ChickenCoder
2008-06-06 17:07:57 UTC
Permalink
Thanks Remy.

You are the greatest!!
Post by Remy Lebeau (TeamB)
Post by ChickenCoder
For the last two years I have been using the following thread
to receive data. It has served me well. I am now in a situation
where I have to accept ACKs, NAKs, and EOTs. I am lost as
to how to modify my code to do this.
You will not be able to use WaitFor() anymore for what you are asking.
procedure TReadingInfinitiThread.Execute;
begin
while not Terminated do
begin
case FConn.IOHandler.ReadByte of
$02: // STX
begin
Buffer := FConn.IOHandler.ReadLn(Chr(3));
If not Terminated then ProcessData;
end;
$04: // EOT
begin
// do something...
end;
$06: // ACK
begin
// do something...
end;
$15: // NAK
begin
// do something...
end;
else
begin
// unknown character, do something...
end;
end;
end;
end;
Gambit
Loading...