![]() |
Execute "AT" command in Python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Networking (https://python-forum.io/forum-12.html) +--- Thread: Execute "AT" command in Python (/thread-35651.html) |
Execute "AT" command in Python - Pavel_47 - Nov-26-2021 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. RE: Execute "AT" command in Python - Larz60+ - Nov-26-2021 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. RE: Execute "AT" command in Python - Pavel_47 - Dec-06-2021 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:]) RE: Execute "AT" command in Python - Larz60+ - Dec-06-2021 Thanks for sharing! |