procedure TForm1.UDPSUDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
var u,v,orgip,h:shortstring;
i,j,k:integer;
orgport:word;
p:TMyMsg;
begin
v:=RD.readMsg(AData,orgip,orgport); // contains AData.Read(buffer,size);
i:=NewOrgEntry(orgip,orgport); // get/make client handle
p:=TMyMsg.create(length(v)); // repack for COMMThread
p.asstring:=v;
p.origin:=i;
MsgQueue.queuein(p); // Queue for COMMThread
..
end;
procedure TForm1.spTriggerAvail(CP: TObject; Count: Word);
var i:integer;
db:byte;
j:integer;
p:OrgEntryPtr;
begin
for i:=1 to count do begin
db:=ord(sp.Getchar);
case CommThread.RxState of
0:begin // wait for ..
//.. skip state machine..
end; //0
1:begin //wait for ..
//.. skip state machine..
end; //1
2:begin // get len
//.. skip state machine..
end;
3:begin // count down
//.. skip state machine..
if RxLen=RxPtr then begin
// ..crc right here ..
CommThread.RxString[0]:=chr(RxLen);
j:=CommThread.PacketOrigin;
p:=OrgEntryPtr(OrgList[j]);
RD.serverip:=p.ip;
RD.serverport:=p.port;
RD.InitClient; // set IP and Port the packet is being sent to
RD.writeMsg(CommThread.RxString);
CommThread.RxCame:=true; // .. statemachine stuff ..
end;// len reached
end;
end; //case
end; //for count
end;
Send packets to the RS485 Server or to the Comport
procedure TForm1.MakeMsg(u:shortstring);
var h:shortstring;
crc:word;
p:TMyMsg;
begin
h:=someheader+u;
CalcCRC(h);
txstring:=someheader+h;
if UseMultiSrv.Checked then begin // through ther RS485Server
Rd.writeMsg(txstring); // add IP and port plus UDP.send(string)
end
else begin
p:=TMyMsg.create(length(txstring)); // Queue for the local COMMThread
p.asstring:=txstring;
p.delay:=100;
MsgQueue.queuein(p);
end;
end;
here the data comes back from the RS485Server
procedure TForm1.UDPSUDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
var s:shortstring;
orgip:shortstring;
orgport:word;
begin
s:=RD.readMsg(AData,orgip,orgport); // contains AData.Read(buffer,size); strip IP & port header
CommThread.RxString:=s;
ProcessRx; // same as from Serialport
end;
Delphi
home
last updated: 12.april.04, or perhaps later
Copyright (99,2004) Ing.Büro R.Tschaggelar