Shop OBEX P1 Docs P2 Docs Learn Events
the "file" command — Parallax Forums

the "file" command

SovrSovr Posts: 12
edited 2010-10-31 06:38 in Propeller 1
hello everyone I am attempting something that has never really happened before, in robotic history (as far as I know). The thing I am attempting is to have a robot connected to a computer (USB) that has a virtual program (dark basic) and it will have the virtual robot in that world (with other robots and obstacles) to do several different tasks. When the robot is done being used that program will rearrange .spin source code and apply info to a .txt file for the propeller to read, so in a way the robot thinks and applies that info to the next time it turns on. In a way it sort of evolves. I could talk a lot more about this but anyways I need to figure out how to use the file command within the propeller to finish this project... can anyone give me an idea on how it works, thank you in advance!!

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2010-10-30 15:10
    The file command simply reads the file and puts the bytes it finds in there to the place where the file command is used.
    In other words, the file is put inside of your HUB-RAM-image.

    I guess file has to be used in a DAT-section - I think I never tried it so far ;o)

    PS: If I understand you right a german computer magazine did something similar already. They developed a robot and a virtual robot including a virtual environment. The program you wrote for the robot could be run on both, the real and the virtual robot.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-10-30 15:48
    The file command came up in a recent thread. Apparently, this has to be a binary file, and the bytes are just inserted into the memory image of your program in your DAT section. It's not at all like the #include statement that other languages provide (unfortunately).

    -Phil
  • potatoheadpotatohead Posts: 10,261
    edited 2010-10-31 01:24
    Well, I don't know that it has to be a binary file, only that the "file" command will treat that file as a binary one.

    It will then put the contents of that file, in the program image, addressed at whatever label is assigned to the file.

    If one has built up a cog image, such that it can be loaded into RAM, and executed with a cognew, then it's a simple way to include a driver, or something into a project, as well. Nice way to simulate reading from SD card, or as a check on that, for example.

    Declare a buffer, then use "file" to fetch a binary, and cognew it. Then, once it's all playing nice, happy, do it again from SD, with the same file.

    Another use is for graphics assets and such. It's pretty easy to pack things into a file, then make use of them in the program with offsets of different kinds.

    This is a very nice way to insert graphics, without having to encode them for DAT section storage the hard way. A bitmap file, could be loaded this way, header ignored, with the program consuming the graphics data directly. Open bitmap in editor, change pixels, save, hit F10...
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2010-10-31 06:38
    The other way I use the FILE command is to embedded text in the program but reference the text as a normal text file. That way it's easy to edit etc.
    DAT
    HELP
            FILE  "HELP.TXT"
            byte  0
    
Sign In or Register to comment.