ttyACM send unwanted at commands on connection how to stop this ?

tty - Under Ubuntu 16/18, ttyACM sends unwanted AT commands on connection how to stop this ?

I have some external hardware running embedded Linux (a relatively old version of the kernel), loosely based off the old DaVinci DA850 development board.

It communicates with the host PC over a USB port using a gadget serial connection. On the external hardware, this is called ttyGS0, as usual.

On the PC side, the Windows gadget serial drivers work perfectly. This was also tested on Ubuntu 14, and again it ran perfectly. Significantly, Ubuntu 14 identified the port as ttyGS0 as well. We have recently retested on Ubuntu 16 and Ubuntu 18, and found that this does not work. These have the new USB system which now identifies the port as ttyACM0 instead.

Checking why this does not work, messages are received by the external hardware correctly, but the PC-side application is not receiving replies from read(). I am using the standard pattern of read() and select() to read with a timeout, as usual. Also perhaps significantly, on first connection the port always sends "AT" three times.

solution 方案

This suggest to me that the new ttyACM flavor of gadget serial is trying to do a Hayes-style handshake, and hence is failing to get further because the external hardware is expecting this to simply work like a dumb RS-232 port. Following a tip from @JdeBP, I have run systemctl status ModemManager.service and I see

Jun 02 21:10:58 XUbuntu-18 ModemManager[402]: <warn>  Couldn't create modem for device '/sys/devices/pci0000:00/0000:00:0b.0/usb1/1-1': Failed to find primary AT port
Jun 02 21:52:36 XUbuntu-18 ModemManager[402]: <info>  [device /sys/devices/pci0000:00/0000:00:0b.0/usb1/1-1] creating modem with plugin 'Generic' and '1' ports
Jun 02 21:52:36 XUbuntu-18 ModemManager[402]: <warn>  Could not grab port (tty/ttyACM0): 'Cannot add port 'tty/ttyACM0', unhandled serial type'
Jun 02 21:52:36 XUbuntu-18 ModemManager[402]: <warn>  Couldn't create modem for device '/sys/devices/pci0000:00/0000:00:0b.0/usb1/1-1': Failed to find primary AT port
Jun 02 22:36:50 XUbuntu-18 ModemManager[402]: <info>  [device /sys/devices/pci0000:00/0000:00:0b.0/usb1/1-1] creating modem with plugin 'Generic' and '1' ports
Jun 02 22:36:50 XUbuntu-18 ModemManager[402]: <warn>  Could not grab port (tty/ttyACM0): 'Cannot add port 'tty/ttyACM0', unhandled serial type'
Jun 02 22:36:50 XUbuntu-18 ModemManager[402]: <warn>  Couldn't create modem for device '/sys/devices/pci0000:00/0000:00:0b.0/usb1/1-1': Failed to find primary AT port
Jun 02 22:41:38 XUbuntu-18 ModemManager[402]: <info>  [device /sys/devices/pci0000:00/0000:00:0b.0/usb1/1-1] creating modem with plugin 'Generic' and '1' ports
Jun 02 22:41:38 XUbuntu-18 ModemManager[402]: <warn>  Could not grab port (tty/ttyACM0): 'Cannot add port 'tty/ttyACM0', unhandled serial type'
Jun 02 22:41:38 XUbuntu-18 ModemManager[402]: <warn>  Couldn't create modem for device '/sys/devices/pci0000:00/0000:00:0b.0/usb1/1-1': Failed to find primary AT port

This seems to tie in with the three AT messages I am seeing on the other end.

Running mmcli --list-modems though, it says No modems were found.

Has anyone seen anything like this before, when they moved from ttyGS gadget serial to the newer ttyACM style? I have googled this, read all the docs on ACM and gadget serial, and checked for anything about AT commands with ACM serial connections, but I can't find anything which seems to answer this.

I have also tried checking the termios settings (which have not changed from the original version which worked) but nothing seems out of the ordinary.

Looks like ModemManager is making some attempts to probe that port, which might be the source of the ATs. Those might then confuse the device at the other end.

You might need to set up an udev rule to tell ModemManager to keep its hands off that device. For example, you might put this into /etc/udev/rules.d/01-disable-mm-ttyACM.rules:

KERNEL=="ttyACM*", ENV{ID_MM_DEVICE_IGNORE}="1"

To make the new rule take effect, you might need to run sudo udevadm control --reload-rules. Then disconnect & reconnect the device, and see if ModemManager will now ignore the device.

后话

@JdeBP On laptops with built-in 3G/4G mobile data connectivity, ModemManager is quite useful since there is a mess of various protocols for communicating with those modems: traditional AT commands, vendor-specific protocols like Sierra's QMI, new standards like MBIM...(sigh). Unfortunately, while it aims to make the "common case" easier, it requires people doing different things with serial-port-like devices to take extra steps. 

https://unix.stackexchange.com/questions/590509/under-ubuntu-16-18-ttyacm-sends-unwanted-at-commands-on-connection-how-to-sto

猜你喜欢

转载自blog.csdn.net/gezi322/article/details/107377405