AnsweredAssumed Answered

twrk60d100m board sdcard file fopen error

Question asked by jack erison on Mar 27, 2014
Latest reply on Apr 22, 2014 by soledad

Hi, buddy,

static rst_code write_inv_data_to_sd(record_type type, Inverter *inv, DATE_STRUCT *time)

{

    uint8_t file_name[32]={0};

    uint8_t data_buffer[200]={0};

    FILE_PTR fd_ptr;

    _mqx_int     error_code;

 

    /* Check whether SD card exists */

    if(FALSE == check_sd_available())

    {

        return ERR_NO_MEMORY;

    }

 

    sprintf(data_buffer,

            "%s,"

            "%04d%02d%02d"

            "%02d%02d%02d,"

            "%d,%d,%d,"

            "%d,%d,%d,%d,"

            "%d,%d,%d,"

            "%d,%d,%d,"

            "%d,%d,%d,"

            "%d,%d,%d,"

            "%d,%d,%d,"

            "%d,%d,%d\n",

            inv->sn,

            time->YEAR,time->MONTH,time->DAY,

            time->HOUR,time->MINUTE,time->SECOND,

            inv->data.pdc,inv->data.pac,inv->data.sac,inv->data.qac,

            inv->data.status,inv->data.error_msg, inv->data.warn_msg,

            inv->data.e_today,inv->data.e_total,inv->data.h_total,

            inv->data.vpv1, inv->data.vpv2, inv->data.vpv3,

            inv->data.ipv1, inv->data.ipv2, inv->data.ipv3,

            inv->data.vac_r, inv->data.vac_s, inv->data.vac_t,

            inv->data.iac_r, inv->data.iac_s, inv->data.iac_t,

            inv->data.temperature1,inv->data.temperature2,inv->data.cosphi);

   

    sprintf(file_name,"a:%s.csv",inv->sn);

 

    /* Open file on disk in the current directory and write to it: */

    fd_ptr = fopen(file_name, "a+");

    if(NULL == fd_ptr)

    {

        printf("fd error!\n");

        return ERR_NO_MEMORY;

    }

 

    write(fd_ptr, data_buffer, strlen(data_buffer));

   

    /* Close the file: */

    error_code = fclose(fd_ptr);

 

   return RST_OK;

}

I have a sd ccard issue in my project.The board is twrk60d100m platform and i was using mqx 4.1 rtos.My purpse is using the sd card to record csv file.At first,everything is ok,when the csv file gets more lagrge,It can't write data to csv file and the file pointer is null.I don't know this why,and change a another sd card is the same result.The fllowing picture is the sdcard card file information.

Outcomes