|
发表于 2019-7-2 15:35:29
|
显示全部楼层
- //sd卡数据复制到U盘
- void SDDataToUpanProcess(void)
- {
- //FATFS fs_; //逻辑磁盘工作区
- FIL U_fdst; //文件
- FRESULT res;//状态变量
- typedef unsigned int UINT;
- UINT br_,bw_;
- res = f_open(&U_fdst,"2:\1.txt",FA_WRITE | FA_CREATE_ALWAYS); //打卡U盘
- if(res !=FR_OK){DEBUG_printf("U_open_ERR:%d\r\n",res); return ;}
- else{DEBUG_printf("U_open_OK\r\n");}
-
- while(1)
- {
- res = f_write(&U_fdst,"1234578\r\n",10,&bw_); 在这里不出来不知道为什么?
- res = res;
- if(res || bw_ < br_){DEBUG_printf("U_write_error disk full:%d-%d\r\n",res,bw_); break ;}
- }
- f_close(&U_fdst);
- DEBUG_printf("f_close\r\n");
- }
复制代码
复制代码
res = f_write(&U_fdst,"1234578\r\n",10,&bw_); 在这里不出来不知道为什么?
下面的代码创建1.txt文件是正常的
- //sd卡数据复制到U盘
- void SDDataToUpanProcess(void)
- {
- //FATFS fs_; //逻辑磁盘工作区
- FIL U_fdst; //文件
- FRESULT res;//状态变量
- typedef unsigned int UINT;
- UINT br_,bw_;
- res = f_open(&U_fdst,"2:\1.txt",FA_WRITE | FA_CREATE_ALWAYS); //打卡U盘
- if(res !=FR_OK){DEBUG_printf("U_open_ERR:%d\r\n",res); return ;}
- else{DEBUG_printf("U_open_OK\r\n");}
-
- f_close(&U_fdst);
- DEBUG_printf("f_close\r\n");
- }
- 复制代码
复制代码
下面的读取代码是正常的
- res=f_open (&U_fdst,"2:/1.txt", FA_READ); //读方式打开配置文件
- // f_lseek(&fil0,i*6); //每次读取之前先移动读写指针达到读写不同数据的目的
- if(res !=FR_OK){DEBUG_printf("ERR:%d\r\n",res);}
- res=f_read (&U_fdst, buf,100,&br_); //读取文件到buf
- if(res !=FR_OK){DEBUG_printf("ERR:%d\r\n",res);}
- f_close(&U_fdst); //关闭文件
- // configbound = atol(buf); //使用stdlib.h头文件里面的函数将字符串转换为数字
- printf("读取1.txt配置文件\r\n内容为:\r\n%s\r\n",buf);//将数字使用printf函数输出
复制代码 |
|