Search code examples
c#phone-callmodem

Make outgoing call with built-in modem in C#


I have to call phone number and detect if the modem at the opposite side is hang-on. How can I do this in C# with SerialPort?


Solution

  • Yes, System.IO.Ports.SerialPort is the class to use.

    Something like this:

    // Set the port name, baud rate and other connection parameters you might need
    SerialPort port = new SerialPort("COM1", 9600 );
    port.Open();
    port.ReadTimeout = 1000;
    port.NewLine = "\r";
    port.WriteLine("ATZ"); // reset the modem
    port.ReadTo("OK\r\n"); // wait for "OK" from modem
    port.WriteLine("ATDT 12345678"); // dial number with dialtone
    string response = port.ReadTo("\r").Trim(); // read until first newline
    port.Close();
    

    It's not tested as I don't have a modem at hand.