TwinCAT - Example for Diagnostics with the FC310x Fieldbus Card

The DiagnoseStation11 bit signals diagnosis for station 11. The diagnostic information is read with the ADS block, and copied into the strDiagnose array. Further processing can be done there.

NETID       NetID of the FC310x card
Port            Diagnostic port fixed 200
IDXGRP    Slave address in the high word, and the constant 0xF181 in the low word
IDXOFF     always "0", read entire diagnosis
LEN           276 bytes

Structure of the diagnostic data

Offset

Description

0

Receive Error Counter (WORD): The number of faulty telegrams occurring while communicating with this slave.

2

As from FC310x, version 1.11:
Repeat Counter[9] (WORD): The repeat counters (Repeat-Counter) indicate how often it has been necessary to repeat a telegram a given number of times (1..MaxRetryLimit, MaxRetryLimit without answer). Repeat-Counter[0] indicates how often it has been necessary to repeat a telegram for this slave once, Repeat-Counter[1] shows how often a telegram for this slave has had to be repeated twice, and so on. The MaxRetryLimit parameter can be set in the PROFIBUS parameters (value range 0..8).

20

NoAnswer Counter (DWORD): The number of telegrams occurring during communication with this slave that received no answer and which have not been repeated. The first time that a slave fails to answer, the telegram is repeated up to MaxRetryLimit times, but if it does not answer even then, further telegrams are not repeated.

24-31

reserved

32-37

Profibus standard diagnostics

38-275

Profibus standard extended diagnostics (see manufacturer's documentation)

Programming Example

VAR
DiagnoseStation11 AT %IX100.0:BOOL;
strDiagnose : ARRAY[0..275] OF BYTE;
fbADSREAD : ADSREAD;
k: INT;
END_VAR

 

CASE k OF
 0: IF DiagnoseStation11 THEN fbADSREAD( NETID:= '172.16.3.106.2.1',
            PORT:=200,
            IDXGRP:=16#BF181,
            IDXOFFS:=16#0,
            LEN:=276,
            DESTADDR:=ADR(strDiagnose),
            READ:= TRUE,
            TMOUT:= t#10s, );
        k:=k+1;
    END_IF
 1:     fbADSREAD(READ:= FALSE);
    IF NOT fbADSREAD.busy THEN
        k:=0;
    END_IF
END_CASE