【问题标题】:DTMF decode using python使用python进行DTMF解码
【发布时间】:2020-01-16 23:44:27
【问题描述】:

我正在尝试使用 python 脚本解码接收到SIM-800 模块的 DTMF 代码。

我的代码:

import serial,time

serialport = serial.Serial("/dev/ttyS0", 115200,timeout=1)

while True:
    command = serialport.read(10)
    ring = "RING"
    ring_command = command.decode('utf-8')
    ring_command = ring_command.strip()

    if ring_command == ring:

        serialport.write("ATA"+"\r")
        print serialport.read(20)

        serialport.write("AT+DDET=1"+"\r\n")  # enable DTMF 
        time.sleep(2)

        while True:
            dtmf = serialport.read(20)

            if dtmf != "":
                dtmf_new = dtmf.strip('+DTMF:')
                print dtmf_new
                time.sleep(1)
            else:
                print "There were notthing"

但我仍然得到输出:+DTMF: B。 为了解码RING 命令,我使用了raspberry-exchange 中的给定指令。 在strip()之前,我也尝试过decode('utf-8'),但答案仍然相同。

DTMF 代码由另一个 SIM-800 和 Raspberry-pi 发送。

提前致谢。

【问题讨论】:

  • 您想用dtmf_new = dtmf.strip('+DTMF:') 完成什么以及dtmf.read(... 之后的值如何。最后,你对dtmf_new 的期望是什么?
  • 我添加了dtmf_new 只是为了更清楚。 dtmf -> +DTMF: A,我期待dtmf_new = A
  • 我认为,您不必收到'RING'后配置调制解调器。将.write("ATA"+"\r").write("AT+DDET=1"+"\r\n") 移出while True: 并在之前发送且仅一次
  • @stovfl 那么我应该如何在不使用ATA 的情况下接听电话?
  • 你说得对,"ATA" 必须在那里,但你为什么只使用'\r'?你想用"AT+DDET=1" 完成什么?

标签: python python-2.7 raspberry-pi3 at-command


【解决方案1】:

在@stovfl 和我办公室的一些同事的帮助下,我已经解决了我的问题。

我刚刚更改了从 DTMF 接收结果代码的方式。

import serial,time

serialport = serial.Serial("/dev/ttyS0", 115200,timeout=1)

while True:
    command = serialport.read(10)
    print(command)
    ring = "RING"
    ring_command = command.decode('utf-8')       # Incoming call
    ring_command = ring_command.strip()          # Decoding incoming RING message
    print("Ring decoded : "+ ring_command)

    if ring_command == ring:
        serialport.write("ATA"+"\r")
        print serialport.read(10)

        serialport.write("AT+DDET=1"+"\r\n")     # enable DTMF
        print serialport.read(10)

        while True:
            dtmf = serialport.read(20)

            if len(dtmf) > 8:
                print dtmf[9]             # Just print the code we sent, Original -> `+DTMF: C`
                time.sleep(1)
            else:
                print "DTMF is less than 8 char"
                time.sleep(1)

我上面的代码,我试图从我的字符串中删除+DTMF:,这里我只是从接收字符串中获取[9] th元素。

这是 100% 有效的代码,经过多次测试。

【讨论】:

    猜你喜欢
    • 2011-04-03
    • 2012-01-27
    • 1970-01-01
    • 1970-01-01
    • 2021-02-19
    • 1970-01-01
    • 1970-01-01
    • 2011-03-04
    • 1970-01-01
    相关资源
    最近更新 更多