Shop OBEX P1 Docs P2 Docs Learn Events
Object Call Syntax? — Parallax Forums

Object Call Syntax?

HumanoidoHumanoido Posts: 5,770
edited 2010-08-30 19:12 in Propeller 1
I'm trying to make the top object call the second file as you can see in the code but having a problem with the correct syntax. How to put the object call into the coginit statements? Thanks in advance.

I think the problem is here in this top object file statement with BlinkLED.

COGINIT (1,BlinkLED, @stack1)   ' Start cog 1, load/run BlinkLED, reserve Stack, pin 0

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2010-08-30 02:18
    Humanoido wrote: »
    I'm trying to make the top object call the second file as you can see in the code but having a problem with the correct syntax. How to put the object call into the coginit statements?
    Are we running in circles here? You have to specify a local method for cognew/coginit, you can't use calls like object.method in there. All discussed in this thread.
  • HumanoidoHumanoido Posts: 5,770
    edited 2010-08-30 03:21
    kuroneko wrote: »
    Are we running in circles here? You have to specify a local method for cognew/coginit, you can't use calls like object.method in there. All discussed in this thread.
    I feel like a dog chasing my tail in a spin. In that thread, the program was calling the object in the same program. This new program should call the object in the second file. On page 81 of the Propeller manual v1.1 it talks about this but as you can see their PRI Method example is with the top object and not an outside call as implied in the text. Are there some working real world examples of this somewhere?
  • kuronekokuroneko Posts: 3,623
    edited 2010-08-30 04:08
    Humanoido wrote: »
    I feel like a dog chasing my tail in a spin. In that thread, the program was calling the object in the same program. This new program should call the object in the second file.

    That's exactly what this method does in the context of a new SPIN cog (5th posting in that thread).
    PRI launch(ID)
    
      client[ID].start
    

    Alternatively you could call a generic method on all objects and said method starts a new cog with a local method, e.g.
    ' file one
    OBJ
      object[8]: "two"
    
    PUB main : n
    
      repeat 8
        object[n++].start
    
    ' file two
    VAR
      long stack[20]
    
    PUB start
    
      cognew(private, @stack[0])
    
    PRI private
    

    However, you'll have to figure out a way of specifying the cog ID to be used (e.g. by passing a parameter to the start method). Keep it simple!
  • StefanL38StefanL38 Posts: 2,292
    edited 2010-08-30 10:25
    I wouldn't use coginit,

    as with the command coginit YOU as the coder have to specify a cog-id and
    then take care ALL the time which cog is used and which not.

    If you always use cognew the interpreter takes care of the cog-id
    cognew it and forget it except for running out of cogs

    best regards

    Stefan
  • kuronekokuroneko Posts: 3,623
    edited 2010-08-30 19:12
    StefanL38 wrote: »
    I wouldn't use coginit, ...

    So why don't you provide us with a cognew based solution then? Preferably one which can cope with any eventuality (like more then one active cog at the time of the call, the OP doesn't explicitly exclude that case).
Sign In or Register to comment.