Is there a way to get the device name connected to the serial port?
This code gives me just the name of the serial port. But I need the device name connected to it i.e. Nokia Phone
ser = serial.Serial('/dev/ttyACM0',
xonxoff = False,
rtscts = False,
bytesize = serial.EIGHTBITS,
parity = serial.PARITY_NONE,
stopbits = serial.STOPBITS_ONE)
sere = ser.name
print (ser, sere)
I've been checking other possibilities like
gammu-detect but I would like to have a self standing python script that does this operation. Is there a way to get it done with pyserial?
Yes, of course.
But this is not strictly linked to serial port itself. It depends on the protocol the device is using.
In essential, you send some preset initial data to the device and it responds with manufacturer, name, model and version or some combination of these.
I am not sure whether this is standardized or not, you will have to search for it.
If it is standardized, it is most probably something like:
1. Open the port with 9600 baud rate 2. Send the request for info 3. Use info to reset the port etc.
I know that some programs do this. You can even hear old 56K modems reacting to the query when detection algorithm asks them who they are.
Now, you have to search whether this is a standard procedure or each device has its own.
If you are searching for phones, then very probably there is one for phone versions, perhaps each per OS like iOS, Symbian, Android, Windows *, ...
If you cannot find the protocol on the internet, then install virtual card for serial ports, perform man in the middle on looped ports to see what data is sent at initial communication with the phone application.
Note: Don't watch for data when connecting to the internet i.e. using the phone as a modem. You will see only AT&T protocol, which wouldn't help you much.
If you want to see how it works universally, use same technique with virtual serial card but when new device wizard detects for new hardware.
P.S. I found something!
You should get back some data containing numeric identifier of a device. Like serial number.
Now things work well! I had to type the .read command. Here the solution:
import serial import time ser = serial.Serial('/dev/ttyACM0', 460800, timeout=5, xonxoff = False, rtscts = False, bytesize = serial.EIGHTBITS, parity = serial.PARITY_NONE, stopbits = serial.STOPBITS_ONE) #s = input('Enter AT command --> ') #print ('AT command = ' + s) ser.write(bytes('AT+CGMI' + '\r\n')) ser.timeout = 1 response = ser.read(999) print(response) ser.close()