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:
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):
|
0 |
|
2 |
Output of the status of all subordinate components of the addressed hardware component. |
Structure DNN (see below for description):
|
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 |
|
||
|
1 |
The hardware component is disabled. |
|
||
|
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 |
|
||
|
9 |
- |
- |
||
|
10 |
Inputs/outputs are not available. |
|
||
|
ComponentStateDetail |
DWORD |
Bit array |
Status:
|
- |
|
0 to 2 (Enum) |
Additional information:
|
- |
||
|
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) |
|
- |
||
|
11 to 14 (Enum) |
|
- |
||
|
15 |
Reserved (always "1"). |
- |
||
|
16 to 31 |
Status information for modules generated by the CPU:
|
- |
||
|
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 |
If bit 0 = 1, bits 1 to 5 and bit 7 = 0. |
||
|
Bit 1 = 1 |
Disabled |
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 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 |
|
||
|
8 to 14 |
Reserved (always = 0) |
- |
||
|
Bit 15 |
Network/hardware fault
|
- |
||
|
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 |
|
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.
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.