//send mServer ATCMD message
CDc_clientDlg *pView = (CDc_clientDlg *)m_pView;
if ( pView->OuterSendCMPAT(m_IMEI, (UCHAR*)buf, len))//AT+DTU&IMEI?
{
m_InRunning = 1;
GetDlgItem(IDOK)->EnableWindow(FALSE);
m_iAtRspTimer = SetTimer(AT_RSP_TIMER_ID, 5000, NULL);
}
else
{
len = m_editRsp.GetWindowTextLength();
m_editRsp.SetSel(len, len);
CString str;
str.LoadString(IDS_VIEW_ATCMD_SEND_ERROR);
m_editRsp.ReplaceSel(str, FALSE);
}

}

解决方案 »

  1.   

    完整的源码如下:
    void CSendATCMDDlg::OnOK() 
    {
    char buf[128];
    int len; UpdateData(true);


    if (m_IMEI.GetLength() != IMEI_LEN)
    {
    AfxMessageBox(IDS_INVALID_IMEI, MB_OK|MB_ICONINFORMATION);
    return ;
    }

    m_editRsp.SetWindowText("");

    memset(buf, 0, sizeof(buf));

    m_LineIdx = 0;
    while (strcmp(buf, "\0") == 0 || strcmp(buf, "\n") == 0)
    {
    if (m_LineIdx == m_editATCmd.GetLineCount())
    break;
    len = m_editATCmd.GetLine(m_LineIdx++, buf, sizeof(buf));
    if (len > 0)
    buf[len] = '\0';
    else
    memset(buf, 0, sizeof(buf));
    }

    if (strcmp(buf, "\0") == 0) 
    {
    len = m_editRsp.GetWindowTextLength();
    m_editRsp.SetSel(len, len);
    CString str;
    str.LoadString(IDS_VIEW_ATCMD_LIST_EMPTY);
    m_editRsp.ReplaceSel(str, FALSE);
    return ;
    }

    strcat(buf, "\r");
    CDc_clientDlg *pView = (CDc_clientDlg *)m_pView;
    if ( pView->OuterSendCMPAT(m_IMEI, (UCHAR*)buf, len))//AT+DTU&IMEI?
    {
    m_InRunning = 1;
    GetDlgItem(IDOK)->EnableWindow(FALSE);
    m_iAtRspTimer = SetTimer(AT_RSP_TIMER_ID, 5000, NULL);
    }
    else
    {
    len = m_editRsp.GetWindowTextLength();
    m_editRsp.SetSel(len, len);
    CString str;
    str.LoadString(IDS_VIEW_ATCMD_SEND_ERROR);
    m_editRsp.ReplaceSel(str, FALSE);
    }

    }