Calling a function from an outside object misbehaviour
Henk van Beek
Posts: 11
My main program (Top object) has two objects:
Tst1 with an assembly part in a separate cog
Tst2 within the main program.
The interresting function resides in Tst1 which write 5 into funct. and wait 10 seconds.
The assembly part in Tst1 is clearing constantly Funct to zero.
This works when called from main but not when called from Tst2.
There is a blinking LED in the assembly part which blinks in both cases.
But when called from Tst2 it will not clear Funct.
Comments
You cannot count on others having all of the objects that you're using. Please include all objects in your archive so that others can properly review your code.
That said, Test2 is calling Test1.Write which uses the Term object which has not been instantiated in Test1.
Sorry Jon,
Hereby all files included.
As far I can see Term is mentioned in Tst1.
Hopefully waiting,
Henk from Breda, Holland
Sorry Jon,
Hereby all files included.
As far I can see Term is mentioned in Tst1.
Hopefully waiting,
Henk from Breda, Holland
With respect, I find this code a bit convoluted and am struggling to determine your ultimate goal. Can you explain in terms that someone in Hollywood (no brain surgeons here) can understand?
If your goal is to have a shared control value that may be accessed by any cog, I suggest you setup that value in your parent application (top cog) and then pass its address to any cog that might need to monitor or change it.
OK, I will do that.
Thanks.
@Jon: After one day I'm dissapointed by your answer.
I have taken efforts minimizing the problem as simple and clear as possible.
So I repeat my question: Why is var Funct in Tst1 cleared when called from main and not when called from Tst2.
In both cases assembly part is running showed by the blinking LED.
I will spare you future disappointment by adding you to my IGNORE THIS USER list.
Here's what's happening... You have two copies of the Test1 object in RAM which means there are two different Funct variables in RAM as well (RAM is unique for every object, only code and DAT values are common). When your program starts you call Tst1.Load which passes the address of Main/Tst1/Funct to the blinker cog which clears that variable. When you call Test2.W5 you are actually using the Main/Tst2/Tst1/Funct variable which has a different address than the one passed to the blinker cog.
The problem is very subtle -- but SOLVED by my original solution: Put the common address in your top object and pass its address to the cogs/objects that need it. You could also put Funct into a DAT section which would make it shared across objects. I verified that change -- while not the best approach in my book -- does work.
Welcome to my IGNORE list.
Henk
If you include the object 'Test1' in Tst2 you generate another instance of Test1, with a new variable 'Funct'.
Because you startet the Load methode only for the first instance the Assembly code clears that first instances 'Funct' variable.
If you want that the 'Funct' variable exists only once, you need to declare it in the DAT section, not in a VAR section:
Andy
Thanks you both.
Now it's clear.
Henk