我寫了一個簡單的程序,它通過串口發送一個AT命令。 我跟着指令 MSDN EXAMPLE串口WriteLine有時會失敗
串行端口(38400,N,8,1)
serialPort1.PortName = "COM" + "5";// textBox1.Text;
try
{
if (!(serialPort1.IsOpen))
serialPort1.Open();
// if (listBox1.SelectedIndex == 0 || listBox1.SelectedIndex == 1)
serialPort1.WriteLine("atrst");
// else
// serialPort1.WriteLine("araprst");
serialPort1.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error opening/writing to serial port :: " + ex.Message, "Error!");
Application.Exit();
}
當我使用WriteLine命令有時AT命令不被髮送到的端口。 任何想法爲什麼?, 有沒有辦法知道WriteLine(String)失敗?
雖然你的代碼是什麼?命令有多大,你的波特率是多少。 – Serdalis 2013-02-10 15:58:35
您是否嘗試處理[ErrorReceived事件](http://msdn.microsoft.com/zh-cn/library/system.io.ports.serialport.errorreceived.aspx)? – 2013-02-10 16:28:08
這是你的實際碼嗎?你似乎沒有設置任何東西,甚至不初始化SerialPort。 – Serdalis 2013-02-10 21:23:47