GET_DIAG: Read diagnostic information (S7-1200, S7-1500) - STEP 7

Extended instructions (S7-1200, S7-1500)

ft:publication_title
Extended instructions (S7-1200, S7-1500)
Product
STEP 7
Version
V20
Publication date
11/2024
Language
en-US
GET_DIAG: Read diagnostic information

Description

The "GET_DIAG" instruction is used to read the diagnostic information of a hardware component. The hardware component is selected with the parameter LADDR. With the MODE parameter, you select which diagnostic information is read. The S7-1200 CPU ignores the parameter LADDR when MODE=0.

Parameters

The following table shows the parameters of the "GET_DIAG" instruction:

Parameter

Declaration

Data type

Memory area

Description

MODE

Input

UINT

I, Q, M, D, L or constant

Use the MODE parameter to select which diagnostics data is output.

LADDR

Input

HW_ANY (UINT)

I, Q, M, L or constant

Hardware ID of the hardware component

RET_VAL

Return

INT

I, Q, M, D, L

Status of the instruction

CNT_DIAG

Output

UINT

I, Q, M, D, L

Reserved (always "0").

DIAG

InOut

VARIANT

I, Q, M, D, L

Diagnostic information corresponds to the selected mode, see table below

DETAIL

InOut

VARIANT

I, Q, M, D, L

Parameter is hidden. Do not use this parameter!

You can find additional information on valid data types under "Overview of the valid data types".

Parameter MODE

Depending on the value at the MODE parameter, different diagnostic data is output at the DIAG, CNT_DIAG and DETAIL output parameters.

MODE

Description

DIAG

CNT_DIAG

0

Output of all supported diagnostic information for a hardware component as DWORD, where Bit X=1 indicates that mode X is supported.

Bits of the DWORD data type:

  • Bit 0 = 1: MODE 0 is supported

  • Bit 1 = 1: MODE 1 is supported

  • Bit 2 = 1: MODE 2 is supported

  • Bits 3 to 31: Not relevant

With MODE=0, the S7-1200 CPU ignores the parameter LADDR.

0

1

Output of the diagnostic status of the addressed hardware component.

Structure DIS (see below for description):

  • MaintenanceState

  • ComponentStateDetail

  • OwnState

  • IOState

  • OperatingState

0

2

Output of the status of all subordinate components of the addressed hardware component.

Structure DNN (see below for description):

  • SubordinateState

  • SubordinateIOState

  • DNNmode

0

DIS structure

With parameter MODE = 1, the diagnostic information is output in accordance with the DIS structure. In this case, enter the system data type "DIS" as data type for the tag declaration.

Note

Determining the OperatingState

When determining the OperatingState of a standard CPU, you need to select LADDR = 52 (hardware identifier of CPUExecUnit).

When determining the OperatingState of a CPU of an R/H system, you need to select LADDR = 65147 (hardware identifier of Local1~HCPUredCtrl) or LADDR = 65347 (hardware identifier of Local2~HCPUredCtrl).

When determining the system state of an R/H system, you need to select LADDR = 34 (hardware identifier of Local1~RHSystem).

The following table shows the meaning of the individual parameter values.

Parameter

Data type

Value

Description

Rule for forming the parameter

MaintenanceState

DWORD

Enum

 

MaintenanceState depends on ComponentStateDetail.

0

Good

  • Bit 15 of ComponentStateDetail is always 1.

  • Bits 11 to 14 of ComponentStateDetail can have the value 0 or 1.

  • Bit 3 of ComponentStateDetail can be 1.

  • All other bits of ComponentStateDetail are 0.

1

The hardware component is disabled.

  • If bit 16 of ComponentStateDetail is 1

  • If bit 17 of ComponentStateDetail is 1

2

-

-

3

-

-

4

-

-

5

Maintenance required

If bit 4 of ComponentStateDetail is 1

6

Maintenance demanded

If bit 5 of ComponentStateDetail is 1

7

Error

If bit 6 of ComponentStateDetail is 1

8

Status unknown / error in higher-level hardware component

  • If bits 11 to 14 of ComponentStateDetail have the value 3

  • If bits 7 to 10 of ComponentStateDetail have the value 3 or 4

9

-

-

10

Inputs/outputs are not available.

  • If bits 11 to 14 of ComponentStateDetail have the value 2

  • If bits 7 to 10 of ComponentStateDetail have the value 1 or 2

  • If bit 18 of ComponentStateDetail is 1

  • If bit 19 of ComponentStateDetail is 1

ComponentStateDetail

DWORD

Bit array

Status:

  • Bit 0 to 15: Status of the hardware component

  • Bit 16 to 31: Status of the CPU

-

0 to 2 (Enum)

Additional information:

  • 0: No additional information

  • 1: Transfer not permitted

-

3

Bit 3 = 1 if at least one qualified diagnostics is available

-

4

Bit 4 = 1: Maintenance required for at least one channel or the component

-

5

Bit 5 = 1: Maintenance demanded for at least one channel or the component

-

6

Bit 6 = 1: Error in at least one channel or the component

-

7 to 10 (Enum)

  • 0: Own - Hardware component is available

  • 1: Application Ready Pending - No I/O access

  • 2: Locked by Superordinated - No access to hardware component

  • 3: Locked by IOController - No access to hardware component

  • 4: Locked by IOSupervisor - No access to hardware component

-

11 to 14 (Enum)

  • 0 (bit 11 = 0, bit 12 = 0, bit 13 = 0, bit 14 = 0): OK - The correct element exists.

  • 1 (bit 11 = 1, bit 12 = 0, bit 13 = 0, bit 14 = 0): Substitute - The element was replaced by a compatible element.

  • 2 (bit 11 = 0, bit 12 = 1, bit 13 = 0, bit 14 = 0): Wrong - The element was replaced by an incompatible element (The element is reachable, but not ready for operation.).

  • 3 (bit 11 = 1, bit 12 = 1, bit 13 = 0, bit 14 = 0): No Submodule - The element does not exist.

-

15

Reserved (always "1").

-

16 to 31

Status information for modules generated by the CPU:

  • Bit 16 = 1: Submodule or module disabled

  • Bit 17 = 1: CiR operation active

  • Bit 18 = 1: Input not available

  • Bit 19 = 1: Output not available

  • Bit 20 = 1: Overflow diagnostics buffer

  • Bit 21 = 1: Diagnostics not available

  • Bit 22 = 1: Partial device failure (with PNIO for Shared iDevices)

  • Bit 23 - 31: Reserved (always 0)

-

OwnState

UINT

Enum

Maintenance status

OwnState depends on MaintenanceState.

0

Good

If MaintenanceState has the value 0.

1

Disabled

If MaintenanceState has the value 1.

2

Maintenance required

If MaintenanceState has the value 5.

3

Maintenance demanded

If MaintenanceState has the value 6.

4

Error

If MaintenanceState has the value 7.

5

Not accessible

If MaintenanceState has the value 8.

6

Diagnostic status unknown

Default value for components that do not return diagnostic events.

7

IO not available - Inputs/outputs are not available.

If MaintenanceState has the value 10.

IOState

WORD

Bit array

I/O status of the hardware component

One or more bits can be set.

IOState depends on ComponentStateDetail.

Bit 0 = 1

Good

  • Bit 15 of ComponentStateDetail is always 1.

  • Bits 11 to 14 of ComponentStateDetail can have the value 0 or 1.

  • Bit 3 of ComponentStateDetail can be 1.

  • All other bits of ComponentStateDetail are 0.

If bit 0 = 1, bits 1 to 5 and bit 7 = 0.

Bit 1 = 1

Disabled

  • If bit 16 of ComponentStateDetail is 1

  • If bit 17 of ComponentStateDetail is 1

If bit 1 = 1, all other bits are 0.

Bit 2 = 1

Maintenance required

If bit 4 of ComponentStateDetail is 1

Bit 3 = 1

Maintenance demanded

If bit 5 of ComponentStateDetail is 1

Bit 4 = 1

Error

If bit 6 of ComponentStateDetail is 1

Bit 5 = 1

Hardware component not reachable - Hardware component cannot be accessed.

  • If bits 11 to 14 of ComponentStateDetail have the value 3

  • If bits 7 to 10 of ComponentStateDetail have the value 3 or 4

If bit 5 = 1, all other bits are 0.

Bit 6 = 1:

Qualified: Bit 6 = 1 if at least one qualified diagnostics is available

If bit 3 of ComponentStateDetail is 1

Bit 0, 2, or 3 is set in this case.

Bit 7 = 1:

I/O data not available - I/O data not available

  • If bits 11 to 14 of ComponentStateDetail have the value 2

  • If bits 7 to 10 of ComponentStateDetail have the value 1 or 2

  • If bit 18 of ComponentStateDetail is 1

  • If bit 19 of ComponentStateDetail is 1

8 to 14

Reserved (always = 0)

-

Bit 15

Network/hardware fault

  • S7-1200: Reserved (always = 0)

  • S7-1500: If bit 4 = 1 or bit 5 = 1:

    • Bit 15 = 0: Network error

    • Bit 15 = 1: Hardware error

-

OperatingState

UINT

Enum

-

0

Not Supported - for I/O modules OperatingState always has the value 0.

-

1

STOP / firmware update

-

2

STOP / Memory reset

-

3

STOP / self start

-

4

STOP

-

5

Memory reset

-

6

Startup

-

7

-

-

8

RUN

-

9

RUN-Redundant

-

10

HOLD

-

11

-

-

12

-

-

13

DEFECT (Note: can only be seen in diagnostics buffer entries)

-

14

-

-

15

De-energized (Note: can only be seen in diagnostics buffer entries)

-

16

CiR

-

17

STOP without ODIS

-

18

RUN ODIS

-

19

PgmTest

-

20

RunPgmTest (state of primary CPU when the backup CPU is in test mode)

-

21

Run-Syncup (only Primary CPU in SYNCUP system state)

-

22

SYNCUP (only backup CPU in SYNCUP system state)

-

31

State of partner CPU unknown (for example when the partner CPU is not available)

-

32

-

-

33

STOP system state

-

34

Reserved

-

35

STARTUP system state

-

36

Reserved

-

37

RUN-Solo system state

-

38

SYNCUP system state

-

39

Reserved

-

40

RUN-Redundant system state

-

DNN structure

With parameter MODE = 2, the diagnostic information details are output in accordance with the DNN structure. In this case, enter the system data type "DNN" as data type for the tag declaration.

The following table shows the meaning of the individual parameter values.

Parameter

Data type

Value

Description

SubordinateState

UINT

Enum

Status of the subordinate component (see parameter OwnState of the DIS structure)

SubordinateIOState

WORD

Bitarray

Status of the inputs and outputs of the subordinate component (see parameter IO State of the DIS structure)

DNNmode

WORD

Bitarray

  • Bit 0 = 0: Diagnostics enabled

  • Bit 0 = 1: Diagnostics disabled

  • Bit 1 to 15: Reserved

Parameter RET_VAL

Error code*


(W#16#...)

Description

0

No error

n

The data area at the DETAIL parameter is too small. Not all details of the diagnostics data are output.

8080

Value in the MODE parameter is not supported.

8081

Type at the DIAG parameter is not supported with the selected mode (parameter MODE).

8082

Type at the DETAIL parameter is not supported with the selected mode (parameter MODE).

8090

LADDR does not exist

80C1

Insufficient resources for parallel execution.

* The error codes in the program editor are displayed as integer or hexadecimal values. For information on switching the display formats, refer to "See also".

Example

In the following example, you read out the diagnostic information of a CPU.

Create four tags and a "myDIAG" structure (with the DIS data type) in a global data block for storing the data.

Interconnect the parameters of the instruction as follows.

The HW identifier of the CPU is made known to the "GET_DIAG" instruction through parameter LADDR ("myLADDR"). According to the value "1" of parameter MODE ("diagMODE"), the following applies:

  • The instruction reads the status of the addressed hardware object (of the CPU).

  • At parameter DIAG ("myDIAG"), the diagnostic information is output in a structure (DIS data type).

To understand the diagnostic information, the hex values must be converted to binary code. At parameter DIAG ("myDIAG"), the following is indicated:

  • MaintenanceState: According to the value "0", the CPU requires no maintenance.

  • ComponentStateDetail: According to the hex value "0000_8000", bit 15 is active.

  • OwnState: According to the value "0", no fault has occurred.

  • IOState: According to the hex value "0001", there is no maintenance required.

  • OperatingState: Outputs "0".

The output parameter RET_VAL ("returnValue") indicates that processing took place without errors. At output parameter CNT_DIAG ("CountDiagDetails"), it is indicated that "0" diagnostic details of parameter DETAIL have been output.

Note: For example, you could individually read out bit 3 (channel diagnostics yes/no) from the ComponentStateDetail tag.

  • Address the bit as follows: ComponentStateDetail.%X3

Example - Diagnostics of an IO device

In the following example, you read out the diagnostic information of an IO device. For diagnostics, you use the device view of the IO device and the instruction GET_DIAG.

Diagnostics in the device view

One of the IO device modules signals an error. The device status changes and is displayed as follows:

The module and the head module of the IO device show a group status in the device view. An error is therefore displayed for both.

Diagnostics with the GET_DIAG instruction

To read out the diagnostic information of the IO device, address the head module of the IO device (via LADDR).

  • In mode 1 (MODE has the value 1), you read out the status of the IO device.

  • In mode 2 (MODE has the value 2), you read out the status of the subordinate modules.

Call MODE 1: Self-diagnostics

Call MODE 2: Summary of the subordinate diagnostics

LADDR (HW ID) = IM151-3pn~IODevice

DIAG (DIS structure) = #DeviceData.DeviceState

DIS.OwnState = 0 (no error)

DIS.IOState = bit sequence 0000 0000 0000 0001

LADDR (HW ID) = IM151-3pn~IODevice

DIAG (DNN structure) = #DeviceData.SubState

DNN.SubordinateState = 4 (error)

DNN.SubordianteIOState = bit sequence 1000 0000 0001 0001

Result

Unlike the device view, the GET_DIAG instruction does not return the group status of the IO device. The error in the subordinate module is not read until mode 2.