Questo blocco funzione 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.
Function block
CODESYS: Non disponibile
LogicLab: eLLabXUnified12Lib
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)
PROGRAM ST_SysGetPeerInfos VAR Pulse : BOOL; (* One shot *) i : UDINT; (* Auxiliary variable *) 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 i:=Sysmemmove(ADR(PeerIP), PeerInfos.PeerIP, SIZEOF(PeerIP)); //Peer IP PeerPort:=PeerInfos.PeerPort; //Peer port END_IF; END_IF; // [End of file]
Ultimo aggiornamento: 15 Settembre 2020