Hi,
Is there a limit to the amount of bytes one can write to the SD card in one go? I have been trying to log a string of about 900 bytes long, sometimes this works and most of the time I get OSError 5. Once that happens I can no longer write to the file unless I close it and open another.
I have also stuffed in a routine which split the string into 100 byte sized chunks if it detects anything bigger than 100 bytes. This seems to fix the OSError issue but is there an underlying issue which is causing this to occur? This happens for the latest (stable) release, 1.5.2 and 1.4.2
Thanks,
Cooper
Limit to file.write() ?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Limit to file.write() ?
I can't replicate this. Might there be a problem with your SD card?
[and so on, ad nauseam]
Code: Select all
MicroPython v1.6-99-g42bc25b-dirty on 2016-03-02; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>>
>>> with open('/sd/rats.txt', 'w') as f:
... s = 'the quick brown fox jumps over the lazy dog\n'
... f.write(s*100)
...
4400
>>>
/mnt/qnap2/data/Projects/MicroPython/micropython-epaper> cat /sd/rats.txt
the quick brown fox jumps over the lazy dog
the quick brown fox jumps over the lazy dog
the quick brown fox jumps over the lazy dog
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Limit to file.write() ?
I had an OS Error 5 when reading more that 511 bytes at once after seek or read to a position which is not a multiple of 4. Transferring 511 bytes and less works. According to your description, that could be the case here too (about 900 fails, chunks of 100 pass). See https://github.com/micropython/micropython/issues/1863
As a temporary fix, I used splitting, hoping that this behavior will be fixed sometime. It's limited to PyBoard & SD card.
Regards
As a temporary fix, I used splitting, hoping that this behavior will be fixed sometime. It's limited to PyBoard & SD card.
Regards
Re: Limit to file.write() ?
@pythoncoder my SD card is definitely ok, as this occurs with other cards.
@Roberthh thank you for the link to the bug, it does sound consistent with the issues I am having. I shall continue to use the chopping scheme until the issue has been solved.
Thank you both for your reply and assistance!
@Roberthh thank you for the link to the bug, it does sound consistent with the issues I am having. I shall continue to use the chopping scheme until the issue has been solved.
Thank you both for your reply and assistance!