ObjectIterator (FB)ΒΆ

FUNCTION_BLOCK ObjectIterator IMPLEMENTS IObjectIterator

Helps to iterate through the objects of an ObjectDictionary. For using this iterator property ObjectIterator.ObjectDictionary must be set to the IObjectDictionary interface. This interface can be retrieved from the CANopenDevice instance. After setting the Object Dictionary interface the iterator points in front of the first element of the Object Dictionary (==> property ObjectIterator.Current is 0). The iterator can be moved to the next element by calling the ObjectIterator.MoveNext method. If ObjectIterator.MoveNext returns TRUE the object can be retrieved by calling Property ObjectIterator.Current. The iterator can be set back in front of the first element by calling ObjectIterator.Reset.

Example

Following example iterates through all objects in an Object Dictionary an increments a counter.

METHOD CountObjects
VAR_INPUT
END_VAR
VAR_OUTPUT
    udiObjectCount : UDINT;
    udiSubObjCount : UDINT;
END_VAR
VAR
    ObjIterator : _3SCSS.ObjectIterator;
    SubObjIterator : _3SCSS.SubObjectIterator;
    itfCurObj : _3SCSS.IODObject;
    itfCurSubObj : _3SCSS.IODSubObject;
END_VAR

//Link Object Iterator to Object Dictionary
ObjIterator.ObjectDictionary := _itfOD;

//Go through all objects
WHILE ObjIterator.MoveNext() DO
    itfCurObj := ObjIterator.Current; //Note: No NULL check necessary here because MoveNext returned TRUE.
    udiObjectCount := udiObjectCount + 1;

    //Link SubObjIterator with current Object
    SubObjIterator.Object := itfCurObj;

    //Go through all SubObjects
    WHILE SubObjIterator.MoveNext() DO
        itfCurSubObj := SubObjIterator.Current;
        udiSubObjCount := udiSubObjCount + 1;
    END_WHILE
END_WHILE

Properties:

Methods:

Structure: