Page 1 of 1

Is it possible to write two files simultaneously in usb?

PostPosted: Thu Aug 30, 2018 12:43 pm
by Manoj
I am trying this code technicalyy the codes has no compile error. it is also running but only on file is being saved.
Can anyone point out what I missed?
CODE:
Code: Select all
//initialization
#ifndef MINIMUM_BUILD
   
    volatile BYTE       logBufferReading;
    BYTE                logBufferWriting;
    volatile BYTE       logBufferReading2;
    BYTE                logBufferWriting2;
    LOGGER_STATUS       loggerStatus;
    volatile DWORD      currentTick;

   volatile LOG_DATA   logData[NUM_LOG_BUFFERS];
   volatile LOG_DATA   logData2[NUM_LOG_BUFFERS];
        FSFILE              *filePointer2;
        FSFILE              *filePointer4;


void   LoggingRoutine(void)
{
               
               char oneChar;
               SearchRec searchRecord1;   
               int d=0;
               No_samples=0;
            //   DispL2(0);
               LoggingON = TRUE;
               MStat[0]=1;
               MStat[1]=1;
               MStat[2]=1;
                     ch2scanflag=1;// this enables the file pointer4 to open write and close
                            logBufferReading        = 0;
                            logBufferWriting        = 0;
                              logBufferReading2       = 0;
                            logBufferWriting2       = 0;
                            ReadingCount            = 0;
                            previousTime.l          = 0;
                     ByteCount             = 0;
                     int timeintnew, timeintold=0;      
                     
                     sprintf(Filenameauto,"%.2x%.2x%.2x%.2x.txt",currentDate.mon,currentDate.mday,currentTime.hour,currentTime.min); //generating first file there is no issue with this one
                                    
                             if ((filePointer2 = FSfopen( Filenameauto, "w" )) == NULL)
                            {
                        DispL2(0);
                        Put_String_LCD( "File access error" );
                            }

                              for (value=0; value<NUM_LOG_BUFFERS; value++)
                            {
                                logData[value].index       = 0;
                                logData[value].bufferFull  = FALSE;

                            }            
                  
                     sprintf( (char *)&(logData[logBufferReading].buffer[logData[logBufferReading].index]),// saving data in file 1
                                                    "PORTABLE   BALANCER   5200                    \r\n" );
                     logData[logBufferReading].index=48;
                  
                     sprintf( (char *)&(logData[logBufferReading].buffer[logData[logBufferReading].index]),
                                                    "        \r\n" );

                     logData[logBufferReading].index=50;
                     sprintf( (char *)&(logData[logBufferReading].buffer[logData[logBufferReading].index]),"%.2x/%.2x/%.2x\r\n",currentDate.mday,currentDate.mon,currentDate.year);

                     logData[logBufferReading].index=60;
                     if(ch2scanflag)// entering 2nd file make option
                        {
                           sprintf(Filenameauto2,"%.2x%.2x%.2x%.2xch2.txt",currentDate.mon,currentDate.mday,currentTime.hour,currentTime.min);      // 2nd file generation with //different name            

                                   if ((filePointer4 = FSfopen( Filenameauto2, "w" )) == NULL)
                                  {
                              DispL2(0);
                              Put_String_LCD( "File access error" );
                                  }

                                    for (value=0; value<NUM_LOG_BUFFERS; value++)
                                  {
                                      logData2[value].index2       = 0;
                                      logData2[value].bufferFull2  = FALSE;

                                     }
   
                           sprintf( (char *)&(logData2[logBufferReading2].buffer2[logData2[logBufferReading2].index2]),
                                                    "PORTABLE   BALANCER   5200                    \r\n" );
                           logData2[logBufferReading].index2=48;
                  
                           sprintf( (char *)&(logData2[logBufferReading2].buffer2[logData2[logBufferReading2].index2]),
                                                          "        \r\n" );

                           logData2[logBufferReading].index2=50;
                           sprintf( (char *)&(logData2[logBufferReading2].buffer2[logData2[logBufferReading2].index2]),"%.2x/%.2x/%.2x\r\n",currentDate.mday,currentDate.mon,currentDate.year);

                           logData2[logBufferReading2].index2=60;
                while (c<1.6)
                      {
                              MonitorMedia();

                                        currentTime.l = PIC24RTCCGetTime();
                                        currentDate.l = PIC24RTCCGetDate();

                                if (timeintnew != timeintold)
                                   { 
                              FrequencyScan(); // Get the latest reading
                              sprintf((char *)&(logData[logBufferReading].buffer[logData[logBufferReading].index]),"%05.1f,%07.2f  \r\n",Amount1,c);
                              logData[logBufferReading].index+=16;               
                                            if ((logData[logBufferReading].index)+17 > MAX_LOG_BUFFER_SIZE)
                                           {
                                            logData[logBufferReading++].bufferFull = TRUE;
                                               if (logBufferReading >= NUM_LOG_BUFFERS)
                                               {
                                                logBufferReading = 0;
                                               }
                                           }   
                           //   timeintold=timeintnew;
                                   if (logData[logBufferWriting].bufferFull)
                                      {
                                         WriteOneBuffer( filePointer2, (BYTE *)logData[logBufferWriting].buffer, logData[logBufferWriting].index );
                                      }
                           }
                                     KEY;
                         if (U2STAbits.URXDA)// not sure if this one is necessary
                                   {
                                       oneChar = UART2GetChar();
                                   }
                        if(ch2scanflag)
                           {
                              sprintf((char *)&(logData2[logBufferReading2].buffer2[logData2[logBufferReading2].index2]),"%05.1f,%07.2f  \r\n",Amount1,c);
                              logData2[logBufferReading2].index2+=16;               
                                         if ((logData2[logBufferReading2].index2)+17 > MAX_LOG_BUFFER_SIZE)
                                             {
                                              logData2[logBufferReading2++].bufferFull2 = TRUE;
                                               if (logBufferReading2 >= NUM_LOG_BUFFERS)         
                                                  {
                                                      logBufferReading2 = 0;
                                                     }
                                             }                                     //   timeintold=timeintnew;
                                         if (logData2[logBufferWriting2].bufferFull2)
                                            {
                                               WriteOneBuffer2( filePointer2, (BYTE *)logData2[logBufferWriting2].buffer2, logData2[logBufferWriting2].index2 );
                                            }
                           
                           }
                              
                   } // end of while loop


                        sprintf((char *)&(logData[logBufferReading].buffer[logData[logBufferReading].index]),"\r\n***********\r\n    ");
                                    logData[logBufferReading].index+=16;
                        if(ch2scanflag)
                           {
                              sprintf((char *)&(logData2[logBufferReading2].buffer2[logData2[logBufferReading2].index2]),"\r\n***********\r\n    ");
                                    logData2[logBufferReading2].index2+=16;
                           }


                            while (logData[logBufferWriting].bufferFull)  // Write all remaining buffers to the file
                            {
                                WriteOneBuffer( filePointer2, (BYTE *)logData[logBufferWriting].buffer, logData[logBufferWriting].index );
                            }

                            // If the last buffer isn't full but it has data, write the data we have.
                            if (logData[logBufferWriting].index)
                            {
                                WriteOneBuffer( filePointer2, (BYTE *)logData[logBufferWriting].buffer, logData[logBufferWriting].index );
                            }

                     if(ch2scanflag)
                        {
                           sprintf((char *)&(logData2[logBufferReading2].buffer2[logData2[logBufferReading2].index2]),"%02d        \r\n      ",peakcountno);
                                    logData2[logBufferReading2].index2+=16;

                                     while (logData2[logBufferWriting2].bufferFull2)  // Write all remaining buffers to the file
                                        {
                                         WriteOneBuffer2( filePointer4, (BYTE *)logData2[logBufferWriting2].buffer2, logData2[logBufferWriting2].index2 );
                                        }
                           
                                     if (logData2[logBufferWriting2].index2) // If the last buffer isn't full but it has data, write the data we have.
                                        {
                                               WriteOneBuffer2( filePointer4, (BYTE *)logData2[logBufferWriting2].buffer2, logData2[logBufferWriting2].index2 );
                                        }
                        }

                     FSfclose( filePointer4 );// closing files
                     FSfclose( filePointer2 );

}// end of frequency scan



///function write one buffer

/****************************************************************************
  Function:
    void WriteOneBuffer( FSFILE *fptr, BYTE *data, WORD size )

  Description:
    This function writes one log buffer to the indicated file.  It then
    advances the pointer to the current buffer to write.

  Precondition:
    None

  Parameters:
    FSFILE *fptr    - Pointer to an open file
    BYTE *data      - Pointer to data to write
    WORD size       - How many bytes of data to write

  Return Values:
    None

  Remarks:
    None
  ***************************************************************************/

void WriteOneBuffer( FSFILE *fptr, BYTE *data, WORD size )
{
    if (FSfwrite( data, 1, size, fptr) != size)
    {
      
        PrintString( "! Error writing log file\r\n" );
    }
    logData[logBufferWriting].bufferFull    = FALSE;
    logData[logBufferWriting].index         = 0;

    logBufferWriting++;
    if (logBufferWriting >= NUM_LOG_BUFFERS)
    {
        logBufferWriting = 0;
    }

}
void WriteOneBuffer2( FSFILE *fptr, BYTE *data, WORD size )
{

          if (FSfwrite( data, 1, size, fptr) != size)
          {   
              PrintString( "! Error writing log file\r\n" );
           }
         logData2[logBufferWriting2].bufferFull2    = FALSE;
          logData2[logBufferWriting2].index2         = 0;
         logBufferWriting2++;
          if (logBufferWriting2 >= NUM_LOG_BUFFERS)
          {
              logBufferWriting2 = 0;
          }         
}// end of function



if i try different formant for different files such as .txt and .csv .I can see the envelope of second file but there is no data in it and it is corrupted.
Thank you.

Re: Is it possible to write two files simultaneously in usb?

PostPosted: Fri Aug 31, 2018 12:47 am
by jtemples
Your problem has nothing to do with USB, it's a function of the file system you're using. How have you set FS_DYNAMIC_MEM and FS_MAX_FILES_OPEN?

Re: Is it possible to write two files simultaneously in usb?

PostPosted: Fri Aug 31, 2018 9:23 am
by Manoj
thnx . I did not

Re: Is it possible to write two files simultaneously in usb?

PostPosted: Sun Sep 02, 2018 7:30 am
by ric
Well what are those symbols set to?