How do I pass a byte array between objects?
Chemikal
Posts: 32
Evening,
I have, what I think, is going to be a pretty cool XBee object eventually, but I am stuck at something I have never known how to do, and rather than sidestepping it like I usually do, there must be a simple way to do it...
In my XBee object, I am forming a byte array in a "Receive" PUB statement, and I would like to pass it back to the object that originally called the PUB... I was thinking I would send the pointer to the Main object, and then itterate through the remote array and store it to a local byte array before it gets overwritten...
This is what I have right now, trying to get it to work:
Main object: (simplified) - **brackets replaced with {}
XBee object:
Doesn't work. So how do I pass the byte array to the Main object?
Thanks for the help... these XBees are going to be handy soon...
I have, what I think, is going to be a pretty cool XBee object eventually, but I am stuck at something I have never known how to do, and rather than sidestepping it like I usually do, there must be a simple way to do it...
In my XBee object, I am forming a byte array in a "Receive" PUB statement, and I would like to pass it back to the object that originally called the PUB... I was thinking I would send the pointer to the Main object, and then itterate through the remote array and store it to a local byte array before it gets overwritten...
This is what I have right now, trying to get it to work:
Main object: (simplified) - **brackets replaced with {}
VAR byte PacketPtr PUB Main repeat PacketPtr := XB.receive SER.str(CONSOLE,string("PUB: ")) SER.hex(CONSOLE,byte{@PacketPtr}{3},2) 'byte 3 of the packet is $90, which is just one thing I want to retrieve SER.str(CONSOLE,string(10,13)) waitcnt(clkfreq + cnt)
XBee object:
VAR byte API_Packet{200} PUB Receive ... fill the byte array, etc return @API_Packet
Doesn't work. So how do I pass the byte array to the Main object?
Thanks for the help... these XBees are going to be handy soon...
Comments
SER.hex(CONSOLE, byte{PacketPtr+3} ,2)
You don't use the @ sign because the variable's value IS already the address.
ETA: Fixed the goof with the braces.· I think that's right.
Post Edited (photomankc) : 11/5/2009 6:42:59 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
SER.hex(CONSOLE,byte{PacketPtr}{3},2) works now
One more question:
Can I send more than one variable back to the Main Object?
I mean, now that I have the address for the byte array, I would also like to send back the variable that is calculated while it is receiving: the byte array length, but the 'return' statement only takes one argument... I am thinking of just referring to another PUB statement, such as "GetLength" or something, but I think that'd be rather a messy method of doing this...
Any way to send that back as well, or any suggestions?
EDIT: forgot the braces
It would be messy if you pack that information into the return value as well (because currently you only need 16 bit of the 32 bits available). So, you should not use
return @API_Packet + API_Len<<16
;o)
And returning a pointer to an array of return values would be ugly as well.
But we talk about microcontroller programming, so ugly or messy tricks are allowed when you run out of memory. Of course we don't want to see such tricks in official ObEx objects ;o)·
After FillVars executes the values of v1 through v3 should now be 12. It can get confusing when you do that later on down the road if the name of the function doesn't suggest what is going to happen but it's an effective way to get multiple values back from a function.
You don't need to specify the address fro each variable, this can get very messy with large numbers of variables.
Using your example....
This same topic came up between me and one of my co-workers recently...
Attached are two examples of passing variables between COGs without using 'copies' of variables. The first example Var Pass Test is a very simple illustration that uses the DEMO board LED’s, showing how to pass values from one cog to another. The second file Var Pass Test v2 is basically another way of doing what the first file does, but it ensures that the value of the variable can be changed at the source after the DisplayVariables cog has been launched. In other words more of a sanity check to make sure that variables we are working with are ‘live’ and not a copy. There are probably other ways to pass variables from one cog to the next, but this seems to make the most sense to me.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 11/5/2009 3:15:55 PM GMT