ProfinetDiagnosisResources (FB)

FUNCTION_BLOCK ProfinetDiagnosisResources

Function block for accessing diagnosis strings from a TextList generated by “PROFINET Diagnosis Resources”.
Note: Do not access this generated TextList directly. Use this helper function block instead.

Example: Get buffered Diagnosis-Data

PROGRAM DiagExample
VAR
    submodule : ProfinetCommon.SubmoduleInfo;
    submodules : ProfinetCommon.SubmoduleIterator;
    diagEntries : ARRAY[0..3] OF ProfinetCommon.SubmoduleDiagnosisEntry;
    numDiagEntries : DINT;
    i : DINT;
    ID : UDINT;

    diagRes : PVU.ProfinetDiagnosisResources;
    channelDiag : ProfinetCommon.ChannelDiagnosisData;
    message : WSTRING(255);
    help : WSTRING(255);
    extMessage : WSTRING(255);
    extHelp : WSTRING(255);
END_VAR


// init. fucntion block with gnerated TextList (command Add Object -> PROFINET Diagnosis Resources)
IF(NOT diagRes.xInit AND NOT diagRes.xError) THEN
    diagRes.Init('ProfinetDiagnosisTxt');
END_IF

IF(pnDevice.xDiagnosis) THEN        // the device (here named 'pnDevice' in the device tree)
    submodules.InitByID(pnDevice.ID);       // we use the iterator to run throug all submodules of thsi PN Device
    WHILE(submodules.Next(submodule => submodule)) DO
        IF(submodule.xStateInformation) THEN                    // some valid info in SubmoduleState ?
            IF(submodule.SubmoduleState.IdentInfo <> ProfinetCommon.SubmoduleState_IdentInfo.OK) THEN
                ;//-->  'Wrong Module' or sth. like that
            END_IF

            IF(submodule.SubmoduleState.xDiagnosis) THEN        // submodule has any diagnosis entries ?
                numDiagEntries := ProfinetCommon.GetSubmoduleDiagnosis(submodule.ID, diagEntries);
                i := 0;
                WHILE i < numDiagEntries DO
                    //clear text
                    message := "";
                    help  := "";
                    extMessage  := "";
                    extHelp  := "";

                    //resolve numeric error codes tor diagnosis text, e.g. for usage in HMI
                    ID := submodule.ID;
                    channelDiag := diagEntries[i].Diagnosis;
                    IF(diagRes.TryGetDiagMessage(ID, channelDiag, ADR(message), SIZEOF(message))) THEN
                        diagRes.TryGetDiagHelp(ID, channelDiag, ADR(help), SIZEOF(help));       // get additional help

                        IF(channelDiag.ExtChannelErrorType > 0) THEN            // extended error code ? -> more detailed message
                            IF(diagRes.TryGetExtDiagMessage(ID, channelDiag, ADR(extMessage), SIZEOF(extMessage))) THEN
                                diagRes.TryGetExtDiagHelp(ID, channelDiag, ADR(extHelp), SIZEOF(extHelp));
                            END_IF
                        END_IF
                    END_IF

                    i := i + 1;         // hint: set breakpoint here to check values
                END_WHILE
            END_IF

        END_IF
    END_WHILE
END_IF
InOut:

Scope

Name

Type

Output

xInit

BOOL

xError

BOOL

Methods:

Structure: