3 Replies Latest reply on Jul 30, 2014 9:28 AM by JPMontero_Intel

    SD Library Function Seek() for Ring-Buffer Not Working

    RSavage1

      I am newbie and have been experimenting with SD library to write a data logging routine that uses a file on the SD card to create a ring buffer. Data is written to a text file and when the file size reaches a maxim size a pointer is reset causing the file to be rewritten stating at the beginning. In this way the file is always kept to a desired size and prevents it from exceeding the max size of the SD card.

       

      In the process of writing code (see attached file) I have found that the SD "seek" function does not appear to be working. Using an Arduino Uno I tested my code and it works correctly, but when I load it on the Galileo it does not. The problem is that the SD seek function does not work correctly. When I try to set a write position within the file it never goes to the new position. All that happens when I print to the file is an append to the end of the file. Does anybody know if this is a known issue or how to create a work around?

        • 1. Re: SD Library Function Seek() for Ring-Buffer Not Working
          Intel_Jesus

          Hi RSavage1,

           

          Try this workaround, replace the following line 

           

          myFile.seek(FilePointer);
          

          with

              myFile.close();
              system("rm /media/mmcblk0p1/testC.txt");
              system("touch /media/mmcblk0p1/testC.txt");
               myFile = SD.open("testC.txt", FILE_WRITE);
          

           

          Regards,

          Intel_JEspinoza

          • 2. Re: SD Library Function Seek() for Ring-Buffer Not Working
            RSavage1

            Hi JEspionza,

            Thank you for the help and suggestion, but for what I am trying to do deleting and remaking the file will not work. What I am trying to do is to create a Ring Buffer. In that the contents of the file always remain intact and any new data always replaces the last know oldest data point in the file (FILO). In this way the file "Ring Buffer" can be used indefinitely and will never run out of space and will always contain a running history of all the data points.

             

            My first attempt to do this was to us a file pointer to track the position of the next write location and when the file reaches a certain size the file pointer is reset back to the beginning of the file. Once this occurs the file pointer is then incremented by one and new data is stored at the location and the pointer is incremented again. This process would then continue until the end of the file is reached and the whole process would be repeated indefinitely. For the program I would also use the file pointer to be able to printout the data in chronological order. To do all of this I was relying on the SD "seek" function but it appears that it is not working correctly.

            • 3. Re: SD Library Function Seek() for Ring-Buffer Not Working
              JPMontero_Intel

              Hi RSavage1

               

              The ring buffer hasn't been ported to the Galileo yet. The function is defined in the libraries but it is empty I believe, that is why it compiles successfully, but it doesn't do anything.
              Regards
              JPMontero_Intel