Shop OBEX P1 Docs P2 Docs Learn Events
how to return several bytes from another object — Parallax Forums

how to return several bytes from another object

Sabre00Sabre00 Posts: 30
edited 2008-10-06 15:05 in Propeller 1
I have tried to "modularize" or in propeller case "object-terise" my application code. I have a situation where am reading 6 bytes from an external device in a child object and I would would like to return these 6 bytes to the main object. I tried making the parent object a child of the child but I got a cyclic call error. that didn't work.

I have the bytes saves in an array and when I use the RETURN Arrayname and that didn't seems to work either.

I was trying to see if I could alter the values of a mirror array within the parent object but I can't seem to figure out how to do that just yet. if it even is possible.

my question is is it possible to return from a child object multiple bytes?

while writing this I thought about using the COG RAM to store data where it can be seen from all objects. is that the answer?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-04 13:21
    There are two schemes for passing multiple bytes of data from one object to another. The caller can pass the address of an area to use or the child object can return the address of a local area where the result is stored. The advantage of the first scheme is that you can easily have several result areas and the caller can decide which one to use for what purpose. The second scheme is easier when the child object is doing most of the work with the result field. An example of this is the Numbers object from the Object Exchange where the address of a string buffer is returned. For the first case, if you have a result area called MyResult, you'd call myObject.operation(@MyResult, other parameters). Inside myObject, if the parameter is called workAddress, you'd reference parts of it with LONG[noparse][[/noparse] workAddress ][noparse][[/noparse] index ] or something similar.
  • Sabre00Sabre00 Posts: 30
    edited 2008-10-06 15:05
    Thanks mike,

    I didn't use your method but I found out another way to get the job done. I am just putting my solution in here so others can see it.

    in the child object where the array is stored I create another PUB where there is one parameter, a count parameter for the array.
    eg.

    PUB GET_ARRAY(counter)

    RETURN arrayname(counter)

    in the parent object I have;

    repeat a from 0 to 5
    parentarray[noparse][[/noparse]a] := child.GET_ARRAY(a)

    once complete I can then use the parentarray values.

    This is with a known array size in this example six. If the size is variable you can just use an end of array character.

    Although this essentially uses up twice as much memory it is a crude way to get around the problem to return values from a child object back to the parent.
Sign In or Register to comment.