Diagnostics in the PLC program

For the analysis of the terminal bus (K-bus) the State register can be accessed via TwinCAT from a PLC program.

Diagnostics in the PLC program 1:

The error analysis is presented as an example below.

A signal/variable is essentially required for the error analysis:

External variables must similarly be created in the PLC program for this:


VAR

    k_bus_state AT %IB2 : USINT;

END_VAR

The error can then be determined in the PLC program as follows (this is pseudo code, which is not directly executable in this form)


....

IF k_bus_state != 0 THEN     (* auf dem K-Bus ist ein Fehler aufgetreten *)

IF k_bus_state.1 = 1 THEN melde Fehler; (* Klemmenzustandsfehler *) END_IF
IF k_bus_state.2 = 1 THEN melde Fehler; (* Prozessdatenlänge ungültig *) END_IF
IF k_bus_state.8 = 1 THEN melde Fehler; (* keine gültigen Eingänge *) END_IF
IF k_bus_state.9 = 1 THEN melde Fehler; (* K_bus Input Update ist aktiv *) END_IF
IF k_bus_state.10 = 1 THEN melde Fehler; (* K_bus Output Update ist aktiv *) END_IF
IF k_bus_state.11 = 1 THEN melde Fehler; (* Watchdog Fehler *) END_IF
IF k_bus_state.15 = 1 THEN melde Fehler; (* Bus ist asynchron *) END_IF
END_CASE

k_bus_request := TRUE;     (* Rücksetzen des Busses, wenn Fehler beseitigt, dann startet der Klemmbus wieder *)

....

In order for the controller and the registers to co-operate, they must be linked in the System Manager.