【发布时间】:2010-03-29 08:41:51
【问题描述】:
我必须拨打电话号码并检测对面的调制解调器是否挂起。 如何在 C# 中使用 SerialPort 执行此操作?
【问题讨论】:
标签: c# phone-call modem
我必须拨打电话号码并检测对面的调制解调器是否挂起。 如何在 C# 中使用 SerialPort 执行此操作?
【问题讨论】:
标签: c# phone-call modem
是的,System.IO.Ports.SerialPort 是要使用的类。
类似这样的:
// 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();
因为我手头没有调制解调器,所以没有经过测试。
【讨论】:
您可以在正确配置的 Windows 中创建连接(因此您可以手动拨号)。然后使用 RAS API 拨号连接并检查结果。
【讨论】: