If you try to put an OBJ clause in a child that uses the parent object you will get a "circular reference" error.
Long answer, I bet someone here has figured out a way to do it.
My answer. Even if there is a way to do it you probably don't want to, it is likely to be an unfathomable hack:) There must be a better way to structure you code.
You could add the wanted logic to the child application. Then you would have two copies of the code, not good. How about abstracting the logic to make a new object that can be shared between the parent and child.
I have a simple method for calling a number of spin routines from an assembly language routine.
I define a single variable in the spin routine that the assembly language can write to.
Then in the spin routine, I have a routine that is periodically called. In that routine, there is a case statement looking for that variable. Depending on the value of the variable, it calls a particular routine and stores the results where needed. When it finishes, it clears the variable.
The assembly routine just waits until the variable is cleared, then resumes operation, just as if it had called the routine.
Please let me know if you would like code examples.
That technique is used in several objects posted in the OBEX that use multiple cogs, and it works very well. However, Bruce is asking about calling a method in a parent object from a child object in the same cog, which is a different problem. I've encountered this problem in the past, and resolved it by moving the method from the parent object to another child object.
As was pointed out to me, although I was aware of the potential problem, if this object were used for highly repititious transmissions, there would be a race condition for getting the available data out and overwriting the available data. In it's current state, the parent object would have to get the data out before a new transmission is received. Even though this will work for me, I believe it would be a much better object for all people if a solution were provided.
The parent creates a child item, the child item creates a cog, the cog updates two variables, the parent needs these updated variable values but must get the information before the cog updates the variables again. That is the problem in a nutshell. However, the nut inside has taken roots, and gone a little deeper. Still thinking about this one.
I just got a message pertaining to this article yesterday. Reading it is definitely on my to do list. I am currently studying microsoft serial communication protocol, but I will get to that issue shortly. However, thanks for pointing me in the right direction.
Comments
If you try to put an OBJ clause in a child that uses the parent object you will get a "circular reference" error.
Long answer, I bet someone here has figured out a way to do it.
My answer. Even if there is a way to do it you probably don't want to, it is likely to be an unfathomable hack:) There must be a better way to structure you code.
Well of course you can pass pointers to data from the parent to the child and in that way the child has a means to access data within the parent.
I would be interested in learning more if you have the time to provide the details.
Bruce
I do not have a real definition for my problem yet, but I would like input on this subject.
Bruce
Thanks for that information. I will take a peek at it in the very near future.
Bruce
The link to the thread for this information is a dead link. Can you repair this link please?
Bruce
I define a single variable in the spin routine that the assembly language can write to.
Then in the spin routine, I have a routine that is periodically called. In that routine, there is a case statement looking for that variable. Depending on the value of the variable, it calls a particular routine and stores the results where needed. When it finishes, it clears the variable.
The assembly routine just waits until the variable is cleared, then resumes operation, just as if it had called the routine.
Please let me know if you would like code examples.
Jim
That technique is used in several objects posted in the OBEX that use multiple cogs, and it works very well. However, Bruce is asking about calling a method in a parent object from a child object in the same cog, which is a different problem. I've encountered this problem in the past, and resolved it by moving the method from the parent object to another child object.
Dave
Thanks for clarifying that for me.
Has anyone answered your suggestion, about passing a pointer for the parent routine to the child routine and calling it that way?
Or have you tried it? Shouldn't this also work for variables?
It seems like this is almost equivalent to linking back to the parent.
Jim
Here is the situation.
In another post ->http://forums.parallax.com/showthread.php?129118-Looking-for-suggestions-pertaining-to-new-object<- , I have an object that I am working on. If you like you can take a peak at the source code. Anyhow the problem is described as such within the primary post:
The parent creates a child item, the child item creates a cog, the cog updates two variables, the parent needs these updated variable values but must get the information before the cog updates the variables again. That is the problem in a nutshell. However, the nut inside has taken roots, and gone a little deeper. Still thinking about this one.
Bruce
I just got a message pertaining to this article yesterday. Reading it is definitely on my to do list. I am currently studying microsoft serial communication protocol, but I will get to that issue shortly. However, thanks for pointing me in the right direction.
Bruce