1

I'm testing some satellital modem with a USB-to-serial (RS232) converter. I have already tested the "connection", and it works. I'm using minicom and am able to capture data sent from one terminal (running one bash script that echoes random numbers) to another.

To make this modem send things, I must send it AT commands to it. What is the best way to do it? Should I just echo the AT command from my bash script? Or is there any better way?

#!/bin/bash
while true;
  do 
    number=$RANDOM
    echo $number >/dev/ttyUSB0
    sleep 4     
  done

Thank you for your time!

2 Answers 2

4

I got a working answer from for this from here:

https://unix.stackexchange.com/questions/97242/how-to-send-at-commands-to-a-modem-in-linux

First using socat.

echo "AT" | socat - /dev/ttyUSB2,crnl

worked great.

Then I used atinout

echo AT | atinout - /dev/ttyACM0 -

Ultimately I chose socat, because atinout isn't in any repository.

Sign up to request clarification or add additional context in comments.

1 Comment

Another way is this: /bin/echo -n -e "AT\r\n" > /dev/ttyUSB2 && cat /dev/ttyUSB2
2

Since you're talking with a modem, the general way to talk with the modem is to use ModemManager, an application that handles the communication with the modem for you.

If you are unable to use ModemManager or you must use bash for some reason, note that commands must end with a \r\n to be used by the modem. The best way that I have found to do that is to use /bin/echo as follows:

/bin/echo -n -e "AT\r\n" > /dev/ttyUSB0

This ensures that echo will convert the escape characters to the carriage return and newline appropriately.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.