Communication between module and mainLine
eddymouse
Posts: 67
Can I call a function defined in the main program inside a module?
How?
Thanks
alex
How?
Thanks
alex
0
Comments
MODULE
MAIN PROGRAM
Similar, but reversed, use send_command to send data TO a module FROM the main program.
If you mean a direct call from with in a module of a function that is not part (inside) of the module then no. Just putting the function call in the module will cause it to not compile because it is not defined with the scope of the module and can't be passed as a parameter to it.
Simple remedy is to copy and paste the needed function into the module or do it as an include which is affectively the same. Now this is fine providing what you want the function to act upon (devices or variables) are defined, reference or passed to the module. Sometimes that's not all that practical to do so you may need to do what Colzie suggests and create a virtual in the main code and pass that virtual definition as a parameter to the module and then create a data_event for that virtual in both the module and main code and pass what ever you want back and forth. Of course this would not be a direct function call but a string that you would look for to initate the function call as well as any parameters you want the function to work with from the module.
Confused yet?
ciao
Alessandro