I have a DWM-156 GSM modem. Below you can see the list of devices that added to my computer after plugging this GSM modem to the USB port:
Note that the every time that I connect the modem to my computer, it use different COM port numbers.
Now I want to send some AT commands to this modem using Python or any other language. Actually I want to answer/make a call from/to a dial up phone and record the raw data that transfers during that communication. After doing a search I found this question in SO. One of the answerers was suggested the below code:
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')
I replace PORT_NUMBER with 9 , 10 and 12. These are results:
>>> ================================ 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
>>>
My questions:
- While I don't receive any response?
- Why in the third program it throw could not open port 'COM13' while I am trying to connect to COM12?
- Is there any more efficient and better way to use GSM modem to sniff a call? (I want to call to the SIM card that I inserted in my GSM modem using a dial up phone set and log the raw data that transfers during this communication.)