Shop OBEX P1 Docs P2 Docs Learn Events
Objects and Cogs — Parallax Forums

Objects and Cogs

KokovecKokovec Posts: 14
edited 2009-07-04 03:23 in Propeller 1
Here's a newbie question...

Is it possible to initialize a cog in one object and then access that same cog in another object?
For instance:

"Main" object starts SPI object in COG1
"Client" object uses SPI object in COG1 to send out a byte.

I'm sure this has been iscussed before but I have not been able to find a thread to answer this question.
·

Comments

  • jazzedjazzed Posts: 11,803
    edited 2009-07-03 20:57
    As long as variables used by the lower level object are in a dat section, you should have no problem just including that object in main and client objects and using SPI receive, etc in both objects. A limit is that only one object should "start" the lower level object. Of course, if you have two different COGs objects trying to use the same lower level object, you may up with interference in the dat with indeterminate results on the interface (to get over that, you'll have to use locks).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230
  • KokovecKokovec Posts: 14
    edited 2009-07-03 21:11
    OK, I see.

    What about if I wanted to use an object from the library.

    Can I start COG1 in "Main" with the TV_Text object and then have the "Client" object send out a character using the same COG?

    Does that make sense?

    Dan
  • jazzedjazzed Posts: 11,803
    edited 2009-07-03 21:38
    Usually you have to make some changes. I've attached a Tv_Text example for you.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230
  • KokovecKokovec Posts: 14
    edited 2009-07-03 21:42
    Cool. I get it now.

    Thanks for your help!

    Dan
  • phil kennyphil kenny Posts: 233
    edited 2009-07-04 02:51
    @jazzed,

    As one who is just learning the Spin language, I have a question about
    some of the syntax you used in xObjectTest.spin.

    The ascii strings, "Hello", "Hello1" and "Hello2" are followed by
    sd.

    What is the significance of sd?

    I thought the text string was supposed to be terminated by zero.

    phil
  • jazzedjazzed Posts: 11,803
    edited 2009-07-04 03:08
    The character $d (13 decimal) makes a new line for TV_Text and friends. The 0 is appended after the $d.

    Syntax for string(...) allows all kinds of constants in any order i.e. string("line",$d,"newline",$9,"tabbed word",$d).
    It's kind of like "character-coding" .... In the case of TV_Text.str(...) codes can be used to change colors or
    reposition characters, etc... since the str() method calls out() and out "interprets" the character codes (ASCII).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230
  • phil kennyphil kenny Posts: 233
    edited 2009-07-04 03:23
    jazzed,

    Thanks.

    When I first looked at it in the Propeller Tool, it was hard to see
    that the character was a dollar sign and not simply 's'. Makes sense
    now.

    phil
Sign In or Register to comment.