Question about pwrite method in fsrw (the SD card object)
ElectricAye
Posts: 4,561
Hi all,
I've been working with the SD card object from the Object Exchange, fsrw.spin, and I have a basic question about how the pwrite method works.· As I understand it, the following bit of code
······· PwriteCheck1 := fsrw.pwrite(Simple_Numbers.dec(Frequency1),7)
would convert Frequency1 into a string, and then the pwrite method would write 7 bytes of that string into an already opened file on the SD card.· If 7 bytes were successfully written, then the value of PwriteCheck would be 7.· All of this would work fine so long as Frequency1 consists of 7 digits.
My question is this: what happens if the value of Frequency1 were to drop below or rise above 7 digits?· Does it write junk to the SD card file if Frequency1 is fewer than 7 digits?· And·what gets·chopped off if Frequency1 goes above 7 digits?· Must I put in some kind of test code that checks the size of Frequency1 so the number of requested "byte writes" matches the number of digits making up Frequency1? or can I just change the 7 into 20 so that I'm always guaranteed that pwrite will write enough bytes?
My question stems from my suspicion that I'm suffering from memory stomp of some kind.· And normally I would simply run countless trials of the above mentioned ideas and reverse engineer how pwrite works, but I've trashed some SD cards in the past with my software, so I'm trying to figure this out as much as I can without actually playing with SD cards.·
many thanks,
Mark
I've been working with the SD card object from the Object Exchange, fsrw.spin, and I have a basic question about how the pwrite method works.· As I understand it, the following bit of code
······· PwriteCheck1 := fsrw.pwrite(Simple_Numbers.dec(Frequency1),7)
would convert Frequency1 into a string, and then the pwrite method would write 7 bytes of that string into an already opened file on the SD card.· If 7 bytes were successfully written, then the value of PwriteCheck would be 7.· All of this would work fine so long as Frequency1 consists of 7 digits.
My question is this: what happens if the value of Frequency1 were to drop below or rise above 7 digits?· Does it write junk to the SD card file if Frequency1 is fewer than 7 digits?· And·what gets·chopped off if Frequency1 goes above 7 digits?· Must I put in some kind of test code that checks the size of Frequency1 so the number of requested "byte writes" matches the number of digits making up Frequency1? or can I just change the 7 into 20 so that I'm always guaranteed that pwrite will write enough bytes?
My question stems from my suspicion that I'm suffering from memory stomp of some kind.· And normally I would simply run countless trials of the above mentioned ideas and reverse engineer how pwrite works, but I've trashed some SD cards in the past with my software, so I'm trying to figure this out as much as I can without actually playing with SD cards.·
many thanks,
Mark
Comments
You should replace your code with the following so you always write the correct amount of characters:
Right you are! And I guess what I meant to say is that I'm worried that if I don't get the "byte write" to match, then perhaps the pwrite method would write some "magic garbage" onto the SD card and cause it to die. Of course, magic garbage by itself would not be enough to kill the SD card, but maybe if magic garbage was combined with another error on my part, it might write garbage into a sensitive part of the SD card that would kill it. I'm clueless about how SD cards work, so it was just a guess.
I love your technique for getting the bytes to match. Being a very inexperienced clod, I would have treed my code with all sorts of IF statements. You saved me a lot of trouble.
a thousand thanks!
Mark
I'm confused about what kind of variable str is.· Up until now I thought SPIN did not have string variables.· So would the str be a LONG?· If so, is it limited by how many characters are in the string?·
baffled,
Mark
you are truly awesome.· Thanks for explaining that to me and answering so quickly!· WOW!
Mark