TotalCount=600; /* 自己定義的讀600字節(jié) */ while ( TotalCount ) { if ( TotalCount > MAX_BYTE_IO ) c = MAX_BYTE_IO; else c = TotalCount; mCmdParam.ByteRead.mByteCount = c; i = CH375ByteRead( ); mStopIfError( i ); TotalCount -= mCmdParam.ByteRead.mByteCount; for ( i=0; i!=mCmdParam.ByteRead.mByteCount; i++ ) {printf( "%c", mCmdParam.ByteRead.mByteBuffer[i] ); } 。。。。。。 }
文本文件內(nèi)容如下: 0x00, 0x00, 0x02, 0x30, 0x00, 0x00, 0x00, 0x00, 0x25, 0xb1, 0xb1, 0x10, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb5, 0xd8, 0xcf, 0xc2, 0xa3, 0xb1, 0xb3, 0xac, 0xca, 0xd0, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xca, 0x25, 0x01, 0x01, 0x10, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb5, 0xd8, 0xcf, 0xc2, 0xa3, 0xb1, 0xb3, 0xac, 0xca, 0xd0, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xa1, 0xcb, 0x25, 0x01, 0x01, 0x10, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb5, 0xd8, 0xcf, 0xc2, 0xa3, 0xb1, 0xb3, 0xac, 0xca, 0xd0, 0xa1, ...... //如上所示:用上邊的代碼讀文本文件的內(nèi)容都能讀出來(lái),可是在加入以下代碼之后 就只能讀出前38個(gè)數(shù)據(jù)了,再往后讀出來(lái)的就是錯(cuò)誤了
//代碼部分 把for ( i=0; i!=mCmdParam.ByteRead.mByteCount; i++ ) 的循環(huán)的內(nèi)容修改如下: for( i=0;i{ ch = mCmdParam.ByteRead.mByteBuffer[i]; switch(ch) { case 'x': { next1=mCmdParam.ByteRead.mByteBuffer[i+1]; next2=mCmdParam.ByteRead.mByteBuffer[i+2]; if((next1>=0x30)&&(next1<=0x39)) { next1=next1-0x30; } else if((next1>=0x61)&&(next1<=0x66)) { next1=next1-0x61+10; } else printf("error1"); if((next2>=0x30)&&(next2<=0x39)) { next2=next2-0x30; } else if((next2>=0x61)&&(next2<=0x66)) { next2=next2-0x61+10; } else printf("error2"); bao[datalen]= next1*16 + next2; datalen++; count++; } break; default: break; } } if(count%38==0) { for(i=0;i { printf("%c",bao[i]); /* 循環(huán)輸出當(dāng)前包中的數(shù)據(jù) */ } datalen=0; count=0; }
加上述代碼的目的 :是為了實(shí)現(xiàn)每讀取到38個(gè)數(shù)據(jù)的時(shí)候,就把這38個(gè)數(shù)據(jù)通過(guò)串口發(fā)出去; 問(wèn)題 1:應(yīng)用上邊的代碼只能讀出前38個(gè)數(shù)據(jù),再往后讀出來(lái)的就是錯(cuò)誤了,請(qǐng)問(wèn)如何解決? 2. 用375能讀寫(xiě)二進(jìn)制文件嗎?操作二進(jìn)制文件和操作文本文件在編程上有何區(qū)別? 麻煩各位幫俺 看看 ,謝謝