Page 1 of 1

Port "busy" when trying to send AT commands to modem

Posted: Tue Dec 18, 2018 6:04 pm
by scottk
Hi,
I'm using a Telit USB modem. When I plug it into the latest Stretch image, I see it enumerate as several USB ports.

Image

I want to send AT commands to it. But when I try, I get a port busy (I think). I've tried using both Screen and Python script to send AT commands. The python script returns an error that the port is busy. Screen just terminates without giving a reason.

I've included what my inputs and outputs are below. I do have modem and network manager installed, but it's not set to autoconnect.

Here's the output from Screen (I think ACM3 should be the correct port, but I tried both).
[email protected]:~/modem $ screen /dev/ttyACM3 9600
[screen is terminating]
[email protected]:~/modem $ screen /dev/ttyACM0 9600
[screen is terminating]
[email protected]:~/modem $
My python script using the serial library returns a port busy error:

Code: Select all

import serial
import time

phone = serial.Serial("/dev/ttyACM3", baudrate=9600, timeout=2.0)

phone.write('AT+CCLK?\r')
result=phone.read(500)
print (result)
Traceback (most recent call last):
File "read_serial.py", line 4, in <module>
phone = serial.Serial("/dev/ttyACM3", baudrate=9600, timeout=2.0)
File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 236, in __ini t__
self.open()
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 268, in open
raise SerialException(msg.errno, "could not open port {}: {}".format(self._p ort, msg))
serial.serialutil.SerialException: [Errno 16] could not open port /dev/ttyACM3: [Errno 16] Device or resource busy: '/dev/ttyACM3'

Here's the mmcli output. It seems to indicate that ttyACM3 is for AT commands.

Image

Re: Port "busy" when trying to send AT commands to modem

Posted: Wed Dec 19, 2018 6:58 pm
by topguy
There is a commandline tool called "lsof" which lists all open files and which programs that uses them. It might point you in the direction of the culprit.

Re: Port "busy" when trying to send AT commands to modem

Posted: Wed Dec 19, 2018 7:22 pm
by rhubarbdog
You have to terminate screen correctly. Ctrl+A \ then answer yes to the question.
All other methods back to a command prompt leave a lock on /dev/ttyACMx
Using lsof which you will have to install will help.

Code: Select all

sudo apt-get install lsof
Then kill the processes which have the file in question open.

Code: Select all

kill -term <pid>

Re: Port "busy" when trying to send AT commands to modem

Posted: Thu Dec 20, 2018 2:25 pm
by Aydan
@scottk
if you are running Stretch with Desktop, it could be that ModemManager has grabbed the ports.
try

Code: Select all

sudo systemctl stop ModemManager
and see if the ports are then acessible.

Regards
Aydan