PDA

View Full Version : تماس تلفنی با مودم 3g



mghalgar
یک شنبه 13 مهر 1393, 09:04 صبح
​من میخوام یه برنامه با C#‎‎‎‎ بنویسم برای تماس خروجی و ورودی از کامپیوتر با مودم 3g .
برنامه رو با Atapi.NET نوشتم برای مودم های دیال آپ جواب میده ولی با مودم 3g جواب نمیده .
using System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Configuration;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using JulMar.Atapi;






namespace prjMakePhoneCall
{
// Line numbers are given for understanding and are not part of the actual code
public partial class frmPersons : Form
{
private TapiManager tapiManager = new TapiManager("prjMakePhoneCall");

private string lineName, logEntry = string.Empty;
string name = "";
public frmPersons()
{
InitializeComponent();


///ezafe shod
tapiManager.Initialize();


name = tapiManager.Lines[24].Name;
this.lineName = (tapiManager != null && tapiManager.Lines.Length > 0 ? name : string.Empty);






foreach (TapiLine line in tapiManager.Lines)
{


line.NewCall += this.OnNewCall;
line.Ringing += this.OnRinging;
}

}

private void OnNewCall(object sender, NewCallEventArgs e)
{
if (InvokeRequired == true)
{
this.BeginInvoke(new EventHandler<NewCallEventArgs>(this.OnNewCall), new object[] { sender, e });
return;
}


//ActiveCallForm acf = new ActiveCallForm(e.Call);
//acf.Show();
}
private void OnRinging(object sender, EventArgs e)
{
if (InvokeRequired == true)
{
this.BeginInvoke(new EventHandler<RingEventArgs>(this.OnRinging), new object[] { sender, e });
return;
}


//if (sender == name)
//{
label1.Text = "Ringing...";

//}
}
private void frmPersons_Load(object sender, EventArgs e)
{
tapiManager.Initialize();


this.lineName = (tapiManager != null && tapiManager.Lines.Length > 0 ? tapiManager.Lines[0].Name : string.Empty);
}


private void frmPersons_FormClosed(object sender, FormClosedEventArgs e)
{
tapiManager.Shutdown();
Application.ExitThread();
}




private void frmPersons_FormClosing(object sender, FormClosingEventArgs e)
{

}




private void btnCall_Click(object sender, EventArgs e)
{
if(this.txtPhone.Text.Trim().Length > 0)
this.MakePhoneCall(this.txtPhone.Text);
}




private void MakePhoneCall(string phoneNumber)
{
TapiLine line = tapiManager.GetLineByName(this.lineName, true);

if (line != null)
{
if (!line.IsOpen)
line.Open(MediaModes.DataModem);

line.NewCall += new EventHandler<NewCallEventArgs>(line_NewCall);
line.CallInfoChanged += new EventHandler<CallInfoChangeEventArgs>(line_CallInfoChanged);
line.CallStateChanged += new EventHandler<CallStateEventArgs>(line_CallStateChanged);

if (phoneNumber.Length > 0)
{
MakeCallParams makeCallParams = new MakeCallParams();
makeCallParams.DialPause = 2000;
try
{
TapiCall call = line.MakeCall(phoneNumber, null, makeCallParams);
this.MakeLogEntry("Created call " + phoneNumber + " -> " + call, "Sending…");
}
catch (Exception exc)
{
if (exc.Message.IndexOf("[0x80000005]") > -1 && tapiManager != null)
{
tapiManager.Shutdown();
tapiManager = new TapiManager("prjMakePhoneCall");
if (tapiManager.Initialize())
this.MakePhoneCall(phoneNumber);
}
}
}
}
}

private void line_NewCall(object sender, NewCallEventArgs e)
{
this.MakeLogEntry("New call: " + e.Call, e.Privilege.ToString());
}

private void line_CallStateChanged(object sender, CallStateEventArgs e)
{
this.MakeLogEntry("CallState: " + e.Call.ToString(), e.CallState.ToString());
}

private void line_CallInfoChanged(object sender, CallInfoChangeEventArgs e)
{
this.MakeLogEntry("CallInfo: " + e.Call.ToString(), e.Change.ToString());
}


private void MakeLogEntry(string callInfo, string status)
{
this.logEntry += DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString() + " : " + callInfo + ", " + status + "|";
}





}
}