F_CreateServerHnd

F_CreateServerHnd 1:

The function F_CreateServerHnd is used to initialize/set the internal parameters of a server handle variable hServer. The server handle is then transferred to the instances of the function block FB_ServerClientConnection via VAR_IN_OUT. An instance of the FB_ServerClientConnection function block can be used to manage (establish or remove) a sever connection in a straightforward manner. The same server handle can be transferred to several instances of the function block FB_ServerClientConnection, in order to enable the server to establish several concurrent connections.

Syntax

FUNCTION F_CreateServerHnd : BOOL
VAR_IN_OUT
    hServer         : T_HSERVER; 
END_VAR
VAR_INPUT
    sSrvNetID       : T_AmsNetID := ''; 
    sLocalHost      : STRING(15) := ''; 
    nLocalPort      : UDINT := 0;
    nMode           : DWORD := LISTEN_MODE_CLOSEALL (* OR CONNECT_MODE_ENABLEDBG*);
 bEnable            : BOOL := TRUE;
END_VAR

F_CreateServerHnd 2: Return value

Name

Type

Description

F_CreateServerHnd

BOOL

Returns TRUE if everything is OK, FALSE if there is an incorrect parameter value.

F_CreateServerHnd 3: Inputs

Name

Type

Description

sSrvNetID

T_AmsNetID

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

sLocalHost

T_IPv4Addr

Local server IP address (Ipv4) in the form of a string (e.g. '172.13.15.2'). For a server on the local computer (default), an empty string may be entered.

nLocalPort

UDINT

Local server IP port (e.g. 200).

nMode

DWORD

Parameter flags (modes). The permissible parameters are listed here and can be combined by ORing.

LISTEN_MODE_CLOSEALL:

All previously opened socket connections are closed (default).

CONNECT_MODE_ENABLEDBG:

Enables logging of debug messages in the application log. In order to view the debug messages open the TwinCAT System Manager and activate log view.

bEnable

BOOL

This input determines the behavior of the listener socket. A listener socket opened beforehand remains open as long as this input is TRUE. If this input is FALSE, the listener socket is closed automatically, but only once the last (previously) accepted connection was also closed.

F_CreateServerHnd 4:/F_CreateServerHnd 5: Inputs/outputs

Name

Type

Description

hServer

T_HSERVER

Server handle variable whose internal parameters are to be initialized.

Example:

See FB_ServerClientConnection.

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)