标题:串口通讯Debug Assertion Failed!问题求助
只看楼主
li343
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2009-10-9
结帖率:0
 问题点数:0 回复次数:0 
串口通讯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 编辑 ]
搜索更多相关主题的帖子: 通讯 Failed Debug 串口 Assertion 
2009-10-26 13:53



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-289971-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.174302 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved