views:

365

answers:

2

Hi,

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 ?

Thanks in advance

BEst regards

A: 

You could create a connection in windows that is configured correctly (so you could manually dial it). Then use the RAS API to dial the connection an check the result.

Thorsten Dittmar
+1  A: 

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(">"); // wait for prompt
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.

Mikael Svenson