Analyzing Diagnostic Data
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.1
Introduction
Diagnostic interrupt (OB 82)
Read out diagnostic data with SFC 59
Read out system status lists with SFC 51
Diagnostics-capable module CPU
Own message "Wrong weight", actual value: ... Diagnostic
SFC 52
buffer
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.2
Interesting Facts about System Functions
The system functions (SFCs and SFBs) are stored
in the CPU‘s operating system
System Software Reference Manual for S7-300/400
System Functions and Standard Functions
Extensive Online help available in the STEP 7 software
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.3
Call of System Functions
Call in STL Call in FBD
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.4
Analyzing an Error Message
The scan of the BR-bit (binary result) returns RLO=0 for
processing with fault and RLO=1 for fault-free processing.
Scan of BR for STL with A BR
Scan in LAD/FBD using the output parameter ENO
Most of the system functions return an error code with the
following configuration in the output parameter RET_VAL (INT):
RET_VAL=W#16#8 X Y Z
Error class, error‘s individual number (SFC specific)
or event number (general)
X>0: general error, X= no. of faulty parameter
X=0: SFC specific error occurred
"8" signals: error occurred
Example:
W#16#8081 is an SFC specific error code.
W#16#823A is a general error code; the error was caused by parameter
no. 2.
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.5
Writing User Messages in the Diagnostic Buffer
CPU Station
e.g. PG, OP
Send buffer
SEND =
TRUE
1 2
SFC 52
Sending
Diagnostic buffer
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.6
SFC 52 System Function
Parameter Declaration Data type Memory area Description
SEND INPUT BOOL I, Q, M, D, L, Const. Enabling the sending of the user-defined diagnostic
message to all logged on stations (PG/OP)
EVENTN INPUT WORD I, Q, M, D, L, Const. Event ID. This message number defines the text
that is entered in the diagnostic buffer, or is sent
to a display device.
INFO1 INPUT ANY I, Q, M, D, L Additional information 1 (1 word) as wildcard
in the message text
INFO2 INPUT ANY I, Q, M, D, L Additional information 2 (1 double word) as
wildcard in the message text
RET_VAL OUTPUT INT I, Q, M, D, L Error information
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.7
Assignment of Parameters of the ANY Data type
P#M100.0 Int 1 MW100
or
P#M102.0 Real 1 MD102
Length ANY data type
Data type
Byte and
Bit address
ID
Pointer
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.8
Calling the SFC 52 Block
Network 2: User message when limit value exceeded
CMP>R
MD 120 IN1 M 90.1 SFC 52
P
5.000000e+003 IN2 EN
M 0.1 SEND
W#16#A901 EVENTN RET_VAL #error_sfc52
#dummy INFO 1
MD 120 INFO 2 ENO
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.9
Structure of the EVENTN Parameter of the SFC 52 Block
EVENTN 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Event class Identification Event number
1..9 are standard texts for the different events
Event class (see the Standard and System Functions manual)
A..B free texts, that are specified using Message Configuration
C..F reserved for expansions in the future
Specifies if it is an incoming or an outgoing event, or, an internal
or an external event, for example:
Identification Bit 8="1" --> Text for incoming message
Bit 8="0" --> Text for outgoing message
Bit 10="1" --> internal error
Bit 11="1" --> external error
Continuous message number from 1 to 255 within an
Event number
event class
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.10
Configuring Your Own Message Texts
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.11
Exercise: Analyzing an Error Message using RET_VAL
Network X: Analyzing RET_VAL, ENO
SFC 52
M 90.1
P
I 0.6 EN
M 0.1 SEND
W#16#901 EVENTN RET_VAL MW 200
MW 208 INFO 1
Q 9.2 (Q 5.2)
MW 210 INFO 2 ENO =
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.12
Exercise: Writing User Messages in the Diagnostic Buffer
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.13
SFC 51 System Function
Parameter Declaration Data type Memory area Description
REQ INPUT BOOL I, Q, M, D, L, Const. REQ=1: triggers processing
SZL_ID INPUT WORD I, Q, M, D, L, Const. SZL-ID of the sublist or of the sublist excerpt
INDEX INPUT WORD I, Q, M, D, L, Const. Type or number of an object in a sublist
RET_VAL OUTPUT INT I, Q, M, D, L If an error occurs while the SFC is being processed,
then the RET_VAL parameter contains an error
code.
BUSY OUTPUT BOOL I, Q, M, D, L TRUE: Read function not yet completed
SZL_HEADER OUTPUT STRUCT D, L see page after next
DR OUTPUT ANY I, Q, M, L, D Target range for the SZL sublist that is read or
the SZL sublist excerpt that is read.
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.14
Excerpt of SZL Sublists for S7-300
SZL_ID Sublist Index Record contents
0111H CPU identification 0001H CPU type and version
0014H Operating system areas - Size of PIQ, PII, M, T, C ...
Number and size of OBs,
0015H Block types -
DBs, SDBs, FCs, FBs
0019H Status of all module LEDs - Status of LEDs
0232H CPU protection level 0004H Position of the key switch
0692H Status of racks - OK status
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.15
Structure of the Parameter SZL_Header
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.16
Structure of the Data Record Status LEDs (SZL_ID 0019H)
Name Length Meaning
LED identifier
W#16#0001: SF
W#16#0004: RUN
Index 1 Word
W#16#0005: STOP
W#16#0006: FRCE
W#16#0008: BATF
led_on 1 Byte 0= LED off, 1= LED on
0= LED doesn‘t blinkt, 1= LED blinks with 2 Hz, 2= LED blinks
led_blink 1 Byte
with 0.5 Hz
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.17
User-defined Data Type (UDT)
UDT block as template Global DB (example)
index index
Led_on Led_on Data record
1
Led_blink Led_blink
index
Led_on Data record
2
Led_blink
index
Array with
Led_on Data record 4 elements
3 of the UDT type
Led_blink
index
Led_on Data record
4
Led_blink
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.18
Inputting a UDT Block
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.19
Example: Array of UDTs
Declaration view
Data view
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.20
Exercise: Reading Out the SZL Sublist “Status of LEDs“
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.21
Reading Out Diagnostic Data with the System Function SFC 59
Parameter Declaration Data type Memory area Description
REQ INPUT BOOL I, Q, M, D, L, Const. REQ = 1: Request for reading
IOID INPUT BYTE I, Q, M, D, L, Const. Identifier of address area:
B#16#54 = Peripheral input (PI)
B#16#55 = Peripheral output (PQ)
If it is a mixed module the area identifier of the
lower address is to be specified. If the address is
the same B#16#54
LADDR INPUT WORD I, Q, M, D, L, Const. Logical address of the module
RECNUM INPUT BYTE I, Q, M, D, L, Const. Data record number (permitted values: 0 to 240)
RET_VAL OUTPUT INT I, Q, M, D, L Error number as return value
BUSY OUTPUT BOOL I, Q, M, D, L BUSY = 1: The reading function is not yet completed.
RECORD OUTPUT ANY I, Q, M, D, L Target area for the data record that is read
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.22
Diagnostic Data of the Signal Modules
Data rec. No. Contents Size
Module-specific
0 4 bytes
diagnostic data
for S7-300: 16 bytes
Channel-specific
1 for S7-400:7-220 bytes
diagnostic data
2-127 User data each <= 240 bytes
128 to 240 Diagnostic data each <= 240 bytes
Address Structure of data record 1
0 Module diagnostic byte 1 Configuration - Parameter-
0
assignment error
1 Common-mode error
3 Module diagnostic byte 4 2 P-short circuit
4 Channel type (70H=DI, 71H=AI, 72H=DO, 73H=AO) 3 M-short circuit
5 Number of diagnostic bits per channel
4 Wire break
6 Number of channels
7 Channel error bits 5 Reference channel error
8 Channel-spec. diagnostic byte, channel 0 6 Exceeding measuring range (lower)
7 Exceeding measuring range (upper)
15 Channel-spec. diagnostic byte, channel 7
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.23
Exercise: Reading Out Data Record 1 of an Analog Module
Step What to Do Result
Check whether the diagnostic interrupt
1 is enabled on the analog module.
At the end of OB 82 insert a new network.
2
Using the SFC 59, read out the data record
3 1 of the analog module and save this in
DB 59 as of data byte 0.
Test the program by setting a voltage You can analyze additional diagnostic
4 > 13V at an analog channel. Interpret data.
the data record by reading out the DB 59.
SIMATIC S7 Date: 18.08.2018 SITRAIN Training for
Automation and Drives
Siemens AG 2000. All rights reserved. File: PRSERV_04E.24