Shop OBEX P1 Docs P2 Docs Learn Events
Accessing objects from other objects — Parallax Forums

Accessing objects from other objects

RogerInHawaiiRogerInHawaii Posts: 87
edited 2009-04-25 05:31 in Propeller 1
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

Comments

  • rokickirokicki Posts: 1,000
    edited 2009-04-24 19:47
    If you change all var declarations to dat declarations, then you get a "single copy".

    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
  • mparkmpark Posts: 1,305
    edited 2009-04-25 01:11
    Or you could try Homespun's object-passing feature: http://forums.parallax.com/showthread.php?p=777920.
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-04-25 05:31
    no there is a much easier way

    in the obex is a variant of a serial driver which can be accessed ACROSS objects

    SerialMirror

    best regards

    Stefan
Sign In or Register to comment.