FB_SocketUdpSendTo
Available in the product version: TwinCAT TCP/IP Connection Server v1,0,0,31 or higher
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.
VAR_INPUT
VAR_INPUT
sSrvNetId : T_AmsNetId := '';
hSocket : T_HSOCKET;
sRemoteHost : STRING(15);
nRemotePort : UDINT;
cbLen : UDINT;
pSrc : DWORD;
bExecute : BOOL;
tTimeout : TIME := T#5s;
END_VAR
sSrvNetId: string containing the network address of the TwinCAT TCP/IP Connection Server. For the local computer (default) an empty string may be specified.
hSocket: the handle of an opened UDP socket.
sRemoteHost: IP address (Ipv4) of the remote device to which data are to be sent as a string (e.g. '172.33.5.1'). An empty string can be entered for a device on the local computer.
nRemotePort: IP port number of the remote device to which data are to be sent (e.g. 200).
cbLen: number of data to be sent in bytes. The maximum number of data bytes to be sent is limited to 8192 bytes by default (by declaring the TCPADS_MAXUDP_BUFFSIZE constant in the library to conserve memory resources).
pSrc: address (pointer) of the transmit buffer.
bExecute: the function block is enabled via a positive edge at this input.
tTimeout: maximum time that may not be exceeded when the function block is executed.
From product version: TwinCAT TCP/IP Connection Server v1.0.50 and higher, the maximum number of data bytes to be sent can be increased (if absolutely necessary). |
1) In the PLC project, redefine the global constant (in our sample we want to increase the maximum number of data bytes to 32000 bytes):
VAR_GLOBAL CONSTANT
TCPADS_MAXUDP_BUFFSIZE : UDINT :=32000;
END_VAR
2) Then activate the option "Replace constants" in TwinCAT PLC Control->"Project->Options...->Build" dialog box.
3) Compile the project.
VAR_OUTPUT
VAR_OUTPUT
bBusy : BOOL;
bError : BOOL;
nErrId : UDINT;
END_VAR
bBusy: When the function block is activated this output is set. It remains set until and acknowledgement is received.
bError: If an error should occur during the transfer of the command, then this output is set once the bBusy output was reset.
nErrId : If the bError output is set, this parameter returns the TwinCAT TCP/IP Connection Server error number.
Requirements
Development environment | Target system type | PLC libraries to be linked |
---|---|---|
TwinCAT version 2.8.0 or higher | PC or CX (x86) | TcpIp.Lib (v1.0.4 or higher) ( Standard.Lib; TcBase.Lib; TcSystem.Lib are included automatically ) |
TwinCAT v2.10.0 Build >= 1301 | CX (ARM) |