Step 7: Read status LED indicators of S7-300 CPU
This function obtains the status of the CPU LED indicators, for visualization on an HMI, for example. In this function block, we only output the status for system fault and a combined bus fault (for any interface), but you can easily change that.
We will use
RDSYSST (Reading a System Status List or Partial List) with SSL_ID 0x19 to obtain the status of all LEDs at once. The header will contain the record length and the number of records that were returned. The number of records that are returned is CPU dependent. This particular FB I have used without modifications in the S7-300 CPUs 315, 316, 317, 318 and 319.
Once the data has been obtained we copy it to a buffr for analysis, since it is not retained between reads.
After the data has been copied, it is a matter of looping through the records to pick out the ones that are of interest. For this, you need to know the LED IDs (also documented in the FB):
0x01 SF 0x02 INTF 0x03 EXTF 0x04 RUN 0x05 STOP 0x06 FRCE 0x07 CRST 0x08 BAT 0x09 USR 0x0A USR1 0x0B BUS1F 0x0C BUS2F 0x0D REDF 0x0E MSTR 0x0F RACK0 0x10 RACK1 0x11 RACK2
0x12 IFM1F 0x13 IFM2F 0x14 BUS3F 0x15 MAINT 0x16 DC24V 0x17 BUS5F 0x80 IF (init failure) 0x81 UF (user failure) 0x82 MF (monitoring failure) 0x83 CF (communication failure) 0x84 TF (task failure) 0xEC APPL_STATE_RED 0xED APPL_STATE_GREEN
In this example, I use the system fault (SF) status and combine any of the bus faults (BUS1F, BUS2F, BUS3F). Once you look at the code, it is easy to see how that can be adapted to suit your need.
The SFC51 SZL_HEADER output is a structure consisting of the record length and the number of records. The FB has 10 data records of 4 bytes each (for the LED ID, on status and flash status).