急!stm32f103+ch376 U盤讀寫文件,已折騰三四天了!
1:U盤新建文件返回值都是USB_INT_SUCCESS,并且CH376FileOpenPath( TarName )能打開、CH376GetFileSize()能得到正確大
小,但是大多數(shù)時候在電腦里面看不到剛剛新建的文件。
能打開、能得到正確大小,說明是創(chuàng)建成功的,為什么在電腦里面看不到文件?
2:無論在電腦里面能不能看到的文件,讀取時,CH376ByteRead()等函數(shù)的返回值也都是USB_INT_SUCCESS,并且其RealCount參
數(shù)也是得到正確的大小,但是buf參數(shù)總是空字符串。
能打開、能得到正確大小,創(chuàng)建文件應(yīng)該說也是成功的,RealCount參數(shù)也正確,為什么buf參數(shù)沒有獲取內(nèi)容?
另外,獲取的U盤剩余空間總是正確的。
下面附部分關(guān)鍵代碼,其它代碼都是標(biāo)準(zhǔn)代碼,基本上保持不變的:
按鍵創(chuàng)建、讀取等:
if(key==3)//get info and file len
{
s = CH376DiskQuery( (PUINT32)buf );
printf("Querys1=0x%02x,0x%02x ",(unsigned short)s,USB_INT_SUCCESS );
printf("free cap2 = %ld MB", *(PUINT32)buf / ( 1000000 / DEF_SECTOR_SIZE ) );
strcpy( (char *)TarName, "\\TEST.TXT" );
s =CH376FileOpenPath( TarName );
printf("Opens3=0x%02x ",(unsigned short)s );
kk=CH376GetFileSize();
s = CH376FileClose( FALSE ); ??
?printf("Closes4=0x%02x;%d\n",(unsigned short)s,kk );
}
if (key==4)//read file
{
strcpy( (char *)TarName, "\\TEST.TXT" );
s =CH376FileOpenPath( TarName );
printf("Opens5=0x%02x ",(unsigned short)s );
strcpy((char *)buf, "Test" );// ,Hello World!
printf("memset6:%s;%d ",(char *)buf,i);
memset((char *)buf,0,64);//
s = CH376ByteLocate( 0 );
printf("Locate7=0x%02x ",(unsigned short)s );
s = CH376ByteRead( buf, 5,&i);?
if (s!=USB_INT_SUCCESS)//0x14
{
printf("Reads8=0x%02x ",(unsigned short)s );
}
else
{
buf[63]=0;
printf("Read9:%s;%d;%d;%d;%d ",(char *)buf,i,buf[0],buf[1],buf[2]);?
}
?s = CH376FileClose( FALSE ); ?
?printf("Closes10=0x%02x\n",(unsigned short)s );
}
if(key==5)////create file
{
strcpy( (char *)TarName, "\\TEST.TXT" );?
s = CH376FileCreatePath( TarName ); ?
printf("Opens11=0x%02x ",(unsigned short)s );
strcpy((char *)buf, "Test ,Hello World gfhh!" );
s = CH376ByteWrite( buf, strlen((const char *)buf), NULL );?
printf("Writes12=0x%02x ",(unsigned short)s );
?s = CH376FileClose( TRUE ); ??
?printf("Closes13=0x%02x\n",(unsigned short)s );
}
if(key==6)//// create dir and file
{
strcpy( (char *)TarName, "\\170106\\" );?
s = CH376FileOpenPath( TarName ); ?
printf("Opens14=0x%02x ",(unsigned short)s );
if ( s != USB_INT_SUCCESS && s != ERR_OPEN_DIR ){
?s = CH376DirCreatePath( TarName );
printf("Creates15=0x%02x ",(unsigned short)s );
}
s = CH376FileClose( FALSE ); ??
?printf("Closes16=0x%02x ",(unsigned short)s );
//if (s == ERR_OPEN_DIR ){//
?strcpy( (char *)TarName, "\\170106\\150254.TXT" );?
?s = CH376FileCreatePath( TarName ); ?
?printf("Creates17=0x%02x ",(unsigned short)s );
?strcpy((char *)buf, "Test ,Hello World gfhh!" );
?s = CH376ByteWrite( buf, strlen((const char *)buf), NULL );?
?printf("Writes18=0x%02x ",(unsigned short)s );
? ?s = CH376FileClose( TRUE ); ?
? ?printf("Closes19=0x%02x\n",(unsigned short)s );
//}
}
?