Function BlockTcpSendPLCopen motion icon

Description

This function block sends characters over a socket. It is possible that the number of characters actually sent is less than the number expected. In that case, you will need to use TcpSend again to send the pending characters.


  • It is possible that the socket becomes invalid if an error occurs in the TCP connection after this function block is called. You must use the TcpIsValid function block after TcpSend. If the socket is no longer valid then you must close it by using the TcpClose function block.

Figure 7-224: The TcpSend function block

Related Functions

TcpAccept, TcpBinReceive, TcpBinSend, TcpClose, TcpConnect, TcpIsConnected, TcpIsValid, TcpListen, TcpReceive

Arguments

Input

Execute Description On the rising edgeClosedA rising edge is the transition of a digital signal from low to high. It is also called positive edge send a string over a socket connection.
  Data Type BOOL
  Range 0, 1
  Unit N/A
  Default
ID Description The ID of the client socket.
  Data Type UDINT
  Range N/A
  Unit N/A
  Default
NbChar Description The number of characters to send.
  Data Type DINT
  Range N/A
  Unit N/A
  Default
Data Description The IP Address of the remote server.
  Data Type STRING
  Range N/A
  Unit N/A
  Default

Output

Done Description If TRUE, then the command completed successfully
  Data Type BOOL
Error Description If TRUE, an error has occurred
  Data Type BOOL
ErrorID Description Indicates the error if Error output is set to TRUE. See the table in Search IndexFile and TCP/IP Function Block ErrorID Output
  Data Type DINT
NbSent Description The number of characters actually sent.
  Data Type DINT

Example

Structured Text

(* TcpSend example *)
CASE StepCounter OF
0:
  Inst_TcpSend(TRUE, MySocketID, 5, 'Hello');
  StepCounter := StepCounter + 1;
1:
  Inst_TcpSend(TRUE, MySocketID, 5, 'Hello');
  IF Inst_TcpSend.Done THEN
     BytesSent := Inst_TcpSend.NbSent;
     Inst_TcpSend(FALSE, 0, 0, '');
     StepCounter := StepCounter + 1;
  END_IF;
END_CASE;