0
我編寫了一個程序,當手機連接到筆記本電腦並獲得最後通話時間時自動撥號。我使用AT + CLCC命令獲取當前通話狀態。儘管它應該返回在一些字符串值作爲.......等我什麼也沒得到這樣的那麼遠,這裏是我的代碼..使用AT + CLCC命令獲取最後通話時長
_serialPort.BaudRate = 9600;
_serialPort.Parity = Parity.None;
_serialPort.DataBits = 8;
_serialPort.StopBits = StopBits.One;
_serialPort.Handshake = Handshake.None;
// Set the read/write timeouts
_serialPort.ReadTimeout = 500;
_serialPort.WriteTimeout = 500;
_serialPort.Open();
_serialPort.DtrEnable = true;
_serialPort.RtsEnable = true;
string phonenr = "";
// string mesaj;
if (!_serialPort.IsOpen)
{
_serialPort.Open();
}
_serialPort.WriteLine("AT\r");
{
Console.WriteLine("Enter the phone number:", phonenr);
phonenr = Console.ReadLine();
_serialPort.WriteLine("ATD" + phonenr + ";" + "\r");
Console.WriteLine("Ring...");
Thread.Sleep(10000);
_serialPort.WriteLine("AT+CLCC");
_serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
//As a seperate function....
private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string indata = sp.ReadExisting();
Console.WriteLine("Data Received:");
Console.Write(indata);
}
什麼是錯,此代碼????我怎麼能以格式獲得響應...等等?
你現在正在做什麼? –
在控制檯我得到數據接收! OK AT + CLCC OK,但沒有任何字符串編號,因爲我想要的 – user3292311