Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem mbed
Fork of PES4_Programme by
Diff: source/sdcard.cpp
- Revision:
- 90:d0805b58b0ae
- Parent:
- 81:a869abf56e85
- Child:
- 94:b24d2b432b27
diff -r 04fe3dff23f4 -r d0805b58b0ae source/sdcard.cpp
--- a/source/sdcard.cpp Mon Apr 09 15:05:43 2018 +0000
+++ b/source/sdcard.cpp Mon Apr 09 15:43:45 2018 +0000
@@ -704,6 +704,61 @@
return buff;
}
+char *read_Inventory()
+{
+ static char *buff;
+ long numbytes;
+
+ char filepath[] = "/sd/protocol/medInventory.txt";
+
+
+ //Configure CRC, large frames, and write validation
+ sd.crc(true);
+ sd.large_frames(true);
+ sd.write_validation(true);
+
+ //mount SD card
+ printf("\n\rMounting SD card...");
+ if (sd.mount() != 0) {
+ printf("failed!\n\r");
+ return NULL;
+ }
+ printf("success!\n\r");
+
+ //open file for read
+ printf("open file %s...",filepath);
+ FILE *fp = fopen(filepath, "r");
+ if(fp == NULL) {
+ printf("failed!\n\r");
+ return NULL;
+ }
+ printf("success!\n\r");
+
+ /* Get the number of bytes */
+ fseek(fp, 0L, SEEK_END);
+ numbytes = ftell(fp);
+
+ /* reset the file position indicator to
+ the beginning of the file */
+ fseek(fp, 0L, SEEK_SET);
+
+ /* grab sufficient memory for the
+ buffer to hold the text */
+ buff = (char*)calloc(numbytes, sizeof(char));
+
+
+ /* copy all the text into the buffer */
+ fread(buff, sizeof(char), numbytes-1, fp);
+ fclose(fp);
+
+ /* free the memory we used for the buffer */
+ //free(buff);
+
+ //Unmount the SD card
+ sd.unmount();
+
+ return buff;
+}
