S7-SoftPLC:Configuration TwinCAT I/O

From IBHsoftec Wiki English
Revision as of 07:53, 17 January 2013 by Jonas (Talk | contribs)

Jump to: navigation, search

The driver allows to exchange I/O data with S7-SoftPLC via the Beckhoff TwinCAT I/O driver. With the TwinCAT I/O driver every I/O component supported by Beckhoff can be accessed, so that this driver is independent from the used fieldbus.

To access the Beckhoff peripheral components with S7-SoftPLC, the TwinCAT I/O driver from Beckhoff has to be installed and licensed on the computer. The I/O tasks, that are supposed to be used with S7-SoftPLC, must be configured with the Beckhoff TwinCAT System Manager. The TwinCatIO.dll maps the process images to the Beckhoff I/O components. Acyclic accesses via peripheral commands are as well possible as the acyclic access with a SFC/FC.

In order to use the driver, the following steps are necessary:

  • Inserting a station in TwinCAT System Manager
  • Creating a task in TwinCAT System Manager
  • Accessing ADS-functions from the PLC-program

Inserting a station in TwinCAT System Manager

TwinCAT d1.png

With a right-click on I/O Devices >> Scan Devices... a dialogue appears in which an I/O component can be selected (if it is available in the net).

TwinCAT d2.png

After having selected the desired device, TwinCAT System Manager asks, whether to scan for new boxes.

TwinCAT d3.png

If agreed, all available I/O components will be scanned. The I/O components are now known to the TwinCAT I/O and can be accessed.

Creating a task in the TwinCAT System Manager

TwinCAT d4.png

With a right-click on Additional Tasks >> Append Task... a new task is created. The task represents the S7-SoftPLCs process images.


Important task settings

Port: The port with the number 301 normally serves as process image for S7-SoftPLC. It is also accessible via a SFC/FC.

AutoStart: S7-SoftPLC triggers the fieldbus and thus informs the TwinCAT driver, that it is still operational. The option AutoStart normally must not be chosen.

If this option is selected, the TwinCAT I/O driver has to be configured in such a way, that it can independently detect, whether the PLC is still operational, in order to switch the outputs of the I/O components into a defined state, if necessary.


Configuring a task

To be able to access the I/O components, the I/O points have to be linked with the task. With a right-click on Inputs or Outputs >> Insert Variable... the I/O points can be assigned to the task.

TwinCAT d5.png

Depending on the available I/O point an adequate type of variable has to be selected.

TwinCAT d6.png

If the variable is declared, it has to be linked with the I/O component. For this activate the button Linked to...to create a link between the variable and the I/O-point.

TwinCAT d7.png

TwinCAT d8.png

If the set of variables is linked with the task, the configuration has to be activated. Thereafter the TwinCAT I/O-task is ready for use, as soon as it is switched into Run-Mode.

Calling special functions and ADS functions from the PLC-program

SFC 14

Via the SFC "DPRD_DAT" inputs can be read out of the TwinCAT I/O task

CALL SFC/FC 14
LADDR  := W#16#100 //INPUT WORD
RET_VAL  := MW 0 //RESULT INT
RECORD  := P#M 100.0 BYTE 1 //OUTPUT ANY

Parameter Type of Data Description
LADDR WORD Start address of inputs to be read
RET_VAL INT 0 on success
RECORD ANY ANY-Pointer to readout data


SFC 15

Via the SFC "DPWR_DAT" outputs can be written into the TwinCAT I/O task

CALL SFC/FC 15
LADDR  := W#16#100 //INPUT WORD
RECORD  := P#M 102.0 BYTE 1 //INPUT ANY
RET_VAL  := MW 0 //RESULT INT

Parameter Type of Data Description
LADDR WORD Start address of outputs to be read
RECORD ANY ANY-Pointer on data to be written
RET_VAL INT 0 on success


ControlSFC

Via the SFC "DPWR_DAT" outputs can be written into the TwinCAT I/O task

CALL SFC/FC 1000
IN0  := FALSE //INPUT BOOL
IN1  := 301 //INPUT INT
IN2  := P#M 104.0 BYTE 1 //RESULT ANY
RET_VAL  := MW 0 //RESULT INT

Parameter Type of Data Description
IN0 BOOL false = Read data from any TwinCAT I/O task

true = Write data into any TwinCAT I/O task

IN1 INT Port number of the I/O-task
IN2 ANY ANY-Pointer to data to be read/written with adequate length (ANY-pointer of type byte are permitted only)
RET_VAL INT 0 = success, otherwise the returned values of the TwinCAT I/O driver are transparently passed through.

0x0057= ERROR_INVALID_PARAMETER - one of the passed parameters is invalid


GetDeviceIdentification

The SFB "GETDEVID" allows it to read out the device identification data

CALL SFC/FC 1001, DB 1001
EXEC  := M0.0 //INPUT BOOL
TMOUT  := TIME#0D_0H_0M_1S_0MS //INPUT TIME
BUSY  := M 0.1 //OUTPUT BOOL
ERR  := M 0.2 //OUTPUT BOOL
ERRID  := MD 4 //OUTPUT DWORD
DEVID  := P#M 10.0 BYTE 214 //IN_OUT ANY

Parameter Type of Data Description
IN0 BOOL TRUE starts the command
IN1 TIME Not used, because underlying ADS function timeout is used
OUT2 BOOL The data are read from the device. After error-free execution, the data is ready when BUSY = FALSE.
OUT3 BOOL Becomes TRUE, as soon as an error occurs
OUT4 DWORD Delivers the error number if ERR is set
IO5 ANY ST_CxDeviceIdentification (length 214 Byte)


AdsRead

The SFB "ADSREAD" allows the execution of an ADS-reading command, to request data from an ADS-device.

CALL SFC/FC 1002, DB 1002
NETID  := #stringvar //INPUT STRING
PORT  := W#16#0 //INPUT WORD
IDXGRP  := DW#16#0 //INPUT DWORD
IDXOFFS  := DW#16#0 //INPUT DWORD
LEN  := DW#16#0 //INPUT DWORD
DESTADDR  := P#M 10 BYTE 1 //INPUT ANY
READ  := M 0.0 //INPUT BOOL
TMOUT  := TIME#0D_0H_0M_1S_0MS //INPUT TIME
BUSY  := M 0.1 //OUTPUT BOOL
ERR  := M 0.2 //OUTPUT BOOL
ERRID  := MD 4 //OUTPUT DWORD


Parameter Type of Data Description
NETID STRING It is a string providing the AMS network identification of the target device, the ADS-command targets.
PORT WORD Contains the port number of the ADS-service
IDXGRP DWORD Contains the index group number (32bit, unsigned) of the requested ADS-service. This value can be extracted from the ADS-chart of the addressed device.
IDXOFFS DWORD Contains the index offset number (32bit, unsigned) of the requested ADS-service. This value can be extracted from the ADS-chart of the addressed device.
LEN DWORD Contains the number of data to be read in bytes.
DESTADDR ANY Pointer to the destination buffer. The buffer needs to be big enough to record LEN bytes. The buffer can be a single variable, an array or a structure.
READ BOOL On TRUE ADS-command is executed
TMOUT TIME Timeout
BUSY BOOL This output is TRUE as long as a ADS command is executed. Reset by timeout or success. While showing BUSY=TRUE, no new command is accepted.
ERR BOOL This output is TRUE, if an error has occurred during the execution of an ADS command. The command-specific error code is contained in "ERRID". If a timeout has occured, "ERR" = TRUE and "ERRID" = 1861 (hexadecimal 0x745). A new command resets "ERR".
ERRID DWORD Contains the command-specific error code of the command executed last. A new command resets "ERRID"


AdsWrite

The SFB "ADSWRITE" allows the execution of an ADS-writing command, to transmit data to an ADS-device.

CALL SFC/FC 1003, DB 1003
NETID  := #stringvar //INPUT STRING
PORT  := W#16#0 //INPUT WORD
IDXGRP  := DW#16#0 //INPUT DWORD
IDXOFFS  := DW#16#0 //INPUT DWORD
LEN  := DW#16#0 //INPUT DWORD
SRCADDR  := P#M 10.0 BYTE 1 //INPUT ANY
WRITE  := M 0.0 //INPUT BOOL
TMOUT  := TIME#0D_0H_0M_1S_0MS //INPUT TIME
BUSY  := M 0.1 //OUTPUT BOOL
ERR  := M 0.2 //OUTPUT BOOL
ERRID  := MD 4 //OUTPUT DWORD

Parameter Type of Data Description
NETID STRING It is a string providing the AMS network identification of the target device, the ADS-command targets.
PORT WORD Contains the port number of the ADS-service
IDXGRP DWORD Contains the index group number (32bit, unsigned) of the requested ADS-service. This value can be extracted from the ADS-chart of the addressed device.
IDXOFFS DWORD Contains the index group number (32bit, unsigned) of the requested ADS-service. This value can be extracted from the ADS-chart of the addressed device.
LEN DWORD Contains the number of data to be written in bytes.
SRCADDR ANY Pointer to the source buffer. The buffer needs to be big enough to hold LEN bytes. The buffer can be a single variable, an array or a structure.
WRITE BOOL On TRUE ADS-command is executed
TMOUT TIME Timeout
BUSY BOOL This output is TRUE as long as a ADS command is executed. Reset by timeout or success. While BUSY=TRUE, no new command is accepted.
ERR BOOL This output is TRUE, if an error has occurred during the execution of an ADS command. The command-specific error code is contained in "ERRID". If a timeout has occured, "ERR" = TRUE and "ERRID" = 1861 (hexadecimal 0x745). A new command resets "ERR".
ERRID DWORD Contains the command-specific error code of the command executed last. A new command resets "ERRID"