FSRW handshaking with write command
StevenR
Posts: 13
Is there a command to find out if the block of data written to the SD card was successful?
For example I am using:
sd.pwrite(@block,256)
What would be the next line of code to confirm the write?
tnx,
Steven.
For example I am using:
sd.pwrite(@block,256)
What would be the next line of code to confirm the write?
tnx,
Steven.
Comments
But if it's positive you can''t tell if it's already written to the card or if only the copy to the buffer was OK.
I haven't used it to directly write to a card, but here's an example of reading a sector from a card. This example reads sector zero from an SD card and displays the FAT boot MBR signature "55AA".
By byte-misaligning the buffer, this demonstrates forcing an abort error, then capturing and displaying the error code (-4 is "misaligned buffer") This can also ask for an address out-of-range, causing the routine to return "-64".
I assume that the underlying SD-access code similarly attempts to capture and report write errors, which would answer your question, but I don't understand the SD access code enough to say for sure that it does that.
In the interest of science, I just tried to write 1024 byte blocks. Again only the first 512 bytes were written to the card.
In the further interest of science, I wrote one byte at a time and the card only took the first 512 writes.
What is limiting the writes to 512 bytes?
(You should pause up to about 1/2 second after the call, because the
card might, under extreme circumstances take that long to actually
write the buffer it was sent). If you need confirmation, just do
anything that forces a read (like trying to open a non-existent file,
which will also close the existing file).
In general, just call pflush() and you should be just fine, unless your
program controls power and you will be immediately powering off.
Note that calling pflush() can seriously slow things down. If you
pflush() every byte, for instance, I wouldn't be surprised if things
are 10,000 slower than normal.
In general, you should pclose() after writes. If you don't pclose()
after writes, then yes, you should pflush() if you think someone
might eject the card, or the program might stop or run out of
power before then. If you do not pclose(), or pflush(),
the data will in general *not* be written to the card (or more
accurately, it will be, but the updated metadata won't be).
Perhaps you might want to explain more about what you are
doing, and we can give you some good advice?
-tom
From this point of view you should maybe think about how ugent it is to have each long logged or if you can efford to loose up to 64 longs. (Maybe one write is doing more than a long, then you'll loose less entries in your case)
FSRW is pretty stable and I never had a problem with loosing sectors. You should post your code.
Here is some pseudo code of what I am trying to accomplish:
Read a byte from the serial port
Store byte into array
If 512 bytes have been stored in array then
sd.prwite array to card
Else get another byte from the serial port
If end of byte stream from serial port then
sd.pclose
Else get another 512 bytes from serial port
Perhaps someone could post some code of their own to make this work.
tnx,
Steven.
Post Edited (StevenR) : 1/25/2010 3:30:20 PM GMT
Say you received 700 bytes.
After 512 you write.
After another 188 you find the end of bytestream condition is true and you close the file.
But you did not write that 188 bytes.
But maybe your pseudo code is not what you really do.