串口通讯Debug Assertion Failed!问题求助
一个串口通讯程序,编译通过,运行出错,错误提示: Debug Assertion Failed!
Program:.....
File:olevar.cpp
Line:2553
For information on how your program can cause an assertion failure,see....
请赐招。
出错段程序如下:
程序代码:
double CHuoqvjiaoduDlg::Val(CString a) { int number=0; CString* p; int sum=0; for(p=&a;*p!='\0';p++) { if(*p>='0'&&*p<='9') { if(number==0) { sum=(atoi(*p)-48); number=1; } else sum=(sum*10+(atoi(*p)-48)); } else break; } return sum; } double CHuoqvjiaoduDlg::readGAM60Value(CString mingling) { int i,j,k; CString Buf(" "); CString InByte(""); CString aa(""); CByteArray OutB; double value; m_MSComm1.SetPortOpen(TRUE); m_MSComm1.SetInBufferCount(0); m_MSComm1.SetOutBufferCount(0); m_MSComm1.SetPortOpen(FALSE); Buf=mingling; Buf.TrimLeft(); Buf.TrimRight(); i = strlen(Buf); k = 0; OutB.RemoveAll(); OutB.SetSize((i/2)+1); j=0; while(i>0) { OutB[j]=atoi(Buf.Mid(k,2)); k = k + 2; i = i - 2; j = j + 1; } m_MSComm1.SetPortOpen(TRUE); m_MSComm1.SetInBufferCount(0); m_MSComm1.SetOutput(COleVariant(OutB)); VARIANT variant_inp; COleSafeArray safearray_inp; LONG len,z=0; BYTE rxdata[2048]; variant_inp=m_MSComm1.GetInput(); safearray_inp=(COleSafeArray)variant_inp; len=safearray_inp.GetOneDimSize(); for(z=0;z<len;z++) safearray_inp.GetElement(&z,rxdata+z); for(z=0;z<len;z++) { BYTE bt=*(char*)(rxdata+z); InByte.Format("%c",bt); } m_MSComm1.SetPortOpen(FALSE); if((InByte.Mid(1,1)) == "+") { aa = InByte.Mid(2,10); value = Val(aa); value=value * 0.01; } if((InByte.Mid(2,1)) == "+") { aa = InByte.Mid(3,10); value = Val(aa); value=value * 0.01; } if((InByte.Mid(3,1)) == "+") { aa = InByte.Mid(4,10); value = Val(aa); value=value * 0.01; } ~~~~~~~~~~~~~~~~~中间省略~~~~~~~~~~~~~~~~~ if((InByte.Mid(16,1)) == "+") { aa = InByte.Mid(17,10); value = Val(aa); value=value * 0.01; } return value; }
[ 本帖最后由 li343 于 2009-10-26 14:57 编辑 ]