minicom is openning port but pyserial is saying 'Device or resource busy''

158 Views Asked by At

I want to send a sms message via Quectel EG25-G, I've already connected to LTE with ModemManager I've managed to connect to the device via minicom and I can send AT commands I wanted to use PySerial to send the message, so I created a basic script which could send AT commands

from serial import Serial

port = Serial("/dev/ttyUSB2", baudrate=115200)

port.write(b'AT\r')
print(port.readline())
print(port.readline())
port.close()

I've been able to run the following script after allowing for read and write of port with command sudo chmod a+rw /dev/ttyUSB2 but after rebooting and running the command again, the script showed

could not open port /dev/ttyUSB2: [Errno 16] Device or resource busy: '/dev/ttyUSB2'

I know that ModemManager uses the device and it used it before too because I connect to the device through OpenVPN through LTE

Even though the script shows that the device or resource is busy, I am able to send the AT commands via minicom and I could run the code once before rebooting.

At this point I think I've searched through everything so it's probably a simple mistake on my part but I cannot for the life of me figure it out...

I've tried killing the ModemManager process on that specific port but it came back up and didn't allow the script to run

1

There are 1 best solutions below

0
On

For anyone looking for an answer I did

sudo chown [username] /dev/ttyUSB2

and it seemed to work. The reason behind minicom working was because it was executed with sudo privileges and therefore could access the port.