Eclipse 4diac Logo design once use everywhere Open Source PLC Framework for
Industrial Automation & Control


External Event SIFB

External Event SIFB

External Events are events in FORTE, which are hidden and can not be seen in 4DIAC. They do not appear as red event lines. They are usually used for Communication between Hardware and Function Blocks. E.g. E_CYCLE is a Function Block that uses this functionality. It registers to the CTimerHandler Class to get External Events in a periodic time.

Recieving External Events

This is an advanced example showing how to make your own timed T-Flip-Flop Service Interface Function Block. It is based on the E_CYCLE Block and works quite the same way. This tutorial shows you how to build it from scratch. Consider that this is just an example that does not follow the IEC 61499 standard.

The Interface

T Flip-Flop as SIFB with integrated Timer. Export the interface to FORTE (*.h and *.cpp files) and include them to your build.

Interface of the T Flip-Flop as SIFB with integrated Timer

Edit the Headerfile

This time we want to create a timed SIFB so we do not inherit from CFunctionBlock. Instead we inherit from CEventSourceFB. A CEventSourceFB can react to External Events. Therefore you should correct the first line of your class declaration like this:

class FORTE_SIBF_T_FF3 : public CEventSourceFB{

In this case we want to get External Events from the included Timer handler. Include the 2 files timerha.h and resource.h and change funcbloc.h to esfb.h. Your include parameters should look like this:

#include <timerha.h> //added #include <resource.h> //added #include <esfb.h> //instead of #include <funcbloc.h> #include <forte_time.h> #include <forte_bool.h>

Then we need a new Constuctor as well as two new private members bool m_bActive; which will indicate that the timed Function Block is currently active and STimedFBListEntry m_stTimeListEntry; which represents the Timer list entry of this timed Function Block.

EVENT_SOURCE_FUNCTION_BLOCK_CTOR(FORTE_SIBF_T_FF3){ m_stEventSourceEventEntry.m_poFB = this; setEventChainExecutor(pa_poSrcRes->getResourceEventExecution()); m_bActive = false; m_stTimeListEntry.m_stTimeOut.m_nLowerValue = 0; m_stTimeListEntry.m_stTimeOut.m_nUpperValue = 0; m_stTimeListEntry.m_nInterval = 0; m_stTimeListEntry.m_pstNext = 0; m_stTimeListEntry.m_poTimedFB = this; m_stTimeListEntry.m_eType = e_Periodic; };

Remove the default constructor FUNCTION_BLOCK_CTOR and replace it with above. This consturctor registers this Function Block as a External Event Listener, that triggers this Function Block if an event occurs. Then the timer list entry is configured.

Edit the Sourcefile

Then you need to edit the executeEvent method. The usual start and stop Events will register this block to the CTimerHandler. Add a new event cg_nExternalEventID, which is defined in CEventSourceFB, and let it set your outputs. This will be triggered if your Function Block receives an External Event.

void FORTE_SIBF_T_FF3::executeEvent(int pa_nEIID){ switch(pa_nEIID){ case cg_nExternalEventID: Q() = !Q(); sendOutputEvent(scm_nEventEOID); break; case scm_nEventSTOPID: if(m_bActive){ CTimerHandler::sm_poFORTETimer->unregisterTimedFB(this); m_bActive = false; } break; case scm_nEventSTARTID: if(!m_bActive){ CTimerHandler::sm_poFORTETimer->registerTimedFB(&m_stTimeListEntry, DT()); m_bActive = true; } break; default: break; } }

Compile FORTE and run it. Test your new Function Block with the tester. If something went wrong, compare your code with the following files.

Sending External Events

To send External Events your Class must inherit from CExternalEventHandler. In the Constructor you must register this class:

m_nExtEvHandID = sm_poDeviceExecution->registerExternalEventHandler(this);

Then you can send External Events with:

if(sm_poDeviceExecution->extEvHandlerIsAllowed(m_nExtEvHandID)){ sm_poDeviceExecution->startNewEventChain(pointerToTargetFB); }

Where to go from here?

Go back to Development index:

Development Index

If you want to go back to the Start Here page, we leave you here a fast access

Start Here page

Or Go to top