Python Forum
Execute "AT" command in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Execute "AT" command in Python
#1
Hello,
To check ICCID value of a modem 4G, I execute AT command in a terminal (e.g. picocom): AT+QCCID.
Is it possible to do the same in Python ?
Thanks.
Reply
#2
I can't give you a complete answer as my needs are few, and I usually do any 'AT' commands directly using Putty.

I will instead direct you to paramiko (which is an implementation of the SSHv2 protocol) URL's:
pipy: https://pypi.org/project/paramiko/
main site: https://www.paramiko.org/
GitHub: https://github.com/paramiko/paramiko

Check the 'demos' https://github.com/paramiko/paramiko/tree/main/demos
to see if you can find an example of what you're looking for.

There may be better options.
Reply
#3
Here is a solution:

import serial
import io
import time
import os

signal = serial.Serial(
    port='/dev/ttyUSB2',
    baudrate=115200,
    bytesize=8,
    parity='N',
    timeout=1,
    stopbits=1,
    rtscts=False,
    dsrdtr=False
)

signal_text = io.TextIOWrapper(signal, newline='\r\n')

signal.write("at+qccid\r\n".encode())

aaa = "a"      
while not aaa[0]=='+':
    aaa = signal_text.readline().rstrip()
print("ICCID: ", aaa[8:])
Reply
#4
Thanks for sharing!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020