Shop OBEX P1 Docs P2 Docs Learn Events
How to use an object in main and in another object — Parallax Forums

How to use an object in main and in another object

henkvbeekhenkvbeek Posts: 11
edited 2006-07-08 07:02 in Propeller 1
I would like to do the following:
I want to use object "Simple_Serial" from main program and the same instance from "MyObj":

Main:
CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

OBJ
  Usart: "Simple_Serial"
  MyObj: "MyObject"

PUB Start                                                             
  Usart.start(-1, 0, 19_200)
  Usart.str(string("Usart object started",13,10))
  MyObj.start




MyObj:
PUB start
  WaitCnt(50_000_000 + Cnt)
  Usart.str("MyObj started",13,10))




Now I get an error on the last line in "MyObj".
When I define the object "Simple_Serial" in "MyObj" I create a new instance.
I prefer to avoid this.

Is there anyone who can help me out.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
What God wants, God gets . . .

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-07-06 22:06
    You could try my callback routines: http://forums.parallax.com/showthread.php?p=593662. With this method, you declare the Simple_Serial object in your top-level program only. Your top-level program would then include a subroutine for sending strings to the usart. You can send a reference to this subroutine to MyObj.start, which MyObj can then call via callback. That way, calls from MyObj to Simple_Serial are made by the top-level program, and MyObj doesn't even have to know that Simple_Serial exists.

    -Phil
  • henkvbeekhenkvbeek Posts: 11
    edited 2006-07-08 07:02
    Thanks, Phil.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    What God wants, God gets . . .
Sign In or Register to comment.