Overview

Not all those function blocks and functions that are often needed in PLC applications are standardized in IEC61131-3. The 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.

Function blocks

ADS function blocks

Name

Description

ADSREAD

Reading data via ADS.

ADSWRITE

Writing data via ADS.

ADSRDWRT

Reading and writing data via ADS.

ADSRDSTATE

Read the state of a device via ADS.

ADSWRTCTL

Write control words to a device via ADS.                                   

ADSRDDEVINFO

Read device information via ADS.

ADSREADEX

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

ADSRDWRTEX

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

Extended ADS function blocks

Name

Description

ADSREADIND

ADSREAD-Indication.

ADSWRITEIND

ADSWRITE-Indication

ADSRDWRTIND

ADSRDWRT-Indication

ADSREADRES

ADSREAD-Response

ADSWRITERES

ADSWRITE-Response

ADSRDWRTRES

ADSRDWRT-Response

General function blocks

Name

Description

DRAND

Random number generator.

GETCURTASKINDEX

Determines the index of the current task.

Time function blocks

Name

Description

GETSYSTEMTIME

Read the operating system time stamp.

GETTASKTIME

Read the target start time of the task.

GETCPUCOUNTER

Read the CPU cycle counter.

GETCPUACCOUNT

Read the PLC task cycle counter.

Watchdog function blocks

Name

Description

FB_PcWatchdog

Activate or Deactivate the PC Watchdog.
Is only available on IPCs with the mainboards: IP-4GVI63, CB1050, CB2050, CB3050, CB1051, CB2051, CB3051 !

F unction 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_FileOpen

Open a file.

FB_FileClose

Close a file.

FB_FileWrite

Write to a file.

FB_FileRead

Read from a file.

FB_FileSeek

Move the file pointer.

FB_FileTell

Get the file pointer position.

FB_FilePuts

Put string to a file.

FB_FileGets

Get string from a file.

FB_EOF

Check the end of file.

FB_FileDelete

Delete a file.

FB_FileRename

Rename a file.

FB_CreateDir

Create new directory.

FB_RemoveDir

Remove directory.

TwinCAT 2.7 function blocks for data  access

These function blocks are contained only for compatibility reasons in the library and should not not be used in new projects.

Name

Description

FILEOPEN

Open a file.

FILECLOSE

Close a file.

FILEWRITE

Write to a file.

FILEREAD

Read from a file.

FILESEEK

Move the file pointer.

IEC SFC functions

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

Name

Description

SFCActionControl

Enables the using of IEC steps.

AnalyzeExpression
AnalyzeExpressionCombined

Is required for using SFC flags.

AppendErrorString

Is required for using SFC flags, to format strings with error description.

Event logger function blocks

The TwinCAT Eventlogger manages all occurring messages (events) in the TwinCAT System. It transfers the data and writes them into the TwinCAT log file.

Name

Description

ADSLOGEVENT

Sending and acknowledgement of messages to the TwinCAT Eventlogger.

ADSCLEAREVENTS

Sending and acknowledgement of messages to the TwinCAT Eventlogger.

 

For further information see the TwinCAT Event Logger documentation.

Functions

General functions

Name

Description

F_SplitPathName

Splits a path name into components.

F_CreateIPv4Addr

Converts address bytes to IPv4 address string.

F_ScanIPv4AddrIds

Converts IPv4 address string to address bytes..

SETBIT32

Sets a bit in a DWORD.

CSETBIT32

Sets/resets a bit in a DWORD.

GETBIT32

Reads a bit from a DWORD.

CLEARBIT32

Clears a bit in a DWORD.

LPTSIGNAL

Outputs a signal on one of the parallel port pins.

F_GetStructMemberAlignment

Reads data struct member alignment information.

F_GetVersionTcSystem

Returns the library version info

I/O port access

Name

Description

F_IOPortRead

Reads from I/O Port

F_IOPortWrite

Writes to I/O Port

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

MEMORY functions

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

Comment

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

MEMSET

Sets the variables in a memory area to a particular value

MEMMOVE

Copies the values from overlapping memory areas

 

Character functions

Name

Description

F_ToASC

Converts string character to ASCII number

F_ToCHR

Converts ASCII number to string character