Questo blocco funzione da eseguire in task Back, ritorna le informazioni della connessione. Passando in File al blocco funzione un file di tipo TCP o UDP è possibile avere in uscita le informazioni relative.
Sostituisce SysGetIpInfos
Sostituisce il blocco funzione SysGetIpInfos modificando il tipo di parametri in ingresso da stringa a puntatore a stringa. La precedente dichiarazione:
VAR PeerInfos : SysGetIpInfos; (* Peer infos *) END_VAR PeerInfos(File:=Fp); PeerIP:=PeerInfos.PeerIP; PeerPort:=PeerInfos.PeerPort;
Diventa:
VAR PeerInfos : SysGetPeerInfos; (* Peer infos *) END_VAR PeerInfos(File:=Fp); i:=Sysmemmove(ADR(PeerIP), PeerInfos.PeerIP, SIZEOF(PeerIP)); PeerPort:=PeerInfos.PeerPort;
Descrizione
File (FILEP) File pointer, deve essere di tipo TCP o UDP.
PeerIP (@STRING) Stringa di definizione indirizzo IP del peer connesso al file.
PeerPort UINT) Porta del peer connesso al file

Esempi
Come utilizzare gli esempi.
Nell’esempio è attivato un server TCP in ascolto sulla porta 4000, è accettata un’unica connessione. Quando un client si connette viene ritornato l’indirizzo IP e la porta del client che si è connesso.
LogicLab (Ptp116, ST_SysGetPeerInfos)
PROGRAM ST_SysGetPeerInfos
VAR
Pulse : BOOL; (* One shot *)
Fp : eFILEP; (* File pointer array *)
PeerPort : UINT; (* Peer port *)
PeerIP : STRING[ 16 ]; (* Peer IP *)
TCPServer : SysTCPServer; (* TCPServer management *)
PeerInfos : SysGetPeerInfos; (* Peer infos *)
END_VAR
// *****************************************************************************
// PROGRAM "ST_SysGetPeerInfos"
// *****************************************************************************
// A TCP server is instantiated on port 4000 when client connects the client
// informations are returned.
// -----------------------------------------------------------------------------
// -------------------------------------------------------------------------
// INITIALIZATION
// -------------------------------------------------------------------------
// First program execution loop initializations.
IF (SysFirstLoop) THEN
TCPServer.FilesArr:=ADR(Fp); //Files array
TCPServer.LocalAdd:=ADR('0.0.0.0'); //Local address
TCPServer.LocalPort:=4000; //Local port
TCPServer.MaxConn:=1; //Accepted connections
TCPServer.FlushTm:=50; //Flush time (mS)
TCPServer.LifeTm:=30; //Life time (S)
TCPServer.RxSize:=128; //Rx buffer size
TCPServer.TxSize:=128; //Tx buffer size
END_IF;
// Manage the TCP server.
TCPServer(Enable:=TRUE); //TCPServer management
// -------------------------------------------------------------------------
// READ PEER INFOS
// -------------------------------------------------------------------------
// On a new connection reads the peer infos.
IF (Pulse <> SysFIsOpen(Fp)) THEN
Pulse:=SysFIsOpen(Fp); //One shot
IF (Pulse) THEN
PeerInfos(File:=Fp); //Get peer infos
eTO_JUNK(Sysmemmove(ADR(PeerIP), PeerInfos.PeerIP, SIZEOF(PeerIP))); //Peer IP
PeerPort:=PeerInfos.PeerPort; //Peer port
END_IF;
END_IF;
// [End of file]