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

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.

Best reply by nexidator

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.

View original
5 replies
Resolved