我正在尝试使用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发送。
提前谢谢。
发布于 2019-09-18 18:04:48
在@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%的工作代码,经过多次测试。
https://stackoverflow.com/questions/57951737
复制相似问题