Shop OBEX P1 Docs P2 Docs Learn Events
How is forth working with files, programs or scripts on the Parallax Propeller P2 — Parallax Forums

How is forth working with files, programs or scripts on the Parallax Propeller P2

AndyPropAndyProp Posts: 60
edited 2024-02-13 09:30 in Forth

Ive been watching a load of videos about forth and kind of getting lost in the subject of most videos being about stacks and math; and few I find about actually doing anything more than flashing some Leds from a single line of code or running single line commands that do other things. I get the idea that it does what you want it to do along the lines of configuring a PLC to automate some tasks; and words are like functions but how about something more normal like an application that is saved as a file on an SD card that gets ran.

This got me wondering how forth uses external programs. Lets say we have a program that is saved as .fth

I know that you can create functions and make them part of the running forth which would be lost at the next power cycle but lets say I want a bunch of applications/functions or words that arnt saved into the tachoz system on flash but instead are files on some media.

How do you go about loading a file and running it. Like one that sends "hello world" to the terminal or one that does a bunch of tasks to be more than one line of code.

Also, is it possible to store such applications on the Flash to be called up by Tachoz

While I am writing, I am thinking about the concept to not tinker with the running Tachoz itself but create external forth scripts that are loaded and ran by the Tachoz, in the usual file system way like we would with Basic

Last one, of course if all the files are stored on lets say SD, and the P2 was power cycled, what would run the first application, basically it needs some user intervention to get rolling, does Tachoz look for some specific file/word on the lines of Autoexec.bat

This subject is likely very useful for others also looking at forth and Tachoz.

Anyone can enlighten this a little bit.

Comments

  • bob_g4bbybob_g4bby Posts: 440
    edited 2024-02-13 11:14

    If you want Taqoz to behave more like an operating system which can load, compile and run a program, then discard it; have a look at 'Run SD card command' on my Forth Stuff Github site. If an unknown word is typed in, forth no longer complains about it, it goes off and finds a file on sdcard of the same name. If that exists, it loads the contents, as if it were typed in. This could be a complete forth program, which is then run until it terminates, at which point it is forgotten again. Just like DOS or CP/M used to do. Here's a trivial program (file on sdcard named whatever you like) that my Batch File code could handle:-

    : TEMP-PROG ." Hello World!"  ;     --- here's the program definition
    TEMP-PROG                                      --- here's where the program is run 
    FORGET TEMP-PROG                       --- forth is told to forget all code including and after this word in the dictionary 
    

    ( In reality a forth program would be many definitions, ending in the top level word that is the program )

    Storing on Flash, instead of SD-card would be possible, but I haven't explored doing it that way. SD-card has a lot of advantages for a product, not the least being easy firmware update. Worth it for the price of an SD card socket.

    You can load such files onto the SD card using a P.C. and Taqoz can read those just fine.

    Here's the original thread on this topic.

    To autostart a user program from source code (as above) see page 33 of my 'Taqoz Reloaded V2.8 Glossary of Words'

    Cheers, Bob

  • @bob_g4bby said:
    If you want Taqoz to behave more like an operating system which can load, compile and run a program, then discard it; have a look at 'Run SD card command' on my Forth Stuff Github site. If an unknown word is typed in, forth no longer complains about it, it goes off and finds a file on sdcard of the same name. If that exists, it loads the contents, as if it were typed in. This could be a complete forth program, which is then run until it terminates, at which point it is forgotten again. Just like DOS or CP/M used to do. Here's a trivial program (file on sdcard named whatever you like) that my Batch File code could handle:-

    : TEMP-PROG ." Hello World!"  ;     --- here's the program definition
    TEMP-PROG                                      --- here's where the program is run 
    FORGET TEMP-PROG                       --- forth is told to forget all code including and after this word in the dictionary 
    

    ( In reality a forth program would be many definitions, ending in the top level word that is the program )

    Storing on Flash, instead of SD-card would be possible, but I haven't explored doing it that way. SD-card has a lot of advantages for a product, not the least being easy firmware update. Worth it for the price of an SD card socket.

    You can load such files onto the SD card using a P.C. and Taqoz can read those just fine.

    Here's the original thread on this topic.

    To autostart a user program from source code (as above) see page 33 of my 'Taqoz Reloaded V2.8 Glossary of Words'

    Cheers, Bob

    Cheers Bob but a point or understanding is missing,

    I realize that you pretty much program the P2/Tachoz just like you would a PLC giving it instructions and then save them in Taqoz to perform that forever or on tap as required but what I saw so far is: if you make something and want to change it later, then it requires to do it all over again. What do you do in that situation.

    If you create a function that carries out a process and that process isnt quite right, you should make a new one? or edit an existing one?.

  • bob_g4bbybob_g4bby Posts: 440
    edited 2024-02-13 16:19

    I don't think Taqoz is any different from your PLC example in that respect. Taqoz is an interpreter program, like the interpreter in the PLC. If the application program or script has bugs, well that needs reprogramming into the hardware and the product retested to check the bugs are gone. That would involve either reprogramming the Flash chip or the SD card, it depends where you've got Taqoz and the application stored.

    The forth source code is usually re-edited to fix bugs. The application source code is sent to the input terminal of the basic Taqoz system and the fixes tested. If all the bugs are fixed, then:-

    1. If everything is stored on Flash, then you've got to handle the user's hardware to reprogram that flash - a site visit or product recall is needed.
    2. If the user program is stored on SD card like we've discussed above, then the new source code could be emailed or a programmed SD card mailed to the customer - if he is savvy enough to deal with it.
  • @bob_g4bby said:
    I don't think Taqoz is any different from your PLC example in that respect. Taqoz is an interpreter program, like the interpreter in the PLC. If the application program or script has bugs, well that needs reprogramming into the hardware and the product retested to check the bugs are gone. That would involve either reprogramming the Flash chip or the SD card, it depends where you've got Taqoz and the application stored.

    The forth source code is usually re-edited to fix bugs. The application source code is sent to the input terminal of the basic Taqoz system and the fixes tested. If all the bugs are fixed, then:-

    1. If everything is stored on Flash, then you've got to handle the user's hardware to reprogram that flash - a site visit or product recall is needed.
    2. If the user program is stored on SD card like we've discussed above, then the new source code could be emailed or a programmed SD card mailed to the customer - if he is savvy enough to deal with it.

    Thanks Bob,

    I am only writing about development environment, not deployment.

Sign In or Register to comment.