Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » 4DIAC - Framework for Distributed Industrial Automation and Control » Basic FB as Event Source(Configuring an Basic FB so that it can create an event )
Basic FB as Event Source [message #1738384] Tue, 19 July 2016 11:38 Go to next message
Leopold Hiesmair is currently offline Leopold HiesmairFriend
Messages: 4
Registered: July 2016
Junior Member
Hallo,

I started working with the 4Diac Framework a few weeks ago and it worked out well so far.
Last week I created my own Basic FB which uses a self created dll. This dll contains a thread which processes inserted data and calls a defined callback-function in the Basic FB to pass the result to the Output Data and send a Output Event.

Now my Problem:
After the data is inserted into the dll and the thread processes the data, the thread calls the callback function where I send an Output Event. But this Event is only sent, when the FB receives the next Input Event (I think, because the Basic FB is no Event Source).

Does anybody know, who I can configure my Basic FB so that it can create Output Events without having an Input Event ?

Thanks in advance.
Re: Basic FB as Event Source [message #1738555 is a reply to message #1738384] Wed, 20 July 2016 20:08 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 1584
Registered: January 2014
Senior Member

Hi,

great to here that 4diac worked well for you.

In the general architecture of forte it is not allowed for classic basic FBs to act as event sources. However you can take the generated C++ code of your basic FB and adapt it to your needs.

First of all: You must not invoke the function sendOutputEvent from your data processing thread!!!! This can lead to severe race conditions.

What you need is to have an class which inherits from CExternalEventHandler. This class is typically a singleton and would handle the call-back from your dll. In the call back you can then transfer any data to your basic FB (which should now inherit from CEventSourceFB). After that you can invoke CExternalEventHandler's startNewEventChain() function. This function will activate the CEventChainExecutionThread of your FB and will send your FB an inputEvent with the value cg_nExternalEventID. In your FB you can check now for cg_nExternalEventID perform any further data processing update any fb outputs if necessary and then send the according output events.

Unfortunately this is not very well documented sofar. An example you could take as reference is the way how the timing FBs (e.g., E_CYCLE, E_DELAY) are implemented.

I hope this helps. You can also contact me in skype if this not helping.

BR,
Alois





Re: Basic FB as Event Source [message #1738578 is a reply to message #1738555] Thu, 21 July 2016 05:42 Go to previous messageGo to next message
Leopold Hiesmair is currently offline Leopold HiesmairFriend
Messages: 4
Registered: July 2016
Junior Member
Thank you very much for you answer. It already helped a lot for my understanding Smile

I created an inner class (inherits from CExternalEventHandler) in my Basic FB (now inherits from CEvenSourceFB) which handlers the callback function of my dll and sends the Output data to my Basic FB.
But how can I connect these two classes, so that the Basic FB can received the external Event created by the ExternalEventHandler ?

[Updated on: Thu, 21 July 2016 05:48]

Report message to a moderator

Re: Basic FB as Event Source [message #1738582 is a reply to message #1738578] Thu, 21 July 2016 06:48 Go to previous messageGo to next message
Jose Maria Jesus Cabral Lassalle is currently offline Jose Maria Jesus Cabral LassalleFriend
Messages: 199
Registered: February 2016
Senior Member
Hi,

now in your CExternalEventHandler class, when you receive the data from the DLL, you should call the startNewEventChain(CEventSourceFB *pa_poECStartFB) function. The pa_poECStartFB parameter should be your Basic FB that now as you said inherits from CEvenSourceFB. The function will put the the external event (your Basic FB with the ExternalEventID) in the queue of the CEventChainExecutionThread which then takes care of calling the executeEvent function in your Basic FB.

Regards,

Jose Cabral
Re: Basic FB as Event Source [message #1738588 is a reply to message #1738582] Thu, 21 July 2016 07:20 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 1584
Registered: January 2014
Senior Member

To add to Jose's comment, normally we have one instance of an External Event Handler per event source (i.e., your callback function) managing external events for several FBs. Therefore FBs are regsitered at the external event handler during the initialization of the FB. The external event handler can then determine in the call back or in its thread for which FB the external event was and perform the steps as described by Jose.
Re: Basic FB as Event Source [message #1738597 is a reply to message #1738588] Thu, 21 July 2016 08:33 Go to previous messageGo to next message
Leopold Hiesmair is currently offline Leopold HiesmairFriend
Messages: 4
Registered: July 2016
Junior Member
It works Very Happy
Thank you very much for your help Jose and Alois.
Re: Basic FB as Event Source [message #1738607 is a reply to message #1738597] Thu, 21 July 2016 11:15 Go to previous message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 1584
Registered: January 2014
Senior Member

Great Smile
You are welcome!
Previous Topic:FORTE terminate when pressing "Launch local FORTE"
Next Topic:Error in the use of SubApplication
Goto Forum:
  


Current Time: Tue Apr 23 11:12:28 GMT 2024

Powered by FUDForum. Page generated in 0.04036 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top