Click to See Complete Forum and Search --> : MSComm


Phil Thurmon
September 18th, 1999, 02:28 AM
I think I need to send or receive a signel to get a connetion to the computer I am dialing but I am not sure how to do it. I have looked at the program From MSDN but still do not undestand why theres will display data recived and mine will not. I can call my internet provider with their program and it will com back with username then it will start to send data. all mine does is display OK then the other computer will hangup.Here is my code
// DIAL_OUT.cpp : implementation file
//

#include "stdafx.h"
#include "Acculeve.h"
#include "DIAL_OUT.h"
#include "mscomm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

int m_ItemNum;
/////////////////////////////////////////////////////////////////////////////
// CDIAL_OUT dialog


CDIAL_OUT::CDIAL_OUT(CWnd* pParent /*=NULL*/)
: CDialog(CDIAL_OUT::IDD, pParent)
{
//{{AFX_DATA_INIT(CDIAL_OUT)
m_PhoneNum = _T("");
m_Transmit = _T("");
m_Recive = _T("");
m_NumberList = _T("");
//}}AFX_DATA_INIT
}


void CDIAL_OUT::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDIAL_OUT)
DDX_Text(pDX, IDC_EDIT2, m_PhoneNum);
DDV_MaxChars(pDX, m_PhoneNum, 13);
DDX_Text(pDX, IDC_TRANS, m_Transmit);
DDX_Text(pDX, IDC_RECIVE, m_Recive);
DDX_Control(pDX, IDC_MSCOMM1, m_MSComm);
DDX_LBString(pDX, IDC_LIST_NUMBERS, m_NumberList);
//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDIAL_OUT, CDialog)
//{{AFX_MSG_MAP(CDIAL_OUT)
ON_BN_CLICKED(ID_ADD_NUMBER, OnAddNumber)
ON_BN_CLICKED(ID_DELETE_NUMBER, OnDeleteNumber)
ON_BN_CLICKED(ID_DIAL, OnDial)
ON_LBN_DBLCLK(IDC_LIST_NUMBERS, OnDblclkListNumbers)
ON_EN_SETFOCUS(IDC_EDIT2, OnSetfocusEdit2)
ON_BN_CLICKED(IDD_DISCONNECT, OnDisconnect)
ON_EN_KILLFOCUS(IDC_RECIVE, OnKillfocusRecive)
ON_EN_KILLFOCUS(IDC_TRANS, OnKillfocusTrans)
ON_BN_CLICKED(ID_SEND, OnSend)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDIAL_OUT message handlers

BEGIN_EVENTSINK_MAP(CDIAL_OUT, CDialog)
//{{AFX_EVENTSINK_MAP(CDIAL_OUT)
ON_EVENT(CDIAL_OUT, IDC_MSCOMM1, 1 /* OnComm */, OnCommMscomm1, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

BOOL CDIAL_OUT::OnInitDialog()
{
CDialog::OnInitDialog();
int n;
m_ItemNum=-1;
CListBox* pBox=(CListBox*) GetDlgItem(IDC_LIST_NUMBERS);
for (int i=0; i < pBox->GetCount(); i++)
{
pBox->InsertString(n,m_NumberList);
}
CListBox* pLBox=(CListBox*) GetDlgItem(IDC_EDIT2);
pLBox->SetFocus();
m_MSComm.SetInBufferSize(1024);
m_MSComm.SetOutBufferSize(1024);
m_MSComm.SetInputLen(0);
m_MSComm.SetHandshaking(2);
m_MSComm.SetRThreshold(1);
m_MSComm.SetRTSEnable(TRUE);
m_MSComm.SetCommPort(2);
m_MSComm.SetSettings("28800,N,8,1");
m_MSComm.SetSThreshold(0);
m_MSComm.SetNullDiscard(FALSE);
m_MSComm.SetInputMode(1);
m_Transmit= "This test sending data better work\r";
m_PhoneNum="9728650073";
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}


void CDIAL_OUT::OnAddNumber()
{
UpdateData(TRUE);
CListBox* pBox=(CListBox*) GetDlgItem(IDC_LIST_NUMBERS);
m_NumberList=pBox->AddString(m_PhoneNum);
m_PhoneNum = "";
UpdateData(FALSE);
CListBox* pLBox=(CListBox*) GetDlgItem(IDC_EDIT2);
pLBox->SetFocus();

}

void CDIAL_OUT::OnDeleteNumber()
{
int iTemp;
CListBox* pBox=(CListBox*) GetDlgItem(IDC_LIST_NUMBERS);
iTemp=pBox->GetCurSel();
if (iTemp < 0)
return;
m_ItemNum=pBox->DeleteString(iTemp);
}

void CDIAL_OUT::OnDial()
{
CString phone_str;
UpdateData(TRUE);
phone_str="ATDT "+m_PhoneNum+";\r";
if (!m_MSComm.GetPortOpen()) m_MSComm.SetPortOpen(TRUE);

m_MSComm.SetOutput(COleVariant(phone_str));
m_MSComm.SetDTREnable(!m_MSComm.GetDTREnable());
}

void CDIAL_OUT::OnDblclkListNumbers()
{
CListBox* pBox=(CListBox*) GetDlgItem(IDC_LIST_NUMBERS);
m_ItemNum=pBox->GetCurSel();
pBox->GetText(pBox->GetCurSel(),m_PhoneNum);
UpdateData(false);
}

void CDIAL_OUT::OnSetfocusEdit2()
{
// TODO: Add your control notification handler code here

}

void CDIAL_OUT::OnCommMscomm1()
{

int n;
VARIANT Input1;
COleSafeArray Input2;
long length,i;
BYTE data[1024];
CString str;
if (m_MSComm.GetCommEvent()==2)
{
Input1 = m_MSComm.GetInput();
Input2=Input1;
length=Input2.GetOneDimSize();
for(i=0;i<length;i++)
Input2.GetElement(&i,data+i);
for(i=0;i<length;i++)
{
char a=*(char*)(data+i);
str.Format("%c",a);
m_Recive+=str;
}
}


UpdateData(FALSE);
}

void CDIAL_OUT::OnDisconnect()
{
m_MSComm.SetOutput(COleVariant("+++ATH+++\r"));
m_MSComm.SetPortOpen(FALSE);
}

void CDIAL_OUT::OnKillfocusRecive()
{
UpdateData(TRUE);

}

void CDIAL_OUT::OnKillfocusTrans()
{
// TODO: Add your control notification handler code here

}

void CDIAL_OUT::OnSend()
{
m_MSComm.SetOutput(COleVariant(m_Transmit));
}