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 FB_ServerClientConnection function block 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 FB_ServerClientConnection function block, in order to enable the server to establish several concurrent connections.

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

hServer: Server handle variable whose internal parameters are to be initialised.

sSrvNetID: 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: Local server IP address (Ipv4) as a string (e.g., '172.13.15.2'). For a server on the local computer (default), an empty string may be entered.

nLocalPort: Local server IP port (e.g., 200).

nMode: parameter flags (modes). The permissible parameters are listed in the table and can be combined via an OR operation:

Flag

Description

LISTEN_MODE_CLOSEALL

All previously opened socket connections are closed (default).

CONNECT_MODE_ENABLEDBG

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

bEnable: This input determines the behavior of the listener socket. Once opened, a listener socket remains open until this input becomes TRUE. If this input is FALSE, the listener socket is closed automatically, but only once the last (previously) accepted connection was also closed.

Return value

Description

TRUE

No error

FALSE

Error, invalid parameter value

Example:

See in the FB_ServerClientConnection function block description.

Requirements

Development Environment

Target System

PLC libraries to include

TwinCAT v2.9.0 Build >= 1030

PC or CX (x86)

TcSocketHelper.Lib

( Standard.Lib; TcBase.Lib; TcSystem.Lib; TcUtilities.Lib; TcpIp.Lib are included automatically )

TwinCAT v2.10.0 Build >= 1301

CX (ARM)