Shop OBEX P1 Docs P2 Docs Learn Events
Transferring data between objects — Parallax Forums

Transferring data between objects

LuckyLucky Posts: 98
edited 2011-02-23 09:46 in Propeller 1
Hi, I am new to the propeller and· I· am not use to the spin language. I was wondering how one goes about transferring data such as a variable from one object to another? Do you use the DAT command to write it to main memory? Can anyone post some code where one object refers to another object's method and then returns a value to the caller object?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-03 06:16
    Let's say you have a main program called mainprog.spin and that program has an object declaration in it like 'OBJ lower : "myObject"'. Let's say you have a variable in 'myObject' called 'important' which is declared like 'VAR long important'. The easiest way to refer to this variable in your main program is to define two methods in 'myObject' like this:
    PUB getImportant
       return important
    
    PUB setImportant(value)
       important := value
    


    You can then get the value of 'important' by writing 'lower.getImportant' and you can set the value of 'important' to 6 by doing something like 'lower.setImportant(6)'

    Similar things can be done with other variables which can be longs, words or bytes. You can also create a method in 'myObject' that returns the address of a variable and use that in your main program to reference the variable.
  • LuckyLucky Posts: 98
    edited 2010-01-03 06:28
    Thank you so much for the quick and easy to understand reply.
  • SarielSariel Posts: 182
    edited 2011-02-23 09:46
    This is simple enough, and I have this working ok for passing numeric data, but is there a way of passing text as a variable from object to object? I'm sure that it is not going to be as easy as I would like it to be. The reason for this is I am trying to design a cable tester, and I would like one configuration object containing Rev numbers, assembly numbers, and connection data all in one simple to modify file so that I don't have to muck with modifying the base source code when it comes time to program this device for a different assembly.
Sign In or Register to comment.