On CODESYS V3.5.19.50 I am using the latest 3S File Access library (CAA File & CAA Types) to save and retrieve configuration data from the User Data section of an SD card, via file called config.txt.
The application reads the file to memory once upon initialisation, and then the only other operation is overwriting the file with the updated configuration whenever the user changes the settings.
An issue is ocurring, seemingly randomly, where the config.txt file, and all surrounding directories, cannot be written to by the unit, returning a READ_ONLY_CAA error upon file open. This sometimes does not clear even after power-cycling the PLC several times, yet checking the file permissions with ls -l shows normal read, write, and execute access.
I am wondering if this is caused by the PLC itself or by an issue in my application. I have included my CAA File handler function block (SD_Card_Bin(FB).txt) and any associated types/calls below:
In case of error while opening the file to read you assume that the file doesn't exist and try to create one. But it could be that the SD card is not ready yet or simply not there. I would try to check first if the SD card is there and accessible. Otherwise with FILE.Create you could end up creating a new directory that is not mapped to the SD card. This would explain the errors even after a reboot, though it doesn't explain the READ_ONLY_CAA error I guess? I would use FILE.DirOpen and FILE.DirList to check if the SD card is there and ready.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
On CODESYS V3.5.19.50 I am using the latest 3S File Access library (CAA File & CAA Types) to save and retrieve configuration data from the User Data section of an SD card, via file called config.txt.
The application reads the file to memory once upon initialisation, and then the only other operation is overwriting the file with the updated configuration whenever the user changes the settings.
An issue is ocurring, seemingly randomly, where the config.txt file, and all surrounding directories, cannot be written to by the unit, returning a READ_ONLY_CAA error upon file open. This sometimes does not clear even after power-cycling the PLC several times, yet checking the file permissions with ls -l shows normal read, write, and execute access.
I am wondering if this is caused by the PLC itself or by an issue in my application. I have included my CAA File handler function block (SD_Card_Bin(FB).txt) and any associated types/calls below:
A case within my MAIN PRG:
I'd like to rule out my application as the cause of this bug - help via comments or criticism would be greatly appreciated.
In case of error while opening the file to read you assume that the file doesn't exist and try to create one. But it could be that the SD card is not ready yet or simply not there. I would try to check first if the SD card is there and accessible. Otherwise with FILE.Create you could end up creating a new directory that is not mapped to the SD card. This would explain the errors even after a reboot, though it doesn't explain the READ_ONLY_CAA error I guess? I would use FILE.DirOpen and FILE.DirList to check if the SD card is there and ready.