1

我必须拨打电话号码并检测对面的调制解调器是否挂断。如何使用 SerialPort 在 C# 中执行此操作?

4

2 回答 2

3

是的,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();

它没有经过测试,因为我手头没有调制解调器。

于 2010-03-29T10:05:12.097 回答
0

您可以在正确配置的 Windows 中创建连接(因此您可以手动拨号)。然后使用 RAS API 拨号连接并检查结果。

于 2010-03-29T10:04:59.187 回答