S7-SoftPLC:Basic configuration

From IBHsoftec Wiki English
Jump to: navigation, search

The basic configuration features of the CIF-cards are set here.

If no PROFIBUS® is used, the configuration has to be executed with the System Configurator SyCon of the Hilscher company.

How the driver is integrated into S7-SoftPLC is part of these instructions:

Using Status and Control SFC

Querying CIF-status

To query the CIF-status the status SFC has to be called cyclically (e.g. from the OB 1). The SFC contains the following parameters:

Name Sort Type Function
HostFlags OUT BYTE HostFlags
DevFlags OUT BYTE DevFlags

CALL SFC 252
OUT0  :=MB10 // HostFlags
OUT1  :=MB11 // DeviceFlags

The HostFlags and DeviceFlags are described exactly in the section Control-SFC function 141 and function 142, as well as in the Hilscher document tke.pdf on page 8.


Control-SFC

The Control SFC is used to execute special functions of the CIF-card. The control block is called in the following way:

L #Value
T MD 20
CALL SFC 210
IN0  := 142 // INPUT Function number.
IN1  := 0 // INPUT Data block number (on DB operationen, else 0).
IO2  := MD 20 // IN_OUT Parameter of function / Result.
OUT3  := MW 24 // OUTPUT Default 80xx Error codes, 0 on success.

When succeeded, the BR bit is set as well.


Control-SFC functions overview

Function number Function description
102 Set number of digital in/outputs
108 Set number of analog in/outputs
125 Read process inputs
126 Write process outputs
130 Read global diagnostic bits
131 Read bus status
132 Read incorrect bus address
133 Read error number
134 Read status bits
135 Read diagnostic bits
136 Read dual-port memory
137 Write dual-port memory
140 Trigger watchdog
141 Read HostFlags
142 Read DevFlags
150 Call DevGetTaskState and provide result in DB
151 Call DevGetInfo and provide result in DB
152 Call DevGetTaskParameter and provide result in DB


Function 102 Set number of digital in/outputs

With this function the number of the digital in/outputs can be set. 512 byte digital in/outputs are preset in S7-SoftPLC. With this function the number of digital in/outputs can be reduced. That causes an acceleration of S7-SoftPLC. If the function was not executed successfully, the BR is not set. The return value contains the standard 80xx error codes.


Error code:

0x8222 = size to big


Example:

L 50 // 50 digital I/Os necessary only
T MD 20 // set number of digital I/Os
CALL SFC 210
IN0  := 102 // function 102
IN1  := 0 // no DB
IO2  := MD 20 // size
OUT3  := MW 24 // error code


Function 108 Set number of analog in/outputs

With this function the number of the analogue in/outputs can be set. The maximum size of the dualport RAM, found during the initialization of the card, is preset in S7-SoftPLC. With this function the number of analog in/outputs can be reduced to the required number. It is counted from byte 0 of the dualport. If the function was not executed successfully, the BR is not set. The return value contains the standard 80xx error codes.


Fehlercode:

0x8222 = Size to big


Example:

L 100 // 100 analog I/Os necessary only
T MD 20 // set number of analog I/Os
CALL SFC 210
IN0  := 108 // function 108
IN1  := 0 // no DB
IO2  := MD 20 // size
OUT3  := MW 24 // error code


Function 125 Read process inputs

With this function the process inputs can be read into a data block. Herewith every available peripheral byte can be accessed. The function writes asynchronous. With word oriented inputs no data consistence exists and the function can only be used with byte oriented inputs.If the function was not executed successfully, the BR is not set. The return value contains the standard 80xx error codes.


Error codes:

0x813A = data block not available

0x8222 = size of data block bigger than size of source area

0x8042 = READY or COM missing

0x807F = internal driver access error


Example:

L W#16#0100 // process input start address
T MD 20
CALL SFC 210
IN0  := 125 // function 125
IN1  := 300 // DB 300
IO2  := MD 20 // process input start address
OUT3  := MW 24 // error code


Function 126 Write process outputs

With this function a data block can be written into the process outputs. Herewith every available peripheral byte can be accessed. The function writes asynchronously. With word oriented outputs no data consistence exists and the function can only be used byte oriented. If the function was not executed successfully, the BR is not set. The return value contains the standard 80xx error codes.


Error codes:

0x813A = data block not available

0x8222 = size of data block bigger than size of source area

0x8042 = READY or COM missing

0x807F = internal driver access error


Example:

L W#16#0100 // process output start address
T MD 20
CALL SFC 210
IN0  := 126 // function 126
IN1  := 300 // DB 300
IO2  := MD 20 // process output start address
OUT3  := MW 24 // error code


Function 130 Read global diagnostic bits

With this function global diagnostic bits can be read.

Bit PROFIBUS® message
0 Parameter error
1 Component branched because of bus error in Auto_Clear_Modus
2 At least one slave is not transferring data or reports a fatal error
3 Fatal bus error, further data transferring impossible
4 Short circuit on the bus
5 Host not ready
6 reserved
7 reserved


Bit Interbus message
0 Parameter error
1 System error occured
2 At least one slave reports module error
3 At least one defective W1-port
4 At least one defective W2-port
5 reserved
6 reserved
7 reserved

If the function was not executed successfully, the BR is not set. The return value contains the standard 80xx error codes.


Error codes:

0x807F = Internal driver access error


Example:

CALL SFC 210
IN0  := 130 // function 130
IN1  := 0 // no DB
IO2  := MD 20 // diagnostic bits
OUT3  := MW 24 // error code


Function 131 Read bus status

With this function the bus status can be read.

Bit Interbus message
0 Bus segment turned off
1 reserved
2 reserved
3 reserved
4 reserved
5 reserved
6 reserved
7 reserved

If the function was not executed successfully, the BR is not set. The return value contains the standard 80xx error codes.


Error codes:

0x807F = Internal driver access error


Example:

CALL SFC 210
IN0  := 131 // function 131
IN1  := 0 // no DB
IO2  := MD 20 // bus status
OUT3  := MW 24 // error code


Function 132 Read incorrect bus address

With this function the incorrect bus address can be read. If the function was not executed successfully, the BR is not set. The return value contains the standard 80xx error codes.


Error codes:

0x807F = Internal driver access error


Example:

CALL SFC 210
IN0  := 132 // function 132
IN1  := 0 // no DB
IO2  := MD 20 // incorrect bus address
OUT3  := MW 24 // error code


Function 133 Read error number

With this function the error number can be read. If the function was not executed successfully, the BR is not set. The return value contains the standard 80xx error codes.


Error codes:

0x807F = Internal driver access error


Example:

CALL SFC 210
IN0  := 133 // function 133
IN1  := 0 // no DB
IO2  := MD 20 // error number
OUT3  := MW 24 // error code


Function 134 Read status bits

With this function the status bits can be read. Before the call the status byte number (0..15) must be selected. After the function call, the selected status byte is returned. If a binary digit in status byte is 1, the corresponding slave is active, if it is 0, it is inactive. If the function was not executed successfully, the BR is not set. The return value contains the standard 80xx error codes.


Error codes:

0x807F = Internal driver access error


Example:

L W#16#03 // byte number 3
T MD 20
CALL SFC 210
IN0  := 134 // function 134
IN1  := 0 // no DB
IO2  := MD 20 // before calling status byte nummer, after calling the content of the status byte
OUT3  := MW 24 // error code


Function 135 Read diagnostic bits

With this function the diagnostic bits can be read. Before the call the diagnostic byte number (0..15) must be selected. After the function call, the selected diagnostic byte is returned. If a bit in the diagnostic byte is 1, the status of the corresponding slave has changed (from active to inactive or vice versa). If the function was not executed successfully, the BR is not set. The return value contains the standard 80xx error codes.


Error codes:

0x807F = Internal driver access error


Example:

L W#16#03 // byte number 3
T MD 20
CALL SFC 210
IN0  := 135 // function 135
IN1  := 0 // no DB
IO2  := MD 20 // before calling diagnostic byte number, after calling the content of diagnostic byte
OUT3  := MW 24 // error code


Function 136 Read dual-port memory

With this function an area from the dual-port memory of the CIF-card can be written into a data block. Basically it begins with the first byte in the data block. The length is passed in the I/O-parameter low word and the relative address in the dual-port memory in the I/O-parameter high word. If the function was not executed successfully, the BR is not set. The return value contains the standard 80xx error codes.


Error codes:

0x813A = data block not available

0x8222 = size of data block to small

0x8224 = range overflow

0x8042 = READY or COM missing

0x807F = Internal driver access error


Example:

L DW#16#0100000A // copy 10 bytes from the relative address 100H
T MD 20
CALL SFC 210
IN0  := 136 // function 136
IN1  := 60 // DB 60
IO2  := MD 20 // 10 bytes are read from the relative address 0x100H
OUT3  := MW 24 // error code


Function 137 Write dual-port memory

With this function an area from the data block can be written into the dual-port memory of the CIF-card. Basically it begins with the first byte in the data block. The length is passed in the I/O-parameter low word and the relative address in the dual-port memory in the I/O-parameter high word. If the function was not executed successfully, the BR is not set. The return value contains the standard 80xx error codes.


Error codes:

0x813A = data block not available

0x8222 = size of data block to small

0x8224 = range overflow

0x8042 = READY or COM missing

0x807F = Internal driver access error


Example:

L DW#16#0100000A // copy 10 bytes into the relatice address 100H
T MD 20
CALL SFC 210
IN0  := 137 // function 137
IN1  := 60 // DB 60
IO2  := MD 20 // 10 bytes are written into the relative address 0x100H
OUT3  := MW 24 // error code


Function 140 trigger watchdog

This function is needed, if very long PLC cycles occur. If the function was not executed successfully, the BR is not set. The return value contains the standard 80xx error codes.


Error codes:

None


Example:

CALL SFC 210
IN0  := 140 // function 140
IN1  := 0 // no DB
IO2  := MD 20 // no function code
OUT3  := MW 24 // error code


Function 141 Read HostFlags

With this function HostFlags can be read.

Bit Hostflag message
0 HostCom: Handshake of the receive mailbox
1 DevAck: Handshake of the send mailbox
2 PdAck: Handshake of the process image
3 ERR: communication error to one network device
4 PdExtAck: extended handshake of the pcrocess image
5 COM: I/O exchange to one network device established
6 RUN: DEVICE is communicating, configuration valid
7 READY: DEVICE is running, end of initialisation

If the function was not executed successfully, the BR is not set. The return value contains the standard 80xx error codes.


Error codes:

0x807F = Internal driver access error


Example:

CALL SFC 210
IN0  := 141 // function 141
IN1  := 0 // no DB
IO2  := MD 20 // returns the HostFlags
OUT3  := MW 24 // error code


Function 142 Read DevFlags

With this function DevFlags can be read.

Bit Deviceflag message
0 HostCom: Handshake of the receive mailbox
1 DevCom: Handshake of the send mailbox
2 PdCom: Handshake of the process image
3 Reserved
4 PdExtCom: extended handshake of the pcrocess image
5 NotRdy: HOST program not ready
6 Init: Initialisation with parameter from dual-port memory
7 Reset: Reset DEVICE

If the function was not executed successfully, the BR is not set. The return value contains the standard 80xx error codes.


Error codes:

0x807F = Internal driver access error


Example:

CALL SFC 210
IN0  := 142 // function 142
IN1  := 0 // no DB
IO2  := MD 20 // returns the DevFlags
OUT3  := MW 24 // error code


Function 150 Execute DevGetTaskState

With this function the global diagnostic infomation, reported from the CIF-module, can be read. The structure contains information about the bus condition and the condition of several slaves. The information is stored in bit-fields. In this way information about the master and the condition of the fieldbus is available. Furthermore it can be read, which slaves are configured and in use, which slaves are active and inactive and which slaves contain diagnostic information. The driver function DevGetTaskState is called internally. The result is written into a DB. To be able to use the function, the information to the function should be extracted from the Hilscher manual dpm_pie.pdf. The DB should comply with the DPM_DIAGNOSTICS structure described there. If the function was not executed successfully, the BR is not set. The return value contains the standard 80xx error codes.


Error codes:

0x813A = data block not available

0x8222 = size of data block to small

0x8225 = range overflow

0x807F = internal driver access error


Example:

L DW#16#2
T MD 20 // task 2
CALL SFC 210
IN0  := 150 // function 150
IN1  := 300 // DB 300
IO2  := MD 20 // task number
OUT3  := MW 24 // error code

Adequate DB example:

DATA_BLOCK DB 300
TITLE=DIAG
VERSION : 0.1
STRUCT
bGlobalBits : BYTE;
bDPM_state : BYTE;
tError : STRUCT
bErr_Rem_Adr : BYTE;
bErr_Event : BYTE;
END_STRUCT;
usBus_Error_Cnt : WORD;
usTime_Out_Cnt : WORD;
abReserved : ARRAY[0..7] OF BYTE;
abSl_cfg : ARRAY[0..15] OF BYTE;
abSl_state : ARRAY[0..15] OF BYTE;
abSl_diag : ARRAY[0..15] OF BYTE;
END_STRUCT;
BEGIN
END_DATA_BLOCK


Function 151 Execute DevGetInfo

With DevGetInfo various information can be read from the dual-port of the CIF-card. These are:

DW#16#1 GET_DRIVER_INFO Driver status information

DW#16#2 GET_VERSION_INFO version information of the CIF

DW#16#3 GET_FIRMWARE_INFO version of the CIF firmware

DW#16#4 GET_TASK_INFO Task information

DW#16#5 GET_RCS_INFO CIF specific operating system information

DW#16#6 GET_DEV_INFO Device information

DW#16#7 GET_IO_INFO Device I/O information

DW#16#8 GET_IO_SEND_DATA Device I/O send data


The driver function DevGetInfo is called internally. The result is written into a DB. In order to use the function, the information to the function should be extracted from the Hilscher manual devdrv.pdf. The DB should comply with the structures described there. If the function was not executed successfully, the BR is not set. The return value contains the standard 80xx error codes.


Error codes:

0x813A = data block not available

0x8222 = data block size to small

0x8225 = not an available function number

0x807F = internal driver access error


Example:

L DW#16#1 // function GET_DRIVER_INFO
T MD 20
CALL SFC 210
IN0  := 151 // function 151
IN1  := 300 // DB 300
IO2  := MD 20 // function number
OUT3  := MW 24 // error code


Function 152 Execute DevGetTaskParameter

With this function the global settings, as for example the transfer rate of the bus, the watchdog time etc. can be read from the CIF-card. The driver function DevGetTaskParameter is called internally. The result is written into a DB. To be able to use the function, the information to the function should be extracted from the Hilscher manual devdrv.pdf. The DB should correspond to the structure described there. If the function was not executed successfully, the BR is not set. The return value contains the standard 80xx error codes.


Error codes:

0x813A = data block not available

0x8222 = data block size to small

0x8225 = not an available function number

0x807F = internal driver access error


Example:

L DW#16#2 // task 2
T MD 20
CALL SFC 210
IN0  := 152 // function 152
IN1  := 300 // DB 300
IO2  := MD 20 // function number
OUT3  := MW 24 // error code


Function 153 Read slave diagnostics of a specific slave

With this function the standard diagnostic data of a DP-slave can be read. The information is returned in DPM_SLAVE_SINGLE_DIAGNOSTICS format. This function may not be used in conjunction with the driver CIFCFG.DLL (PROFIBUS® with CIF-card). In this case the SFC 13 (as hardware PLC), provided by the driver CIFCGF.DLL, has to be used instead. Details can be extracted from the Hilscher Manual dpm_pie.pdf, section DDLM_Slave_Diag. The DB should comply with the structure described there. If the function was not executed successfully, the BR is not set. The return value contains the standard 80xx error codes.


Error codes:

0x813A = data block not available

0x8222 = dize of data block to small

0x8225 = range overflow

0x807F = internal driver access error


Example:

L DW#16#2B // PROFIBUS® address of the slave (here : 11dec)
T MD 20
CALL SFC 210
IN0  := 153 // function 153
IN1  := 300 // DB 300
IO2  := MD 20 // function number
OUT3  := MW 24 // error code

Adequate DB example:

DATA_BLOCK DB 300
TITLE=
VERSION : 0.1
STRUCT
DPM_SLAVE_DIAG : STRUCT
Stationsstatus_1 : BYTE;
Stationstatus_2 : BYTE;
Stationstatus_3 : BYTE;
bMaster_Add : BYTE; // corresponding master address
usIdent_Number : WORD; // ident number, big endian (motorola format)
abExt_Diag_Data : ARRAY[0..99] OF BYTE; // extended diagnostic field
END_STRUCT;
END_STRUCT;
BEGIN
END_DATA_BLOCK