FB_TlsSocketConnect

The FB_TlsSocketConnect function block enables a client to establish a new TCP/IP connection to a remote server via the TwinCAT TCP/IP Connection Server, secured via TLS. If successful, a new socket is opened, and the associated connection handle is returned at the hSocket output. The connection handle is required by the function blocks FB_SocketSend and FB_SocketReceive, for example, in order to exchange data with a remote server. If a connection is no longer required, it can be closed with the function block FB_SocketClose. Several clients can establish a connection with the remote server at the same time. For each new client, a new socket is opened and a new connection handle is returned. The TwinCAT TCP/IP Connection Server automatically assigns a new IP port number for each client. The TLS parameters can be defined via the function blocks FB_TlsSocketAddCa, FB_TlsSocketAddCrl, FB_TlsSocketSetPsk and FB_TlsSocketSetCert. Programming samples for their use can be found in our samples.
Inputs
VAR_INPUT
sSrvNetId : T_AmsNetId:='';
sRemoteHost : STRING(TCPADS_TLS_HOSTNAME_SIZE):='';
nRemotePort : UDINT:=0;
flags : ST_TlsConnectFlags:=DEFAULT_TLSCONNECTFLAGS;
bExecute : BOOL;
tTimeout : TIME:=T#45s;(*!!!*)
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. |
sRemoteHost | STRING(TCPADS_TLS_HOSTNAME_SIZE) | IP address (Ipv4) of the remote server in the form of a string (e.g. 172.33.5.1). An empty string can be entered on the local computer for a server. |
nRemotePort | UDINT | IP port number of the remote server (e.g. 200). |
flags | Additional (optional) client connection parameters. | |
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. |
![]() | Setting the maximum execution time of the function block Do not set the value "tTimeout" too low, as timeout periods of > 30 s can occur in case of a network interruption. If the value is too low, command execution would be interrupted prematurely, and ADS error code 1861 (timeout elapsed) would be returned instead of the Winsocket error WSAETIMEDOUT. |
Inputs/outputs
VAR_IN_OUT
hSocket : T_HSOCKET;
END_VAR
Name | Type | Description |
---|---|---|
hSocket | T_HSOCKET | TCP/IP connection handle to the newly opened local client socket |
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 platform | PLC libraries to be integrated (category group) |
---|---|---|
TF6310 v3.3.15.0 or later TwinCAT v3.1.0 | PC or CX (x86, x64, Arm®) | Tc2_TcpIp (Communication) |