FB_S7CommConnection

FB_S7CommConnection 1:

With the function block FB_S7CommConnection, a TCP/IP based connection to a Siemens S7 Controller can be established. It is possible to tell whether the connection was successfully established via the output bIsConnected. Errors concerning setting up the connection are displayed via the output bError and sErrorTxt.

Syntax

Definition:

VAR_INPUT
    bExecute     : BOOL;
    sIpAddr      : STRING(15);
    eCpuType     : E_S7COMM_CPUTYPE;
    nRack        : UINT;
    nSlot        : UINT;
END_VAR
VAR_OUTPUT
    bError       : BOOL;
    sErrorTxt    : STRING;
    bBusy        : BOOL;
    bIsConnected : BOOL;
END_VAR

FB_S7CommConnection 2: Inputs

Name

Data type

Description

bExecute

BOOL

The connection to the S7 Controller is set up in case of a rising edge. The connection is disconnected in case of a falling edge.

sIpAddr

STRING(15)

IP address of the Siemens S7 Controller.

eCpuType

E_S7COMM_CPUTYPE

Type of Siemens S7 Controller

nRack

UINT

Rack ID of the S7 Controller. This can be obtained from the S7 device manager.

nSlot

UINT

Slot ID of the S7 Controller. This can be obtained from the S7 device manager.

FB_S7CommConnection 3: Outputs

Name

Data type

Description

bError

BOOL

Switches to TRUE if an error occurs during execution.

sErrorTxt

STRING

Contains the error text in the event of an error.

bBusy

BOOL

TRUE until the function block has executed a command. As long as bBusy = TRUE, the function block will not accept any new commands.

bIsConnected

BOOL

TRUE, if the connection to the Siemens S7 Controller was established.

FB_S7CommConnection 4: Methods

Name

Definition location

Description

AddRequest

Local

Adds a Single or CyclicRequest to the connection.

Requirements

Development environment

Target platform

PLC libraries to be integrated (category group)

TwinCAT v3.1.0

PC or CX (x86, x64)

Tc3_S7Comm (Communication)