FB_SocketUdpSendTo

FB_SocketUdpSendTo 1:

The function block FB_SocketUdpSendTo can be used to send UDP data to a remote device via the TwinCAT TCP/IP Connection Server. The UDP socket must first be opened with the function block FB_SocketUdpCreate.

FB_SocketUdpSendTo 2: Inputs

VAR_INPUT
    sSrvNetId   : T_AmsNetId := '';
    hSocket     : T_HSOCKET;
    sRemoteHost : T_IPv4Addr;
    nRemotePort : UDINT;
    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

Handle of an opened UDP socket.

sRemoteHost

T_IPv4Addr

IP address (Ipv4) in string form (e.g. '172.33.5.1') of the remote device to which data is to be sent. An empty string can be entered on the local computer for a device.

nRemotePort

UDINT

IP port number (e.g. 200) of the remote device to which data is to be sent.

cbLen

UDINT

Number of date to be sent in bytes. The maximum number of data bytes to be sent is limited to 8192 bytes (constant TCPADS_MAXUDP_BUFFSIZE in the library in order to save storage space).

pSrc

POINTER TO BYTE

Address (pointer) of the send buffer.

bExecute

BOOL

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

tTimeout

TIME

Maximum time allowed for the execution of the function block.

FB_SocketUdpSendTo 3:

Setting the size of the received data bytes

Available in product version: TwinCAT TCP/IP Connection Server v1.0.50 or higher: The maximum number of data bytes to be received can be increased (only if absolutely necessary).

TwinCAT 2

  1. Redefine global constant in the PLC project (in the sample the maximum number of data bytes to be received is to be increased to 32000):
    VAR_GLOBAL CONSTANT
        TCPADS_MAXUDP_BUFFSIZE : UDINT := 32000;
    END_VAR
  2. Activate option Replace constants in the dialog of the TwinCAT PLC control (Project > Options ... > Build).
  3. Rebuild Project.

TwinCAT 3

In TwinCAT 3, this value can be edited via a parameter list of the PLC library (from version 3.3.4.0).

FB_SocketUdpSendTo 4:

FB_SocketUdpSendTo 5: 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)