急!stm32f103+ch376 U盘读写文件,已折腾三四天了!
1:U盘新建文件返回值都是USB_INT_SUCCESS,并且CH376FileOpenPath( TarName )能打开、CH376GetFileSize()能得到正确大
小,但是大多数时候在电脑里面看不到刚刚新建的文件。
能打开、能得到正确大小,说明是创建成功的,为什么在电脑里面看不到文件?
2:无论在电脑里面能不能看到的文件,读取时,CH376ByteRead()等函数的返回值也都是USB_INT_SUCCESS,并且其RealCount参
数也是得到正确的大小,但是buf参数总是空字符串。
能打开、能得到正确大小,创建文件应该说也是成功的,RealCount参数也正确,为什么buf参数没有获取内容?
另外,获取的U盘剩余空间总是正确的。
下面附部分关键代码,其它代码都是标准代码,基本上保持不变的:
按键创建、读取等:
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 );
//}
}