获取AT命令调用响应

时间:2016-11-26 09:23:18

标签: command at-command

我正在尝试使用USB调制解调器进行语音呼叫,并且它成功拨打电话......现在我想获得该呼叫响应以了解号码是否响铃,忙或不可用

这是我用过的代码:

      string number = textBox1.Text;

        po.PortName = "COM3";
        po.BaudRate = int.Parse("9600");
        po.DataBits = Convert.ToInt32("8");
        po.Parity = Parity.None;
        po.StopBits = StopBits.One;
        po.ReadTimeout = int.Parse("300");
        po.WriteTimeout = int.Parse("300");
        po.Encoding = Encoding.GetEncoding("iso-8859-1");
        po.Open();
        po.DtrEnable = true;
        po.RtsEnable = true;
        po.Write("ATDT "+number+";\r"); 

        System.Threading.Thread.Sleep(7000);

        po.WriteLine("ATH+CHUP;\r");
        po.DiscardInBuffer();
        po.DiscardOutBuffer();
        po.Close();

1 个答案:

答案 0 :(得分:1)

在ATD之后,您需要读取端口以获取有关URC的信息。

对于语音通话,有以下可能的响应,

  

如果没有拨号音   没有拨号

  如果忙,   忙碌

  如果无法建立连接:
  没有承运人
  没有答案

而且,在ATD之前,您最好使用 at + cmee 设置错误格式,对于考试,+ cmee = 2将启用字符串格式。

编辑:(这是python的一个例子)

#! /usr/bin/env python
# -*- coding: utf8 -*-
from __future__ import print_function

import sys
import serial


NUM = "111111111"

ser = serial.Serial("com1", 115200)

ser.write('at+cmee=2\r')
ser.timeout = 10.0
res = "invalid"
while len(res) > 0:
    res = ser.read(1)
    print(res, end='')

ser.write('atd' + NUM + ';\r')
ser.timeout = 60.0
res = "invalid"
while len(res) > 0:
    res = ser.read(1)
    print(res, end='')

ser.write("AT+CHUP\r")
ser.timeout = 10.0
res = "invalid"
while len(res) > 0:
    res = ser.read(1)
    print(res, end='')

它的输出是(我拒绝来自电话的电话" 111111111"),

at+cmee=2
OK
atd111111111;
OK

NO CARRIER
AT+CHUP
+CME ERROR: operation not allowed

并且,在输出“没有运营商”之后,就不再需要挂机了。