Hazoomo
Hazoomo

Reputation: 55

Dial call using C#.net by AT Commands

I want to make a c# program that connects to my mobile phone by usb cable to make just a call. I found how to connect by SerialPort and how to make call by AT Commands, but when I run my program and click to make the call, nothing happens. This is my code, please Help me:

SerialPort SP = new SerialPort("COM3");
SP.BaudRate = 9600;
SP.Parity = Parity.None;
SP.DataBits = 8;
SP.StopBits = StopBits.One;
SP.RtsEnable = true;
SP.DtrEnable = true;
SP.Encoding = System.Text.Encoding.Unicode;
SP.ReceivedBytesThreshold = 1;
SP.NewLine = Environment.NewLine;
SP.Open();
SP.Write("ATDT 0999182542"+ Environment.NewLine);

SP.Close();

Upvotes: 2

Views: 12035

Answers (3)

FraK
FraK

Reputation: 1089

@Cdeez Your answer is the best! it works just fine XD I tried but my mistake was not including the "\r" which works as pressing "enter", and you need to press enter for the command to take action. By the way here is my method for calling, and thanks @Cdeez once again !:

private void Call() {
        SerialPort celu = new SerialPort();
        celu.PortName = "COM13"; // You have check what port your phone is using here, and replace it
        celu.Open();
        string cmd = "ATD";  // Here you put your AT command
        string phoneNumber = "784261259"; // Here you put the phone number, for me it worked just with the phone number, not adding any other area code or something like that
        celu.WriteLine(cmd + phoneNumber + ";\r");
        Thread.Sleep(500);
        string ss = celu.ReadExisting();
        if (ss.EndsWith("\r\nOK\r\n"))
        {
            MessageBox.Show("Modem is connected \r Calling : " + phoneNumber);
        }
        celu.Close();
    }

Upvotes: 2

Shiridish
Shiridish

Reputation: 4962

First of all to see if your modem is connected, send an AT command to the port. If you get a OK as response, then it means your modem is connected.

To make a call the syntax is:

ATDYourphnumber; //Donot forget the ";"

Example: ATD9012345645;

So you should write to the port the same way.

Syntax:

SP.WriteLine("ATD"+phonenumber+";");

You can use WriteLine since that serves the \r\n too.

Update: How to see the response from modem:

After SP.Open( ) ;

string cmd = "AT";
SP.WriteLine(cmd + "\r");
SP.Write(cmd + "\r");
Thread.Sleep(500);
string ss= SP.ReadExisting();
if(ss.EndsWith("\r\nOK\r\n"))
  {
   MessageBox.Show("Modem is connected");
  }

Upvotes: 4

syned
syned

Reputation: 2321

What about COM port logging tools. Do you use it? Did your commands send to COM port?

As far as I know dial command is ATD[Number]; so try to rewrite your code as follows:

    SP.Write("ATD0999182542;"+ Environment.NewLine);

Try to use this library: GSM Communication Library

Upvotes: 0

Related Questions