我使用mscomm控件写了一个modem的拨号程序,但是拨号后没有什么反应,不像超级终端那样对方的电话会响铃,麻烦各位高手帮我看下是不是哪里有问题,或者应该怎样改进,谢过~
void CModemCommDlg::OnComm() //消息映射
{
// TODO: Add your control notification handler code here
VARIANT vResponse;
char *str;
char *str1;
int k,nEvent,i;
nEvent=m_ctrlcomm.GetCommEvent();
switch(nEvent)
{
case 2://收到大于RTHresshold个字符
k=m_ctrlcomm.GetInBufferCount();
if(k>0)
{
vResponse=m_ctrlcomm.GetInput();//读取
//处理数据
str=(char*)(unsigned char*)vResponse.parray->pvData;
}
//接收字符,MSComm控件发送事件
i=0;
str1=str;
while(i<k);
{
i++;
str1++;
}
//清除不必要的字符
*str1='\0';
m_ReceiveData+=(const char*)str;
break;
case 3://CTS线状态变化
break;
case 4://DSR线状态变化
break;
case 5://CD线状态变化
break;
case 6://Ring Indicator发生变化
break;
}
UpdateData(false);
}
void CModemCommDlg::OnDial() //拨号按钮
{
// TODO: Add your control notification handler code here
CString strTemp;
if(!bOpen)
{
UpdateData(true);
bOpen=true;
//向猫发送指令
strTemp="ATDT"+m_TelphoneNo+"\n";
AfxMessageBox(strTemp);
SendString(strTemp);
m_ctrlDial.SetWindowText("挂断");
//AfxMessageBox(m_TelphoneNo);
}
else
{
SendString("ATH0");
bOpen=false;
m_ctrlDial.SetWindowText("拨号");
}
}
void CModemCommDlg::SendString(CString m_strSend) //字符发送函数
{
char TxData[100];
int Count=m_SendData.GetLength();
for(int i=0;i<Count;i++)
TxData[i]=m_SendData.GetAt(i);
CByteArray array;
array.RemoveAll();
array.SetSize(Count);
for(i=0;i<Count;i++)
array.SetAt(i,TxData[i]);
m_ctrlcomm.SetOutput(COleVariant(array));
}
void CModemCommDlg::OpenComm(int number) //选择、打开串口
{
if(!m_ctrlcomm.GetPortOpen())
{m_ctrlcomm.SetCommPort(number);
m_ctrlcomm.SetPortOpen(true);
SendString("ATS0=1\n");
bOpen=false;
m_ctrlDial.SetWindowText("拨号");
AfxMessageBox("打开成功!");
}
else
AfxMessageBox("该串口已被占用,请选择其他串口");
}