Skip to main content

Event Mechanism

The runtime system uses "events" to communicate events such as the Start/Stop/Reset of the PLC, the occurrence of an exception, and so on. With the "event mechanism", it is possible to receive a message as soon as a selected event has been triggered.

The following application-related events are forwarded:

  • EVT_StartDone

  • EVT_StopDone

  • EVT_ResetDone

  • EVT_ExitDone

  • EVT_AllBootprojectsLoaded

  • EVT_CmpApp_Exception

  • EVT_StateChanged

  • EVT_CmpDevice_InteractiveLogin

  • EVT_CmpMgr_LicenseState

The delivered uds_events.py sample provides the CODESYS_EventHandler class which implements the registration to an event.

This class needs the eventid as well as the componentid of of the event to be registered, which are stored in the liEvents list:

liEvents = {
    "CmpApp_EVT_StartDone" : (0x00000002, 0x10000 + 2),
    "CmpApp_EVT_StopDone" : (0x00000002, 0x10000 + 4),
    "CmpApp_EVT_ResetDone" : (0x00000002, 0x10000 + 6),
    "CmpApp_EVT_ExitDone" : (0x00000002, 0x10000 +  15),
    "CmpApp_EVT_AllBootprojectsLoaded" : (0x00000002, 0x10000 +  25),
    "CmpApp_EVT_CmpApp_Exception" : (0x00000002, 0x00080000 + 28),
    "CmpApp_EVT_StateChanged" : (0x00000002,0x10000 + 43),
    "CmpDevice_EVT_CmpDevice_InteractiveLogin" : (0x0000000E, 0x00010000+ 1),
    "CmpMgr_EVT_LicenseState" : (0x00000001, 0x00010000 + 9)
}

Moreover, a callback function has to be specified which will be called when the event occurs:

def callbackfunction_start(componentid, eventid):
    print("Start event occured")

Within Main, an event is registered as follows and the necessary callback function is specified:

componentid, eventid = liEvents["CmpApp_EVT_StartDone"]
myEventHandler_Start = CODESYS_EventHandler(componentid, eventid, callbackfunction_start)
myEventHandler_Start.start()

Now the callback function callbackfunction_start is called as soon as the runtime system has changed to Start.

The underlying mechanism is shown in the following figure:

_rtslex_img_eventmechanism.png

Usage of the interface only as a member of the Linux codesysuser user group

Yes

Process separation

Yes