UART_Send_Str("Start to read data....\r\n"); //开始读取数据
i=0;
linelength=0;
readflag=1;
while(readflag==1)
{
len=znFAT_ReadData(&fileinfo,i,1,&readBuf);
if(readBuf==0x0D)
{
linebufTemp[i]=readBuf;
readflag=0;//跳出读取循环
//判断是不是有X,Y,两者都有
//不断查询数组,看里面是不是存在X和Y,
for(i=0;i<linelength;i++)
{
if(linebufTemp[i]=='X')
{
xreadflag=1;
xnpos=i;
}
if(linebufTemp[i]=='Y')
{
yreadflag=1;
ynpos=i;
}
}
if(xreadflag==1 && yreadflag==1)//存在X和Y,将X和Y的数据拿出来,将Y和0x0D的数据拿出来
{
//将数组中的xnpos+1,ynpos-1之间的元素,放入xstring中,用atof转成float类型 2345 ==5-2+1
for(i=xnpos+1;i<ynpos;i++)
{
xstring[j]=linebufTemp[i];
j++;
}
xstring[j]='\0';
j=0;
for(i=ynpos+1;i<linelength+1;i++)
{
ystring[j]=linebufTemp[i];
j++;
}
ystring[j]='\0';
j=0;
UART_Send_Str("xstring and ystring is below:---"); //输出读到的数据内容
UART_Send_Enter();
UART_Send_Str(xstring); //输出读到的数据内容
UART_Send_Enter();
UART_Send_Str(ystring); //输出读到的数据内容
UART_Send_Enter();
xnew=atof(xstring);
if(xnew<0)
{
UART_Send_StrNum("Have read data xnew(Bytes):",xnew*(-1)*1000+100); //输出实际读到的数据量
UART_Send_Enter();
}
else if(xnew>0)
{
UART_Send_StrNum("Have read data xnew(Bytes):",xnew*1000+100); //输出实际读到的数据量
UART_Send_Enter();
}
}
else if(xreadflag==1 && yreadflag==0)
{
}
else if(xreadflag==0 && yreadflag==1)
{
}
}
else
{
linelength=linelength+1;
linebufTemp[i]=readBuf;//将读取的数据,放到数组里面,一行的数据进行存取;
i++;
}
}
UART_Send_Str("Data is below:\r\n");
UART_Send_Str(linebufTemp); //输出读到的数据内容
UART_Send_Enter();
UART_Send_StrNum("Have read data linebufTemp(Bytes):",linelength); //输出实际读到的数据量
//
// len=znFAT_ReadData(&fileinfo,0,20,buf); //从文件偏移量10位置开始读取20个字节
//
//
//
// buf[20]=0;
//
//
znFAT_Close_File(&fileinfo); //关闭文件
}
else
{
UART_Send_StrNum("Fail to open file, Err Code:",res);
}
znFAT_Flush_FS(); //刷新文件系统
while(1);
return 0;
}
c--SD卡,读取,摘取出来浮点数,然后赋值
最新推荐文章于 2023-04-21 20:25:12 发布
