Accessing objects from other objects
RogerInHawaii
Posts: 87
I have a main object in my project and it references the FullDuplexSerialPlus object so that I can send diagnostic messages out to the Parallax Serial Terminal.·For this, I have the following in my main object:
OBJ
· SerialTerminal· :······ "FullDuplexSerialPlus"
and I properly Start the object and it works fine for sending my diagnostics out to the serial terminal.
But my main object also makes reference to and calls methods within OTHER objects. I want to be able to send diagnostic messages to the Serial Terminal from THOSE OTHER objects as well, not just from the Main object. How can I do that? How can I reference the SerialTerminal object that's declared within the Main object from within any of those other objects?
Can I simply also declare the SerialTerminal, as above, within the other objects and use it within those other objects? I've tried a few approaches to accomplish this but I get garbage text out on the Serial Terminal when I make calls from those other objects.
In general, when an object is declared within, say, the main object, and it's also declared within other objects is there really only one such object loaded into memory and all references to it, no matter from what other object, actually refer to that single loaded object? Or does each declaration of the object, in multiple other objects, create its own instance of the object?
- Roger
OBJ
· SerialTerminal· :······ "FullDuplexSerialPlus"
and I properly Start the object and it works fine for sending my diagnostics out to the serial terminal.
But my main object also makes reference to and calls methods within OTHER objects. I want to be able to send diagnostic messages to the Serial Terminal from THOSE OTHER objects as well, not just from the Main object. How can I do that? How can I reference the SerialTerminal object that's declared within the Main object from within any of those other objects?
Can I simply also declare the SerialTerminal, as above, within the other objects and use it within those other objects? I've tried a few approaches to accomplish this but I get garbage text out on the Serial Terminal when I make calls from those other objects.
In general, when an object is declared within, say, the main object, and it's also declared within other objects is there really only one such object loaded into memory and all references to it, no matter from what other object, actually refer to that single loaded object? Or does each declaration of the object, in multiple other objects, create its own instance of the object?
- Roger
Comments
This requires modifying the object, of course.
I would prefer the ability to declare an object to be a "singleton" and/or declare
"var" variables as "static", but neither exists in the current prop tool.
In any case, this conversion is fairly straightforward.
Of course, just to be clear, this allows one object to be accessed by other objects
in the same cog---but if you start new cogs, the concurrency implications do not go
away . . .
-tom
in the obex is a variant of a serial driver which can be accessed ACROSS objects
SerialMirror
best regards
Stefan