linux - Send/Receive AT commands to GSM modem in python -


i want write simple code in python send ussd codes gsm modem (d-link dwm-157) , receive results , store them in variables. can connect modem minicom , miniterm.py. problem need terminal send/receive @ commands modem. don't want terminal. use following code send simple @ command when run code nothing happens:

import serial, time  def serial_def():     ser = serial.serial()     ser.port = "/dev/ttyusb2"     ser.baudrate = 115200     ser.bytesize = serial.eightbits #number of bits per bytes     ser.parity = serial.parity_none #set parity check: no parity     ser.stopbits = serial.stopbits_one #number of stop bits     ser.timeout = 2              #timeout block read     ser.xonxoff = false     #disable software flow control     ser.rtscts = false     #disable hardware (rts/cts) flow control     ser.dsrdtr = false       #disable hardware (dsr/dtr) flow control     ser.writetimeout = 2     ser.open()      if ser.isopen():          print(ser.name + ' open...')      ser.write("at"+"\r\n")     time.sleep(1)     out=''     while true:         out += ser.read(1)         print (out)              ser.close()  if __name__ == '__main__':     serial_def() 

when run code see following:

/dev/ttyusb2 open... 

any appreciated.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -