我正在开发一个应用程序,它将读取和写入数据到 gsm 调制解调器。当我关闭调制解调器并再次打开时,在启动时我需要发送一个 AT 命令,以便调制解调器自动设置为端口的设置。当我在超级终端中发出此命令时,它不会显示,但命令会发送到调制解调器。并且调制解调器将自己设置为我为超级终端端口设置提供的设置。从那时起,我可以发送其余的命令。但在我的应用程序中,我无法发送第一个 AT 命令,因此我通过超级终端手动执行此操作。为什么这没有通过我的应用程序发生?我也尝试使用按钮单击发送此命令,但仍未在端口上执行。
port.Open();
port.DtrEnable = true;
port.RtsEnable = true;
if (port != null)
{
btn_connect.Enabled = false;
btn_disconnect.Enabled = true;
port.WriteLine("AT");
port.WriteLine("AT+CLIP=1");
port.WriteLine("AT+CMGF=1");
con_status.Text = "Connected at " + cboPortName.Text;
}
我在我的应用程序中提供的端口设置是:
port.PortName = cboPortName.Text;
port.BaudRate = Convert.ToInt32(this.cboBaudRate.Text); //9600
port.DataBits = Convert.ToInt32(this.cboDataBits.Text); //8
port.ReadTimeout = Convert.ToInt32(this.txtReadTimeOut.Text); //300
port.WriteTimeout = Convert.ToInt32(this.txtWriteTimeOut.Text); //300
port.StopBits = StopBits.One; //1
port.Parity = Parity.None; // None
port.Encoding = Encoding.GetEncoding("iso-8859-1");
port.Open();
port.DtrEnable = true;
port.RtsEnable = true;