以字节方式读取文本!?请hcn帮忙。

void CH375FileByteRead_320(UINT16 N_bit,UINT16 C_line) { static UINT8 i,ch; UINT16 k=0; UINT16 TotalCount,c; volatile uint16 *file_bit_buff_1;

file_bit_buff_1 = (volatile uint16 *)(ExSRAM_ADDR1); // strcpy( (char *)mCmdParam.Open.mPathName, "/NEWFILE.TXT" ); /* 文件名,该文件在C51子目录下 */ // strcpy( (char *)mCmdParam.Open.mPathName, "/NEWFILE.TXT" ); // i = CH375FileOpen( ); /* 打开文件 */ TotalCount = N_bit; /* 准备读取总长度 */ // MAX_BYTE_IO=32 // printf( "从文件中读出的前%d个字符是:\n",TotalCount ); // mCmdParam.ByteLocate.mByteOffset = 650*C_line; // 跳过文件的前324个字节开始读写,估计多出了换行。 CH375ByteLocate( ); while ( TotalCount ) { /* 如果文件比较大,一次读不完,可以再调用CH375ByteRead继续读取,文件指针自动向后移动 */ if ( TotalCount > MAX_BYTE_IO ) c = MAX_BYTE_IO; /* 剩余数据较多,限制单次读写的长度不能超过 sizeof( mCmdParam.ByteRead.mByteBuffer ) */ else c = TotalCount; /* 最后剩余的字节数 */ mCmdParam.ByteRead.mByteCount = c; /* 请求读出几十字节数据 */ i = CH375ByteRead( ); /* 以字节为单位读取数据块,单次读写的长度不能超过MAX_BYTE_IO,第二次调用时接着刚才的向后读 */ mStopIfError( i ); TotalCount -= mCmdParam.ByteRead.mByteCount; /* 计数,减去当前实际已经读出的字符数 */ for ( i=0; i // printf( "%C", mCmdParam.ByteRead.mByteBuffer[i] ); /* 显示读出的字符 */ // file_bit_buff_1 [k++] = mCmdParam.ByteRead.mByteBuffer[i] ; //处理 { ch = (mCmdParam.ByteRead.mByteBuffer[i]) ; if((ch>='0')&&(ch<='9')) ch= ch-0x30; else if((ch>='A')&&(ch<='F')) { ch= ch-'A'+10; switch (ch) { case 10: ch=0x0A; break; case 11: ch=0x0b; break; case 12: ch=0x0c; break; case 13: ch=0x0d; break; case 14: ch=0x0e; break; case 15: ch=0x0f; break; } } file_bit_buff_1 [k]=ch<<4 ; ch = (mCmdParam.ByteRead.mByteBuffer[++i]) ; if((ch>='0')&&(ch<='9')) ch= ch-0x30; else if((ch>='A')&&(ch<='F')) { ch= ch-'A'+10; switch (ch) { case 10: ch=0x0A; break; case 11: ch=0x0b; break; case 12: ch=0x0c; break; case 13: ch=0x0d; break; case 14: ch=0x0e; break; case 15: ch=0x0f; break; } } file_bit_buff_1 [k++] |= ch ; } if ( mCmdParam.ByteRead.mByteCount < c ) { /* 实际读出的字符数少于要求读出的字符数,说明已经到文件的结尾 */ // printf( "\n" ); // printf( "文件已经结束\n" ); break; } } } 问题: ch375读取文本文件。 当读取到10600左右个字节时,没有按正常顺序读出,10600前都正常。是什么原因产生的?

你的这部分程序没什么问题。不正常会不会出错呢?


什么地方出错呢?


我的意思是说在你数据不正常的时候,会不会出错,看下返回的错误代码才可以进行分析


文本文件的数据不正常是怎么产生的? i = CH375ByteRead( ); i都会等于0。 5400015B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B15 5400025B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B5B16 以上文本类型

就是 读行数多了,375读取时会越过好几行,大约10600左右个字节时,接着又能正常读取数据了。 不知哪里出错了!!


你可以不可以将你的程序发过来看下啊。 E-MIAL:tech@wch.cn


程序就是前面的。


int main_x( ) { ... ... //初始化硬件,ch375 while (1) { CH375File_open( FileTitle1); //打开文本 for (i=0x00;i<33;i++) CH375FileByteRead_320 (648,i ); CH375FileByteRead_320 (648,i ); //i等于33,读的数据开始不正常,跳过8000多过字节。

for (i=0x33;i<240;i++) //接下来又正常的顺序,但是否一直正常未知。 CH375FileByteRead_320 (648,i ); }

} //子程序 //每次读648个字节。 如果有换行就多出字节了,说明文本要一定的格式!!!??? void CH375FileByteRead_320(UINT16 N_bit,UINT16 C_line) { static UINT8 i,ch; UINT16 k=0; UINT16 TotalCount,c; volatile uint16 *file_bit_buff_1;

file_bit_buff_1 = (volatile uint16 *)(ExSRAM_ADDR1); // strcpy( (char *)mCmdParam.Open.mPathName, "/NEWFILE.TXT" ); /* 文件名,该文件在C51子目录下 */ // strcpy( (char *)mCmdParam.Open.mPathName, "/NEWFILE.TXT" ); // i = CH375FileOpen( ); /* 打开文件 */ TotalCount = N_bit; /* 准备读取总长度 */ // MAX_BYTE_IO=32 // printf( "从文件中读出的前%d个字符是:\n",TotalCount ); // mCmdParam.ByteLocate.mByteOffset = 650*C_line; // 跳过文件的前324个字节开始读写,估计多出了换行。 CH375ByteLocate( );

while ( TotalCount ) { /* 如果文件比较大,一次读不完,可以再调用CH375ByteRead继续读取,文件指针自动向后移动 */ if ( TotalCount > MAX_BYTE_IO ) c = MAX_BYTE_IO; /* 剩余数据较多,限制单次读写的长度不能超过 sizeof( mCmdParam.ByteRead.mByteBuffer ) */ else c = TotalCount; /* 最后剩余的字节数 */ mCmdParam.ByteRead.mByteCount = c; /* 请求读出几十字节数据 */ i = CH375ByteRead( ); /* 以字节为单位读取数据块,单次读写的长度不能超过MAX_BYTE_IO,第二次调用时接着刚才的向后读 */ mStopIfError( i ); TotalCount -= mCmdParam.ByteRead.mByteCount; /* 计数,减去当前实际已经读出的字符数 */ for ( i=0; i// printf( "%C", mCmdParam.ByteRead.mByteBuffer ); /* 显示读出的字符 */ // file_bit_buff_1 [k++] = mCmdParam.ByteRead.mByteBuffer //处理 { ch = (mCmdParam.ByteRead.mByteBuffer) if((ch>='0')&&(ch<='9')) ch= ch-0x30; else if((ch>='A')&&(ch<='F')) { ch= ch-'A'+10; switch (ch) { case 10: ch=0x0A; break; case 11: ch=0x0b; break; case 12: ch=0x0c; break; case 13: ch=0x0d; break; case 14: ch=0x0e; break; case 15: ch=0x0f; break; } } file_bit_buff_1 [k]=ch<<4 ch = (mCmdParam.ByteRead.mByteBuffer[++i]) if((ch>='0')&&(ch<='9')) ch= ch-0x30; else if((ch>='A')&&(ch<='F')) { ch= ch-'A'+10; switch (ch) { case 10: ch=0x0A; break; case 11: ch=0x0b; break; case 12: ch=0x0c; break; case 13: ch=0x0d; break; case 14: ch=0x0e; break; case 15: ch=0x0f; break; } } file_bit_buff_1 [k++] |= ch } if ( mCmdParam.ByteRead.mByteCount < c ) { /* 实际读出的字符数少于要求读出的字符数,说明已经到文件的结尾 */ // printf( "\n" ); // printf( "文件已经结束\n" ); break; } } }


我要读取2M的文本,以上程序只是测试,LOCATE的命令是在什么子程序中产生的?


多字节写入也存在问题。512字节*10次后就不能写入了,等待375中断,一直没反应。


mCmdParam.ByteLocate.mByteOffset = 608; 跳过文件的前608个字节开始读写 CH375ByteLocate( ); 只要文件不关闭,就可以不用ByteLocate,文件自动按顺序。


如果按照你上面的说法的话,你读2M的数据的话,你没必要用LOCATE这个命令,你在你的TotalCount的输入的数据为文件的总长度CH375vFileSize,这样的话,你就可以在那边进行循环的读取数据了,还有就是你用的是什么单片机?我在这边用51单片机做过测试的,读取2M的文件的时候是没有问题的,如果是51的话,你可以参考这个例子UploadImages/hcn0012006629135025.rar


总长度CH375vFileSize,哦,我考虑


很多时候会,等待375中断。是不是PCB不好!!


很多时候会,等待375中断。是不是PCB不好?,还是哪些参数没设好(时间控制),我用lpc2212单片机,请指导!


这是一个2212的例子程序,先进行AD采集,将采集的数据存到U盘里面去的例子,你测试下看可以不可以。我在这边测试的时候是以总线方式进行测试的,你如果不是的话,你可以将其改写为模拟口的方式,如果这个程序在写的过过程中还有问题的话,那可能就是你硬件有点问题了,否则就是你软件上面有点问题UploadImages/hcn0012006630173132.rar


只有登录才能回复,可以选择微信账号登录