Communicating with GSM modems using PySerial in python -


i have dwm-156 gsm modem. below can see list of devices added computer after plugging gsm modem usb port:

enter image description here note every time connect modem computer, use different com port numbers.

now want send @ commands modem using python or other language. want answer/make call from/to dial phone , record raw data transfers during communication. after doing search found this question in so. 1 of answerers suggested 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 9 , 10 , 12. these 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: not open port 'com13': windowserror(2, 'the system cannot find file specified.') >>> #for port = 12 >>>  

my questions:

  1. while don't receive response?
  2. why in third program throw could not open port 'com13' while trying connect com12?
  3. is there more efficient , better way use gsm modem sniff call? (i want call sim card inserted in gsm modem using dial phone set , log raw data transfers during communication.)

  1. while don't receive response?

you never call serialport.read() read response.

  1. why in third program throw not open port 'com13' while trying connect com12?

the serial class comes lib\site-packages\serial\serialwin32.py, , wrapper around win32serial class.

win32serial inherits serialbase in lib\site-packages\serial\serialutil.py, , initialises call serialbase initialiser.

serialbase sets port value assigning port value gave port property, calls serialbase.setport(port).

setport(port) checks whether value passed in string or number. it's number, calls makedevicename(port) in win32serial class.

makedevicename(port) calls device(port).

device(port) function adds 1 number , puts com in front of it:

def device(portnum):     """turn port number device name"""     return 'com%d' % (portnum+1) # numbers transformed string 

why? don't know. if pass string instead, won't change it. try giving string instead: serial.serial(port="com12"... instead of serial.serial(port=12 - suspect background distraction, , it's related being described in device manager screenshot 'debug' port , maybe can't opened normally.

  1. is there more efficient , better way use gsm modem sniff call? (i want call sim card inserted in gsm modem using dial phone set , log raw data transfers during communication.)

i don't understand this. mean "call sim card"? raw data? aren't going able record phonecall audio data using serial link... , aren't going able record modem data sent else because python have serial port open , other program won't able open it.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -