Reputation: 172
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!
Upvotes: 1
Views: 6866
Reputation: 368
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.
Upvotes: 4
Reputation: 2645
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.
Upvotes: 2