Shop OBEX P1 Docs P2 Docs Learn Events
How to self replace a program in BS2 ? — Parallax Forums

How to self replace a program in BS2 ?

dinocogdinocog Posts: 3
edited 2005-04-28 15:26 in BASIC Stamp
Hello all, i've read the Application Note #16 of BS1 about self replacing program. I know that the BSAVE command is no more supported by the 1.33 editor and i can create an obj file from the editor. I think that the file created by the editor cannot be used from a program language that read the bytes from the file and send them to BS2. So, how can overvrite a runnig program with another from the PC ?

Thank in advance, Dino

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-04-28 14:24
    Dino,

    ·· The new editor supports creating a Stand-Alone module that can re-program any of our BASIC Stamp modules, as long as properly connected to the PC.· That is, you will need a serial connection, with the BS1 adapter connected to the host PC to run the module.· Simply select Generate Stand Alone EXE from the Generate Object Code... window.




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • dinocogdinocog Posts: 3
    edited 2005-04-28 14:49
    Thank you, Chris. I know this feature of the editor, but what i would like to realize is dynamically substitute the running program with another without the help of the user.
    I imagine a bs2 program that run and under certain occurrences talks with a PC program (in my case a LabView program) that reads a BS2 object file from disk and sends the tokens to bs2 in such a way that the second program overwrite the first.
    This is how the #16 Application Note seems to function (if i correctly understand).
    I don't know how to use the object file created by the editor with Generate Object Code..., with my Labview program. I see that the dimension of the file is more large of what the BS2 can use. I suppose that inside the obj file created by the editor there are a lot of informations that are not directly connected to the BS2 tokens.
    Thank very much for the answer.
    Dino
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-04-28 15:11
    Dino,

    ·· I see now that you are trying to do a trick from the BS1 on the BS2.· The fact is, at the time the App Note was written, the BASIC Stamp 1 could only be programmed through the LPT port, so this trick was a neat way to get data to the BS1 through the Serial Port without a loader.· However, if you notice the start code on both programs had to be the same.· With only 256 bytes of EEPROM this would also seriously bite into an already small program space.

    ·· Now, on the BS2, you could probably do something similar, but what I would recommend instead would be to use a Stamp Module, such as the BS2sx or BS2p which have 8 different program slots.· You could write the different programs in different slots, and use serial data to help transfer program control from one slot to another.· This would probably be the easiest way to go about getting similar results.

    ·· If there's a need to alter DATA within the program, that's much easier to do via serial than changing the entire program without the Stamp loader.· One more thing to consider about the original idea...The Stamp still needs to be connected to a PC, and so in that case you really could still just use a stand-alone Stamp Loader, unless there's something else specific you're trying to accomplish.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-04-28 15:11
    If you look in the downloads section at the Parallax web site, under the section on the tokenizer, there are the pdfs for the programming protocol. Our Stache module www.emesys.com/stache.htm uses that algorithm to reprogram the Stamps. I'm not sure if they included information there about how to extract the bytes of code from the object file.

    Another approach would insert a little loop in your programs, invoked with a special pin state or secret RS232 command, that READs the tokens from the 2k of memory and transmits them back to your PC, where you capture them in a file. Then go the other way, like app note #16, to overWRITE a running program with a new one.

    It is especially easy with the BS2p, pe, or px, which have the STORE command that allows you to READ and WRITE data into one bank from a program running in a different bank. So a program running in bank zero can READ and transmit back all the program bytes in bank 1 to labview, or vice versa, it can WRITE them and then RUN the new code. I've used that technique over a modem link.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • dinocogdinocog Posts: 3
    edited 2005-04-28 15:26
    I want to thank you Chris and Tracy for your answers. I see that the simplest way is to use BS2p and so on. I will continue to investigate and study about your directives.
    Many thank, dino
Sign In or Register to comment.