passing array`
Rob v.d. berg
Posts: 81
Hi,
Can someone help me with this, how·can to pass an array from·one object to an other.·here a test example in one object.
The mess array has to be·the same as the message array
Rob
CON
· _CLKMODE····· = XTAL1 + PLL16X··
· _XINFREQ····· = 5_000_000
·
· pcDebugTX···· = 30
· pcDebugRX···· = 31
· pcDebugBaud·· = 115200
··
VAR
· long message[noparse][[/noparse]4]
OBJ
· debug········ : "Debug_PC"
···
PUB Main
· debug.startx(pcDebugRX,pcDebugTX,pcDebugBaud)
·
· message[noparse][[/noparse]0] := false '0
· message[noparse][[/noparse]1] := true· '-1
· message[noparse][[/noparse]2] := false '0···
· message[noparse][[/noparse]3] := false '0
· ReceiveArray(@message)
'can be placed·in an other object·
PUB ReceiveArray(mess) | i
·
· i := 0
· repeat 4
··· debug.str(string("Array mess[noparse][[/noparse]"))
··· debug.dec(i)
··· debug.str(string("]: "))
··· debug.dec(mess[noparse][[/noparse]i])
··· debug.putc(13)
··· i++
·
Can someone help me with this, how·can to pass an array from·one object to an other.·here a test example in one object.
The mess array has to be·the same as the message array
Rob
CON
· _CLKMODE····· = XTAL1 + PLL16X··
· _XINFREQ····· = 5_000_000
·
· pcDebugTX···· = 30
· pcDebugRX···· = 31
· pcDebugBaud·· = 115200
··
VAR
· long message[noparse][[/noparse]4]
OBJ
· debug········ : "Debug_PC"
···
PUB Main
· debug.startx(pcDebugRX,pcDebugTX,pcDebugBaud)
·
· message[noparse][[/noparse]0] := false '0
· message[noparse][[/noparse]1] := true· '-1
· message[noparse][[/noparse]2] := false '0···
· message[noparse][[/noparse]3] := false '0
· ReceiveArray(@message)
'can be placed·in an other object·
PUB ReceiveArray(mess) | i
·
· i := 0
· repeat 4
··· debug.str(string("Array mess[noparse][[/noparse]"))
··· debug.dec(i)
··· debug.str(string("]: "))
··· debug.dec(mess[noparse][[/noparse]i])
··· debug.putc(13)
··· i++
·
Comments
So, in your other method you want read from the locations pointed to by the address you passed in. Mess is an address, not an object. Read the prop manual about the methods Byte[noparse]/noparse Word[noparse]/noparse and Long[noparse]/noparse which let you access any element in memory if you know its base address and an index.
So to read from the memory address pointed by @message you passed into your second object, try this...
Just remember that once you use the @ symbol, you're no longer dealing with a variable in local memory, just a pointer to memory address. It becomes more clear when you read about how the assembly operations work.
Post Edited (mcstar) : 12/12/2008 12:54:37 PM GMT
debug.dec(·long[noparse][[/noparse]mess+i])··'·<-·change·here.
after reading the manual, i tray this:·debug.dec(long[noparse][[/noparse]mess][noparse][[/noparse]i]) and is was working
thanks.
Rob
If you use this: "long[noparse][[/noparse]mess+i]", the compiler adds "mess" and "i". This only works when "i" is a multiple of 4 since addresses in Spin are byte addresses and all longs have to be aligned on a 4 byte boundary. Words have to be aligned on a 2 byte boundary.
clear thanks.
Rob.
I·understand, thanks for your input
rob