FB_SocketSend

FB_SocketSend 1:

Using the function block FB_SocketSend, data can be sent to a remote client or remote server via the TwinCAT TCP/IP Connection Server. A remote client connection will first have to be established via the function block FB_SocketAccept, or a remote server connection via the function block FB_SocketConnect.

FB_SocketSend 2: Inputs

VAR_INPUT
    sSrvNetId  : T_AmsNetId := '';
    hSocket    : T_HSOCKET;
    cbLen      : UDINT;
    pSrc       : POINTER TO BYTE;
    bExecute   : BOOL;
    tTimeout   : TIME := T#5s;
END_VAR

Name

Type

Description

sSrvNetId

T_AmsNetId

String containing the network address of the TwinCAT TCP/IP Connection Server. For the local computer (default) an empty string may be specified.

hSocket

T_HSOCKET

Connection handle of the communication partner to which data are to be sent.

cbLen

UDINT

Number of date to be sent in bytes.

pSrc

POINTER TO BYTE

Address (pointer) of the send buffer.

bExecute

BOOL

The function block is activated by a positive edge at this input.

tTimeout

TIME 

Maximum time allowed for the execution of the function block.

FB_SocketSend 3:

Setting the execution time of the function block

If the transmit buffer of the socket is full, for example because the remote communication partner receives the transmitted data not quickly enough or large quantities of data are transmitted, the FB_SocketSend function block will return ADS timeout error 1861 after the tTimeout time. In this case, the value of the tTimeout input variable has to be increased accordingly.

FB_SocketSend 4: Outputs

VAR_OUTPUT
    bBusy     : BOOL;
    bError    : BOOL;
    nErrId    : UDINT;
END_VAR

Name

Type

Description

bBusy

BOOL

This output is active if the function block is activated. It remains active until acknowledgement.

bError

BOOL

If an error should occur during the transfer of the command, then this output is set once the bBusy output was reset.

nErrId

UDINT

If an bError output is set, this parameter returns the TwinCAT TCP/IP Connection Server error number.

Requirements

Development environment

Target system type

PLC libraries to include (category group)

TwinCAT v3.1.0

PC, or CX (x86, X64, ARM)

Tc2_TcpIp (communication)