Reputation:
I want to make a call from a GSM modem using C#. I have written the following code. but I am unable to make the call. Please tell what the mistake is. Also let me know how to handle the response in the code from the modem so that I can display a message like "call connecting" or "cannot connect".
private void button1_Click(object sender, EventArgs e)
{
SerialPort po = new SerialPort();
po.PortName = "COM3";
po.BaudRate = int.Parse( "9600");
po.DataBits = Convert.ToInt32("8");
po.Parity = Parity.None;
po.StopBits = StopBits.One;
po.ReadTimeout = int.Parse("300");
po.WriteTimeout = int.Parse("300");
po.Encoding = Encoding.GetEncoding("iso-8859-1");
po.Open();
po.DtrEnable = true;
po.RtsEnable = true;
po.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
po.Write("ATD9030665834;");
}
public void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
if (e.EventType == SerialData.Chars)
{
//what to write here to display the response??
}
}
Upvotes: 2
Views: 6658
Reputation: 440
private void button1_Click(object sender, EventArgs e)
{
SerialPort po = new SerialPort();
po.PortName = "COM10";
po.BaudRate = int.Parse("9600");
po.DataBits = Convert.ToInt32("8");
po.Parity = Parity.None;
po.StopBits = StopBits.One;
po.ReadTimeout = int.Parse("300");
po.WriteTimeout = int.Parse("300");
po.Encoding = Encoding.GetEncoding("iso-8859-1");
po.Open();
po.DtrEnable = true;
po.RtsEnable = true;
//po.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
// po.Write("ATD01814201013;");
po.WriteLine("ATD01"+textBoxPhoneNumber.Text+";"+Environment.NewLine);
}
Upvotes: 0
Reputation: 4962
Use port.WriteLine("ATD"+phno+";");
This will definitely solve your problem..
And to handle the response use port.ReadExisting() and compare with your requirement. As easy as that :)
Good luck..
Upvotes: 2
Reputation: 4115
po
same as Hyper-terminal as it is working with Hyperterminal.
Hyper Terminal settings are usually like:
If it has Flow Control as NONE then You don't need:
po.DtrEnable = true;
po.RtsEnable = true;
I don't find use of Setting encoding.
Most important thing You are forgetting is Add "\r" at the end of Any AT Command! Seems you haven't read AT Command list!
Upvotes: 1