Developer Portal Community

    Showing results for 
    Search instead for 
    Did you mean: 

    Access to SetEvent/SetExtEvent from a self created FB in the project

    Access to SetEvent/SetExtEvent from a self created FB in the project

    Established Member

    Hello together

    Is it possible to get an access to the methods SetEvent/SetExtEvent in a self created method.

    Would be great, getting an example for this. We have a station, which is a rebuild of an old Opcon project and there are function blocks we would like to reuse them. Therefore, we need to set error messages directly from an instance of a function block.

    If there is an easy way to connect a function block to the mode handler, that would be really helpful.

    Thanks in advance.

    1 REPLY 1

    Community Moderator
    Community Moderator

    SetEvent/SetExtEvent aren't global functions but instance methods of OpconUnit. That's why they can only be called in the context of Control plus model tree objects. Apart from that, the methods are also available in sequences deriving from OpconBaseChain, but only because the chains are always owned by an OpconUnit which is used internally for setting the events.

    The main reason why the methods need the OpconUnit context is that every Control plus event has a source object (i.e. an instance ID) telling exactly who created the event.

    You could pass a reference to an OpconUnit into another FB allowing it to call SetEvent on the Unit. But that means the FB is no longer independent from the Control plus infrastructure.

    The more common solution would be to pass a result value with an error code from the FB to the calling OpconUnit (e.g. ModeHandler) and doing all the event handling there.