Passing bytes from parent to child object question
Don M
Posts: 1,652
in Propeller 1
In my parent object I have a 4 byte array.
Var
byte Buff1[4]
And in my child object I also have the same.
VAR
byte Buff2[4]
Lets say in the parent object I want to pass all the contents of Buff1 to the child objects Buff2.
In the parent object method I do this...
PUB Some method
ChildObject.Transfer(Buff[0], Buff[1], Buff[2], Buff[3])
In the child object I have a method called Transfer and receive the 4 bytes to Buff2 in the child object.
PUB Transfer(data1, data2, data3, data4)
Buff2[0] := data1
Buff2[1] := data2
Buff2[2] := data3
Buff2[3] := data4
This works for me but was wondering if there is a simpler way to send the Buff1 as a whole to the child objects Buff2?
Comments
Do you always want to use the "same" buffer for both objects?
If yes, just put them once in a DAT and pass the address as a pointer to the child object.
Easy-peasy. This method is in the child object, but called from the parent.
Call it like this:
Another thought is you could just pass the address of buf1 to the child during setup. This would allow the child object use buf1 without the explicit transfer requirement. Instead of this:
... you would do this:
In the second case the variable p_buf is a pointer to buf1. This was passed to the child during setup.