开发者

Make outgoing call with built-in modem in C#

开发者 https://www.devze.com 2022-12-24 06:11 出处:网络
I have to call phone number and detect if the modem at the op开发者_JS百科posite side is hang-on.

I have to call phone number and detect if the modem at the op开发者_JS百科posite side is hang-on. How can I do this in C# with SerialPort?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号