TcpSend

PLCopen motion icon

 Function Block - Sends characters over a socket.

Inputs

Input

Data Type

Range

Unit

Default

Description

Execute

BOOL

0 to 1

N/A

No default

On the rising edge, send a string over a socket connection.

ID

UDINT

N/A

N/A

No default

The ID of the client socket.

NbChar

DINT

N/A

N/A

No default

The number of characters to send.

Data

STRING

N/A

N/A

No default

The IP Address of the remote server.

Outputs

Output

Data Type

Range

Unit

Description

Done

BOOL

 

 

If TRUE, the command completed successfully.

Error

BOOL

 

 

If TRUE, an error has occurred.

ErrorID

DINT

 

 

Indicates the error if Error output is TRUE.

See the table in File and TCP/IP Function Block ErrorIDs.

NbSent

DINT

 

 

The number of characters actually sent.

Remarks


  • It is possible that the socket becomes invalid if an error occurs in the TCP connection after this function block is called.
    Use the TcpIsValid function block after TcpSend.
    If the socket is no longer valid, close it using the TcpClose function block.
  • It is possible the number of characters actually sent is less than the number expected.
    • In this case, use this function again to send the pending characters.

Figure 1: TcpSend

FBD Language Example

Not available.

FFLD Language Example

Not available.

IL Language Example

Not available.

ST Language Example

(* 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;

See Also