Hi Ben
A question about the file open. In the version Before, if the file does not exist on the SD card, it does not return 0.
But now if the file does not exist, it creates the file.
This is not practical. I use this to determine if a file already exists.
Is there a way to test if a file already exists?
regards
Stefan
Open file:
ESP32 _ESP32_SDMode (4Bit) OpenFile return
-
- Valued Contributor
- Posts: 760
- http://meble-kuchenne.info.pl
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 150 times
- Been thanked: 171 times
-
- Valued Contributor
- Posts: 760
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 150 times
- Been thanked: 171 times
Re: ESP32 _ESP32_SDMode (4Bit) OpenFile return
Hi Ben
How can I prevent existing files from being overwritten or data attached?
File open ? it always returns 0 if it has created a new one or if it has opened an existing one.
regards
Stefan
How can I prevent existing files from being overwritten or data attached?
File open ? it always returns 0 if it has created a new one or if it has opened an existing one.
regards
Stefan
-
- Matrix Staff
- Posts: 1756
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 446 times
- Been thanked: 606 times
Re: ESP32 _ESP32_SDMode (4Bit) OpenFile return
Hello Stefan,
If you look in here C:\ProgramData\MatrixTSL\FlowcodeV10\CAL\ESP\ESP_CAL_File.c
Around line 193 we have this which opens the file in a mode that allows read and append write access. Unfortunatley this also seems to be creating the file if it doesn't already exist.
I can try to first open the file in read mode to check if the file is there, if it is then I can close the file again and then re-open in a+ mode.
Do you want to try replacing the file with this one and see if this resolves the problem for you.
The file needs to live here, just copy and paste the address into the file explorer address bar.
If it does solve the problem for you then I'll push it out to the library updates.
It looks like CreateFile also uses OpenFile CAL C function so I've added a new CreateFile C function and updated the component to point to this. I'll roll this out with the library update if open is now working as expected.
If you look in here C:\ProgramData\MatrixTSL\FlowcodeV10\CAL\ESP\ESP_CAL_File.c
Around line 193 we have this which opens the file in a mode that allows read and append write access. Unfortunatley this also seems to be creating the file if it doesn't already exist.
Code: Select all
MX_FILE_FP_X[MX_FILE_IDX_X] = fopen (FCL_FILEPATH, "a+");
I can try to first open the file in read mode to check if the file is there, if it is then I can close the file again and then re-open in a+ mode.
Code: Select all
//Open file for in read mode - ensure we don't create new files
MX_FILE_FP_X[MX_FILE_IDX_X] = fopen (FCL_FILEPATH, "r");
//if file not found and creation error
if (MX_FILE_FP_X[MX_FILE_IDX_X] == NULL)
{
//ESP_LOGE(TAG, "Failed to open file for reading");
return 1;
}
//Close file reference
fclose(MX_FILE_FP_X[MX_FILE_IDX_X]);
//Open file for append and reading
MX_FILE_FP_X[MX_FILE_IDX_X] = fopen (FCL_FILEPATH, "a+");
Do you want to try replacing the file with this one and see if this resolves the problem for you.
The file needs to live here, just copy and paste the address into the file explorer address bar.
Code: Select all
C:\ProgramData\MatrixTSL\FlowcodeV10\CAL\ESP\
It looks like CreateFile also uses OpenFile CAL C function so I've added a new CreateFile C function and updated the component to point to this. I'll roll this out with the library update if open is now working as expected.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
- Valued Contributor
- Posts: 760
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 150 times
- Been thanked: 171 times
Re: ESP32 _ESP32_SDMode (4Bit) OpenFile return
Hi Ben
I will gladly try this out. Thank you
I would like to do the following. When I start the recorder I read the card if record1.wav is present, then record2.wav and so on. Until, for example, record7.wav is not present (return a 1 instead of 0). So I know that my next file should be record7.wav and then nextnext record8.wav and so on. This works well with the "old SD-card component" Perhaps there is a better method .
after a restart returns a number for the next filename:
I will gladly try this out. Thank you
I would like to do the following. When I start the recorder I read the card if record1.wav is present, then record2.wav and so on. Until, for example, record7.wav is not present (return a 1 instead of 0). So I know that my next file should be record7.wav and then nextnext record8.wav and so on. This works well with the "old SD-card component" Perhaps there is a better method .
after a restart returns a number for the next filename:
- Attachments
-
- file_last_file_found.fcm
- (3.15 KiB) Downloaded 15 times
-
- Matrix Staff
- Posts: 1756
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 446 times
- Been thanked: 606 times
Re: ESP32 _ESP32_SDMode (4Bit) OpenFile return
Ok fingers crossed. I had other things to push and so I've pushed the changes including the create file to the library updates so hopefully it will all work for you correctly now.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
- Valued Contributor
- Posts: 760
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 150 times
- Been thanked: 171 times
Re: ESP32 _ESP32_SDMode (4Bit) OpenFile return
Hi Ben
It's working perfect!
It is so easy to create an excel file with Flowcode. With the help of my macro "file_last_file_found.fcm" I can, for example, make two recordings and then switch off the recorder completely. When I switch the recorder on again, this macro finds the number for the next file.
I my application IMU1_3.csv
Now there is only one small wish left.
Sometimes I have to create a binary file instead of an Excel file.
I can save a byte array, but that is a bit complicated because I have an integer array.
Would it be possible to add this also with ESP32_SDMode (4Bit) like the old SD-component?
AppendINTArrayToFile:
It's working perfect!
It is so easy to create an excel file with Flowcode. With the help of my macro "file_last_file_found.fcm" I can, for example, make two recordings and then switch off the recorder completely. When I switch the recorder on again, this macro finds the number for the next file.
I my application IMU1_3.csv
Now there is only one small wish left.
Sometimes I have to create a binary file instead of an Excel file.
I can save a byte array, but that is a bit complicated because I have an integer array.
Would it be possible to add this also with ESP32_SDMode (4Bit) like the old SD-component?
AppendINTArrayToFile:
- Attachments
-
- Snag_2acbfe.png (32.13 KiB) Viewed 421 times
-
- Matrix Staff
- Posts: 1756
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 446 times
- Been thanked: 606 times
Re: ESP32 _ESP32_SDMode (4Bit) OpenFile return
Excellent glad it's working correctly for you now, I've now added the INT, Long and Float array read/write functions so hopefully that will help.
Please let me know if you have any issues.
Please let me know if you have any issues.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
- Valued Contributor
- Posts: 760
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 150 times
- Been thanked: 171 times
Re: ESP32 _ESP32_SDMode (4Bit) OpenFile return
Hi Ben
If i append an array with number 0-19 in a loop, it's working fine.
But if i change value 10 and 11 to a special value like "\r\n" and "\n\r" in hex value
its not append the rest of the array anymore.
Set the array: result is perfect:
Set the array with special char: result is not complet after the 0x0A0D:
If i append an array with number 0-19 in a loop, it's working fine.
But if i change value 10 and 11 to a special value like "\r\n" and "\n\r" in hex value
its not append the rest of the array anymore.
Set the array: result is perfect:
Set the array with special char: result is not complet after the 0x0A0D:
-
- Matrix Staff
- Posts: 1756
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 446 times
- Been thanked: 606 times
Re: ESP32 _ESP32_SDMode (4Bit) OpenFile return
Hi Stefan,
Right ok that is odd, looks to be something deep within the fputc function which is returning an error when it gets those characters. It writes both bytes in the INT before checking the error return. I can't look at the library itself to see what it's doing because it's precompiled.
I've had a go at simple ignoring the error in all of the AppendArray functions and hopefully the latest version will work ok for you now. Could be the error is just indicating an end of line character has been received.
Right ok that is odd, looks to be something deep within the fputc function which is returning an error when it gets those characters. It writes both bytes in the INT before checking the error return. I can't look at the library itself to see what it's doing because it's precompiled.
I've had a go at simple ignoring the error in all of the AppendArray functions and hopefully the latest version will work ok for you now. Could be the error is just indicating an end of line character has been received.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
- Valued Contributor
- Posts: 760
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 150 times
- Been thanked: 171 times
Re: ESP32 _ESP32_SDMode (4Bit) OpenFile return
Hi Ben
It's working perfect! Thank you.
I checked it and created the array a little more elegantly.
It's working perfect! Thank you.
I checked it and created the array a little more elegantly.