小弟在尝试做一个测试程序时遇到一个难以解决的问题,耽搁了好多天。我用的是CSerialPort类编写,基本上所有功能都基本实现,但是在用check box 结合button做测试module基本function测试的时候发现一个问题,希望得到大家的解答:
这个问题是 当Check box选择在三个以上(包含三个)的时候,点测试button的时候只有头和尾2个测试选项起作用,中间的AT指令发送和反馈都丢失了,请问各位高手,这里是不是存在没有处理modem反馈数据导致堵塞的问题?但是前面有个OnComm()是对接受字符做处理的,难道还要做另外的处理?另外测试过程中用了sleep()做延迟,会不会在这出了问题?我在下面给出了大部分原代码,方便大家帮我查问题,也希望得到大家的指点
BEGIN_MESSAGE_MAP(CFidelixModuleTestToolDlg, CDialog)
//{{AFX_MSG_MAP(CFidelixModuleTestToolDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_MESSAGE(WM_COMM_RXCHAR,OnComm) //消息映射
ON_BN_CLICKED(IDC_BUTTON_OPEN, OnButtonOpen)
ON_BN_CLICKED(IDC_BUTTON_CLOSE, OnButtonClose)
ON_BN_CLICKED(IDC_BUTTON_SEND, OnButtonSend)
ON_BN_CLICKED(IDC_BUTTON_ClearReceive, OnBUTTONClearReceive)
ON_BN_CLICKED(IDC_BUTTON_ClearSend, OnBUTTONClearSend)
ON_BN_CLICKED(IDC_CHECK_AutoSend, OnCHECKAutoSend)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON1, OnButtonTestModule)
ON_BN_CLICKED(IDC_CHECK_VER, OnCheckVer)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CFidelixModuleTestToolDlg message handlersBOOL CFidelixModuleTestToolDlg::OnInitDialog()
{
CDialog::OnInitDialog();
    m_ctrlComboComPort.SetCurSel(0); 
m_ctrlComboBaud.SetCurSel(0);
// Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
} // Set the icon for this dialog.  The framework does this automatically
//  when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here
m_ctrlCheckVer.SetCheck(0);
//m_ctrlComboComPort.setCurSel(0);
//m_ctrlComboBaud.setCurSel(0);

return TRUE;  // return TRUE  unless you set the focus to a control
}void CFidelixModuleTestToolDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.void CFidelixModuleTestToolDlg::OnPaint() 
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
LONG CFidelixModuleTestToolDlg::OnComm(WPARAM ch,LPARAM port)
{
m_strEditRMsg+=ch;
UpdateData(FALSE);//将接收到的字符显示在接收编辑框中
return 0;
}
// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CFidelixModuleTestToolDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}void CFidelixModuleTestToolDlg::OnButtonOpen() 
{
// TODO: Add your control notification handler code here
int nPort=m_ctrlComboComPort.GetCurSel()+1;//
        int i=m_ctrlComboBaud.GetCurSel();
switch(i)
{
case 0:
i=9600;
break;
case 1:
i=19200;
break;
case 2:
i=38400;
break;
case 3:
i=57600;
break;
case 4:
i=115200;
break;
case 5:
i=230400;
break;

default:
break;
}
int nBaud=i;
if(m_SerialPort.InitPort(this,nPort,nBaud,'N',8,1,EV_RXFLAG|EV_RXCHAR,512))
{
m_SerialPort.StartMonitoring();
m_bSerialPortOpened=TRUE;
}
else
{
AfxMessageBox("没有发现此串口或被占用");
    m_bSerialPortOpened=FALSE;
}
GetDlgItem(IDC_BUTTON_OPEN)->EnableWindow(!m_bSerialPortOpened);
    GetDlgItem(IDC_BUTTON_CLOSE)->EnableWindow(m_bSerialPortOpened);
}void CFidelixModuleTestToolDlg::OnButtonClose() 
{
// TODO: Add your control notification handler code here
m_SerialPort.ClosePort();//关闭串口
m_bSerialPortOpened=FALSE;
GetDlgItem(IDC_BUTTON_OPEN)->EnableWindow(!m_bSerialPortOpened);
    GetDlgItem(IDC_BUTTON_CLOSE)->EnableWindow(m_bSerialPortOpened);
}void CFidelixModuleTestToolDlg::OnButtonSend() 
{
// TODO: Add your control notification handler code here
    if(!m_bSerialPortOpened) return;//检查串口是否打开
UpdateData(TRUE);//读入编辑框中的数据
m_SerialPort.WriteToPort((LPCTSTR)m_strEditSendMsg);//发送数据

}void CFidelixModuleTestToolDlg::OnBUTTONClearReceive() 
{
// TODO: Add your control notification handler code here
m_strEditRMsg.Empty();
// m_ReceiveData.Empty();
UpdateData(FALSE);
}void CFidelixModuleTestToolDlg::OnBUTTONClearSend() 
{
// TODO: Add your control notification handler code here
m_strEditSendMsg.Empty();
UpdateData(FALSE);
}
void CFidelixModuleTestToolDlg::OnCHECKAutoSend() 
{
// TODO: Add your control notification handler code here
m_bAutoSend=!m_bAutoSend;//标志是否打开自动发送
if(m_bAutoSend)
{
if(m_SerialPort.m_hComm==NULL)
{
m_bAutoSend=!m_bAutoSend;
m_ctrlAutoSend.SetCheck(0);
AfxMessageBox("串口没有打开,请打开串口");
return;
}
else
SetTimer(1,m_nCycleTime,NULL);
}
else
{
KillTimer(1);
}
} void CFidelixModuleTestToolDlg::OnTimer(UINT nIDEvent) 
{
// TODO: Add your message handler code here and/or call default
OnButtonSend();
CDialog::OnTimer(nIDEvent);

void CFidelixModuleTestToolDlg::OnButtonTestModule() 
{
// TODO: Add your control notification handler code here
    CString ATstr;
    if(m_ctrlCheckVer.GetCheck())

ATstr="at+gmr\r";  
m_SerialPort.WriteToPort((LPCTSTR)ATstr);
Sleep(10);
}
if(m_ctrlCheckUim.GetCheck())
    {
ATstr="at$fxusts\r";
    m_SerialPort.WriteToPort((LPCTSTR)ATstr);
Sleep(10);
    }
if(m_ctrlCheckCad.GetCheck())
{
ATstr="at+cad?\r";
    m_SerialPort.WriteToPort((LPCTSTR)ATstr);
Sleep(10);
}
    if(m_ctrlCheckCsq.GetCheck())
{
ATstr="at+csq?\r";
    m_SerialPort.WriteToPort((LPCTSTR)ATstr);
Sleep(10);
}
}

void CFidelixModuleTestToolDlg::OnCheckVer() 
{
// TODO: Add your control notification handler code here

}void CFidelixModuleTestToolDlg::OnCheckUIM() 
{
// TODO: Add your control notification handler code here

}