環(huán)境: CH374、SDT2.51、庫(kù)為CH374HF9.ALF、CH374_LIB_VER 0x16
測(cè)試代碼如下: BOOL nRet; //char FileName[16]; FatDateTime DateTime; switch(TestType) { case 1: //創(chuàng)建文件,不寫數(shù)據(jù)不更新文件長(zhǎng)度并關(guān)閉文件,再打開文件,測(cè)試文件長(zhǎng)度 strcpy((char *)mCmdParam.Create.mPathName ,"\\TEST01.TXT"); nRet = CH374FileCreate(); /*創(chuàng)建文件*/ if(nRet != ERR_SUCCESS) { Uart_Printf(0x00,"CH374FileCreate Error!\n"); } DelayMS(10); Uart_Printf(0x00,"CreateFile File size:%u \n",CH374vFileSize); mCmdParam.Close.mUpdateLen = 0; nRet = CH374FileClose(); /*關(guān)閉文件*/ if(nRet != ERR_SUCCESS) { Uart_Printf(0x00,"CH374FileClose Error!\n"); } DelayMS(50); strcpy((char *)mCmdParam.Open.mPathName ,"\\TEST01.TXT"); nRet = CH374FileOpen(); /*打開文件*/ if(nRet != ERR_SUCCESS) { Uart_Printf(0x00,"CH374FileOpen Error!\n"); } Uart_Printf(0x00,"File size is:%u \n",CH374vFileSize); mCmdParam.Close.mUpdateLen = 0; nRet = CH374FileClose(); /*關(guān)閉文件*/ if(nRet != ERR_SUCCESS) { Uart_Printf(0x00,"CH374FileClose Error!\n"); } Uart_Printf(0x00,"Ch374LibTest complete 01!\n"); break; case 2: //創(chuàng)建文件,不寫數(shù)據(jù)但更新文件長(zhǎng)度并關(guān)閉文件,再打開文件,測(cè)試文件長(zhǎng)度 strcpy((char *)mCmdParam.Create.mPathName ,"\\TEST02.TXT"); nRet = CH374FileCreate(); /*創(chuàng)建文件*/ if(nRet != ERR_SUCCESS) { Uart_Printf(0x00,"CH374FileCreate Error!\n"); } DelayMS(10); Uart_Printf(0x00,"CreateFile File size:%u \n",CH374vFileSize);
//更改文件日期和文件長(zhǎng)度 usbfat_datetime((FatDateTime *)&DateTime); mCmdParam.Modify.mFileSize = 0; mCmdParam.Modify.mFileAttr = 0xff; mCmdParam.Modify.mFileTime = DateTime.Time; mCmdParam.Modify.mFileDate = DateTime.Date; nRet = CH374FileModify(); /*更改文件長(zhǎng)度和日期*/ if(nRet != ERR_SUCCESS) { EnableInterrupt(); return FALSE; } mCmdParam.Close.mUpdateLen = 0; nRet = CH374FileClose(); /*關(guān)閉文件*/ if(nRet != ERR_SUCCESS) { Uart_Printf(0x00,"CH374FileClose Error!\n"); } DelayMS(50); strcpy((char *)mCmdParam.Open.mPathName ,"\\TEST02.TXT"); nRet = CH374FileOpen(); /*打開文件*/ if(nRet != ERR_SUCCESS) { Uart_Printf(0x00,"CH374FileOpen Error!\n"); } Uart_Printf(0x00,"File size is:%u \n",CH374vFileSize); mCmdParam.Close.mUpdateLen = 0; nRet = CH374FileClose(); /*關(guān)閉文件*/ if(nRet != ERR_SUCCESS) { Uart_Printf(0x00,"CH374FileClose Error!\n"); } Uart_Printf(0x00,"Ch374LibTest complete 02!\n"); break; default: break; }
return TRUE;
測(cè)試結(jié)果如下:
CreateFile File size:0 File size is:1 Ch374LibTest complete 01!
CreateFile File size:0 File size is:0 Ch374LibTest complete 02!
根據(jù)結(jié)果,如果在關(guān)閉文件前用CH374FileModify()重新定義了文件長(zhǎng)度,這可以實(shí)現(xiàn)0字節(jié)的文件。
請(qǐng)問這是什么問題呀? 謝謝了!