Shop OBEX P1 Docs P2 Docs Learn Events
Sharing Data Between Multiple Programs — Parallax Forums

Sharing Data Between Multiple Programs

spainespaine Posts: 51
edited 2006-08-25 20:04 in BASIC Stamp
Is there a way for me to share data between programs?

For example, can I have the program in slot 0 ask for two integers to be entered (say X and Y), and then call another program (slot 1) to do some equation (say addition for the heck of it) place the result into another variable, and return back to program 0. Then Program 0 will display the result variable?

I would imagine this would be simple, but perhaps it is because I'm still a newbie. Any example code someone can show me would be appreciated.

Thanks smilewinkgrin.gif

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2006-08-14 19:17
    Yes, you can do this, but you must realize that all variable space is 'common' between slots. So all variables must be declared identically in each slot.
  • NewzedNewzed Posts: 2,503
    edited 2006-08-14 19:20
    Al banks in your program must have the same pin assignments, constants and variables, all listed in precisely the same order, and they must all be sized the same.· This means each variable in each bank must be the same size but all variables do not have to be the same size.· This will ensure correct passing of variables to other banks.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Do you have a Stamp Tester yet?
    http://hometown.aol.com/newzed/index.html

    ·
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-08-14 19:37
    Actually, only the variable declarations themselves need be identical.· Your pins and constants can be different.· Not to confuse you but if you were really clever, you could even have different variable names in the destination slot and use them and their values properly.· But I wouldn't even try that unless you were a seasoned BASIC Stamp Programmer with lots of experience.· Just copy and paste your variable declarations amongst your program slots and you should be good to go.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2006-08-14 20:15
    You can also pass variables in the scratchpad RAM, using GET and PUT. The scratchpad RAM is shared between all the slots.

    If you have a BS2p, pe or px, you can easily pass parameters via the eeprom as well, using READ, WRITE and STORE. This applicable, for example, if you want the user to enter parameters with a routine in one slot, but the parameters are actually used for actions in another slot.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • spainespaine Posts: 51
    edited 2006-08-14 21:10
    Thanks for all the input everyone. I can hardly wait to get home to try it out this evening. I had considered using the eeprom, but I had never used it before, so I thought I would go with what I new so far (using defined variables). Perhaps the EEPROM or scratchpad RAM would be better.
  • spainespaine Posts: 51
    edited 2006-08-25 18:47
    I now understand in theory how to share variables between programs, but I cannot figure out how to do it in practice. When I read the instructions for 'Run' it states that I can learn more by reading about compiler directives in chapter 3, however, I don't see in that chapter how to download a program to a slot #. I mean, I have alway downloaded and ran from slot 0 before.

    How do you tell the IDE to download the program I'm working on to go to say slot 3?

    Thanks,
    Stephen
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-08-25 19:07
    Stephen -

    Take a look at the $STAMP compiler directive. It does more than you may think it does!
    Both the PBASIC Stamp Manual and the PBASIC Help File explain what you need to do.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • spainespaine Posts: 51
    edited 2006-08-25 20:04
    Found it, thanks!

    If I read this properly, I would simply provide the additional file name within the $STAMP directive of Program 0, for each additional program.

    Such that:
    ' {$STAMP BS2p, NextProgram.bsp, YetAnother.bsp}

    Where NextProgram.bsp is the program that will be running in slot 1, and YetAnother.bsp would run in slot 2.

    Thanks,
    Stephen
Sign In or Register to comment.