有没有办法告诉 wvdial 等待命令的答复?

有没有办法告诉 wvdial 等待命令的答复?

某些AT命令会wvdial延迟返回答案。这段时间取决于命令。例如,当您想要扫描可用网络时,可以使用该AT+COPS=?命令。扫描过程大约需要30s,但wvdial不会等到完成后重新发送命令。第二次尝试后,wvdial放弃并出现以下错误:

# wvdial info-scan
--> WvDial: Internet dialer version 1.61
--> Initializing modem.
--> Sending: AT+COPS=?
--> Re-Sending: AT+COPS=?
--> Modem not responding.

一段时间(30秒)后,我可以通过发出另一个命令wvdial,它可以是任何命令,例如ATZ+CFUN=1,当调制解调器已经打开时,它不执行任何操作,但发送命令后,我得到前一个命令的输出:

# wvdial modem-start
--> WvDial: Internet dialer version 1.61
--> Initializing modem.
--> Sending: ATZ+CFUN=1
+COPS: (2,"T-Mobile.pl","TM PL","26002",2),(1,"T-Mobile.pl","TM
PL","26002",7),(3,"Plus","PLUS","26001",7),
(3,"Play","Play","26006",7),(3,"Orange","Orange","26003",7),
(3,"Play","Play","26006",2),(3,"Orange","Orange","26003",2),
(3,"Plus","PLUS","26001",2),,(0,1,2,3,4),(0,1,2)
OK

那么有没有办法为命令设置某种超时,以便他们可以获得延迟的答案?

答案1

我通过创建这个 python 脚本的一些技巧解决了这个问题,它将等待大约 40 秒或一分钟:

import serial
import subprocess
import time

ser = serial.Serial('/dev/modem0', 460800, timeout=2)

cmd = 'AT+COPS=0\r\n'
ser.write(cmd)
ser.sendBreak()

s = []
time_now = time.time()
while(time.time()-time_now)<=40:
    newdata = ser.read()
    if newdata is not None or newdata!="":
            global s
            s.append(newdata)
ser.close
print "".join(s)

subprocess.Popen(["wvdial"])

相关内容