Overview

Not all those function blocks and functions that are often needed in PLC applications are standardized in IEC61131-3. The Tc2_System library contains such functions and function blocks for the TwinCAT system which do not belong to the standard scope of IEC61131-3, and which are therefore manufacturer-specific.

General function blocks

Name

Description

DRAND

Random number generator

FB_IecCriticalSection

Critical sections should be made mutually exclusive

FB_SetLedColor_BAPI

Switches the user LED to PCs and Émbedded PCs with BIOS API support

GETCURTASKINDEX

Determines the index of the current task

ADS function blocks

Name

Description

ADSREAD

Reading data via ADS

ADSREADEX

Reading data via ADS and returning the number of read data bytes

ADSWRITE

Writing data via ADS

ADSRDWRT

Reading and writing data via ADS

ADSRDWRTEX

Writing data via ADS and returning the number of read data bytes

ADSRDSTATE

Read the state of a device via ADS

ADSWRTCTL

Write control words to a device via ADS

ADSRDDEVINFO

Read device information via ADS

Expanded ADS function blocks

Name

Description

ADSREADIND

ADSREAD Indication

ADSWRITEIND

ADSWRITE Indication

ADSRDWRTIND

ADSRDWRT Indication

ADSREADRES

ADSREAD Response

ADSWRITERES

ADSWRITE Response

ADSRDWRTRES

ADSRDWRT Response

Function blocks for data access

The function blocks can be used to process files from the PLC locally on the PC. The TwinCAT target system is identified by the AMS network address. This mechanism makes it possible, amongst other things, to store or to edit files on other TwinCAT systems in the network. Access to files consists of three sequential phases:

  1. Opening the file.
  2. Read or write access to the opened file.
  3. Closing the file.

Opening the file has the purpose of establishing a temporary connection between the external file, whose name is all that initially is known, and the running program. Closing the file has the purpose of indicating the end of the processing and placing it in a defined output state for processing by other programs.

Name

Description

FB_EOF

Check the end of file

FB_FileOpen

Open a file

FB_FileClose

Close a file

FB_FileGets

Get string from a file

FB_FilePuts

Put string to a file

FB_FileRead

Read from a file

FB_FileWrite

Write to a file

FB_FileSeek

Move the file pointer

FB_FileTell

Get the file pointer position

FB_FileDelete

Delete a file

FB_FileRename

Rename a file

FB_CreateDir

Create new directory

FB_RemoveDir

Remove directory

EventLogger function blocks

The TwinCAT EventLogger has the task of managing all messages (events) appearing in the TwinCAT system; to forward them and where necessary to write them into the TwinCAT log file.

Name

Description

ADSLOGEVENT

Sending and acknowledging TwinCAT EventLogger messages.

ADSCLEAREVENTS

Sending and acknowledging TwinCAT EventLogger messages.

FB_SimpleAdsLogEvent

Sending and acknowledging TwinCAT EventLogger messages.

Overview 1:

TwinCAT EventLogger vs. TwinCAT 3 EventLogger

The TwinCAT EventLogger was replaced by the successor TwinCAT 3 EventLogger. The older TwinCAT EventLogger is supported by TwinCAT 3 up to version 3.1.4024. Newer TwinCAT versions (>= 3.1.4026.0) only support the newer TwinCAT 3 EventLogger. PLC function blocks for this can be found in the PLC library Tc3_EventLogger.

IEC steps / SFC flags function blocks

These functions / function blocks are required if IEC steps or SFC flags are used in SFC programs/projects.

Name

Description

AnalyzeExpression

Required if SFC flags are used

AnalyzeEspressionTable

Required if SFC flags are used

AnalyzeExpressionCombined

Required if SFC flags are used

AppendErrorString

Required if SFC flags are used in order to format strings with error description

SFCActionControl

Enables the use of IEC steps

Watchdog function blocks

Name

Description

FB_PcWatchdog

Activates or deactivates the PC watchdog

Only available on IPCs with the following mainboards: IP-4GVI63, CB1050, CB2050, CB3050, CB1051, CB2051, CB3051

FB_PcWatchdog_BAPI

Activates or deactivates the PC watchdog

Only available on IPCs with the following mainboards: CBxx63 with a BIOS version >=0.44

Time function blocks

Name

Description

GETCPUCOUNTER

Read the CPU cycle counter

GETCPUACCOUNT

Read the PLC task cycle counter

General functions

Name

Description

F_CheckMemoryArea

Returns information about the memory area in which the requested variable with the specified size is located

F_CmpLibVersion

Compares an existing library with the required version

F_CreateIPv4Addr

Converts individual IPv4 address bytes to a string

F_ScanIPv4AddrIds

Converts an IPv4 address string to individual address bytes

F_GetMappingPartner

Returns the object ID of the partner side of the mapping

F_GetMappingStatus

Returns the current mapping status of a PLC variable

F_GetStructMemberAlignment

Reads information about the memory alignment used

F_SplitPathName

Splits the path name into four individual components

SETBIT32

Sets a bit in a DWORD

CSETBIT32

Setting/resetting of a bit in a DWORD

GETBIT32

Reads a bit from a DWORD

CLEARBIT32

Clears a bit in a DWORD

GETCURTASTINDEXEX

Determining the task index

LPTSIGNAL

Outputs a signal on one of the parallel port pins

TestAndSet

Setting and checking a flag without option to interrupt it

ADS functions

Functions are described below which, with the aid of the ADS interface makes some of the functions of the Windows-NT operating system (such as the output of message boxes) accessible through PLC calls.

Name

Description

ADSLOGDINT

Log a DINT variable into NT Eventlog and/or Messagebox

ADSLOGLREAL

Log a (L)REAL variable into NT Eventlog and/or Messagebox

ADSLOGSTR

Log a STRING variable into NT Eventlog and/or Messagebox

F_CreateAmsNetId

Creates AmsNetId string

F_ScanAmsNetIds

Converts AmsNetId string to array of address bytes

Character functions

Name

Description

F_ToASC

Converts string character to ASCII number

F_ToCHR

Converts ASCII number to string character

I/O port access

Name

Description

F_IOPortRead

Reads from I/O Port

F_IOPortWrite

Writes to I/O Port

Memory functions

Number of functions, which provide direct access to memory areas in the PLC runtime system.

Notice

System crash or access to forbidden memory areas

The fact that these functions allow direct access to the physical memory means that special care is called for in applying them! Incorrect parameter values can result in a system crash, or in access to forbidden memory areas.

Name

Description

MEMCMP

Compares the values of variables in two memory areas

MEMCPY

Copies the values of variables from one memory area to another

MEMMOVE

Copies the values from overlapping memory areas

MEMSET

Sets the variables in a memory area to a particular value

Time functions

Name

Description

F_GetSystemTime

Read the operating system time stamp

F_GetTaskTime

Read the target start time of the task