我用的是STC 單片機(jī) ,CH375,并口連接,要讀取的數(shù)據(jù)為: 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,.... 兩個OX25之間為一個數(shù)據(jù)包,共38個數(shù),現(xiàn)在只能讀出第一個包中的數(shù)據(jù),第二個包讀出來的就全是錯誤了, 代碼實現(xiàn)部分如下: mCmdParam.ByteLocate.mByteOffset = 0x00000030; /* 移到文件指定位置*/ i = CH375ByteLocate( ); mStopIfError( i ); z = CH375ByteRead( ); mStopIfError( z ); mDelay100mS(); TotalCount = 600; /* 準(zhǔn)備讀取總長度,以字節(jié)為單位 */ printf( "′從文件第8個數(shù)開始讀: \n" ); // 從第一個OX25開始讀 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 { 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]); } datalen=0; count=0; 問題 :第2個包的38個數(shù)讀不出來,麻煩 各位幫幫忙,謝謝