我正在編寫一個串口應用程序,通過串口與藍牙模塊進行通信。我發送給設備的第一個At
命令運行正常,我得到模塊版本的響應。所有後續的命令都會失敗並返回ERROR。代碼的SerialPort First Command OK。第二個命令錯誤
部分是在這裏:
namespace PhoneApp
{
public partial class Form1 : Form
{
//SerialPort myport = OPenPort.OpenIt();
SerialPort myport = new SerialPort();
public Form1()
{
InitializeComponent();
myport.PortName = "COM3";
myport.BaudRate = 115200;
myport.Parity = Parity.None;
myport.DataBits = 8;
myport.StopBits = StopBits.One;
myport.NewLine = System.Environment.NewLine;
myport.ReadTimeout = 500;
myport.WriteTimeout = 500;
myport.DtrEnable = false;
myport.RtsEnable = false;
myport.WriteBufferSize = 4096;
myport.ReadBufferSize = 4096;
myport.Handshake = Handshake.None;
myport.Encoding = System.Text.Encoding.ASCII;
if (!myport.IsOpen)
{
myport.Open();
}
calling.Visible = false;
myport.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
mycommand.Text = @"AT+BGVER";
,它發送命令的按鈕。該設備在每次命令後都需要一個換行符。
private void button2_Click(object sender, EventArgs e)
{
try
{
myport.WriteLine(mycommand.Text.Trim());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
不知道我在這裏錯過了什麼。
您可以使用終端程序與設備通信嗎? – dbasnett 2013-03-05 19:35:46