【发布时间】:2015-06-20 14:30:01
【问题描述】:
我有一个DWM-156 GSM modem。您可以在下面看到将此 GSM 调制解调器插入 USB 端口后添加到我的计算机的设备列表:
请注意,每次我将调制解调器连接到我的计算机时,它都使用不同的 COM 端口号。
现在我想使用 Python 或任何其他语言向这个调制解调器发送一些 AT 命令。实际上,我想从拨号电话接听/拨打电话并记录在该通信期间传输的原始数据。进行搜索后,我在 SO 中找到了this 问题。其中一位回答者被建议使用以下代码:
import serial
serialPort = serial.Serial(port=PORT_NUMBER,baudrate=115200,timeout=0,rtscts=0,xonxoff=0)
def sendatcmd(cmd):
serialPort.write('at'+cmd+'\r')
print 'Loading profile...',
sendatcmd('+npsda=0,2')
我将 PORT_NUMBER 替换为 9 、 10 和 12。这些是结果:
>>> ================================ RESTART ================================
>>>
Loading profile...
>>> #for port = 9
>>> ================================ RESTART ================================
>>>
Loading profile...
>>> #for port = 10
>>> ================================ RESTART ================================
>>>
Traceback (most recent call last):
File "C:\Users\ghasemi.IT\Desktop\testGSMModem.py", line 3, in <module>
serialPort = serial.Serial(port=12,baudrate=115200,timeout=0,rtscts=0,xonxoff=0)
File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 38, in __init__
SerialBase.__init__(self, *args, **kwargs)
File "C:\Python27\lib\site-packages\serial\serialutil.py", line 282, in __init__
self.open()
File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 66, in open
raise SerialException("could not open port %r: %r" % (self.portstr, ctypes.WinError()))
SerialException: could not open port 'COM13': WindowsError(2, 'The system cannot find the file specified.')
>>> #for port = 12
>>>
我的问题:
- 虽然我没有收到任何回复?
- 为什么在我尝试连接到 COM12 时,在第三个程序中抛出 could not open port 'COM13'?
- 有没有更有效和更好的方法来使用GSM调制解调器来嗅探电话? (我想使用拨号电话呼叫我插入 GSM 调制解调器的 SIM 卡,并记录在此通信期间传输的原始数据。)
【问题讨论】:
标签: python python-2.7 gsm pyserial modem