Shop OBEX P1 Docs P2 Docs Learn Events
Open file for read/write? — Parallax Forums

Open file for read/write?

PaulFPaulF Posts: 62
edited 2008-03-28 23:05 in Propeller 1
Hi,
I am trying to develop my first propellor application. The app needs to send upwards of 1 million 'commands' to a controller on a packaging line. The propellor needs to send the commands to the controller at a rate of at least 10 commands (each command is 11 bytes) per sec. I had originally planned to use a thumb drive via the VDrive unit. A text file containing the commands would reside in the thumb drive. I can get the propellor to easily achieve 20 codes per sec, however my problem is that I also need to keep track of the last code sent to the controller to enable the propellor to restart from the correct location in the file.
My solution to keep track of the last command was to either have a second file to which I write the index of the last command printed or else append the data to the file containing the commands. Either of these solutions introduces a considerable delay into the app., allowing me to send only 5 commands per sec. This delay is due to opening the file for read to get the command, then closing the file and reopening for write to write the index etc etc.
Another possibility is to write the index to the eeprom but this I believe would very quickly burn out the eeprom.
Is there any way to open a file for read and write?
Sorry for the long post, but I felt it would be helpful to present the whole scenario.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-28 17:58
    You could still store the restart point in the EEPROM. The limit on the number of times a write can occur is on a "per location" basis. If you create a table of 100 entries, each a long and place this at the end of the Prop's EEPROM, you would have only 10,000 writes per location to get 1,000,000 command restart points. Assuming that the file position is monotonically increasing, you can initialize the table once to zeros. When the program starts, it searches the table for the highest value entry and uses that. When it's time to write a new entry, it's placed in the next location (with wraparound). You can even make the table larger if you want. The only problem is that, if the program is modified and re-uploaded, the whole first 32K of the EEPROM is erased, clearing the table. The solution is to use a 64K byte EEPROM and use the 2nd 32K or part of it for the table.

    Another easier option is to add a DS1307 or DS1302 real time clock to the unit. These have provisions for battery backup and have a small battery backed RAM included. You could just store the address of the restart point in this RAM. It's quick to do and it won't wear out.

    Post Edited (Mike Green) : 3/28/2008 6:03:18 PM GMT
  • PaulFPaulF Posts: 62
    edited 2008-03-28 23:05
    Thanks Mike, I had considered using the DS1307, but I was just wondering if there was a way of using files for convenience, thereby allowing the user to change the file and have the index incorporated in the file (or files).
    I will probably go with the DS1307 for the moment.
Sign In or Register to comment.