comgt 是一个 GPRS 模块配置工具。它更像是一个脚本语言解释器,通过调用内建、或者外部脚本与 GPRS 和 3G 模块通,解决了在脚本中使用microcom命令需要交互输入AT指令的问题。
编译
下载comgt.0.32.rar并解压,进入comgt目录,编译命令:make VERBOSE=1,交叉编译需要给CC赋值;安装命令:make DESTDIR=./usr install,安装在./usr/sbin目录下。
使用
root@genvict_imx8qxp:~# ./comgt help
comgt Usage: comgt [options] [built in script]'|[external script]
Built in scripts -
comgt [default] Checks SIM status (requests PIN if required),
registration and signal strength reported by
datacard.
comgt info Display configuration of datacard.
comgt sig Report Signal strength.
comgt reg Report Registration status.
comgt PIN Set PIN using COMGTPIN env variable.
comgt APN Set APN using COMGTAPN env variable.
Valid for GlobeTrotter GPRS only:
comgt USA Switch to 900/1900 MHz band for USA operation.
comgt Europe Switch to 900/1800 MHz band for Europen operation.
Valid for GlobeTrotter EDGE and Combo EDGE only:
comgt GTEDGE Switch on radio interface.
Valid for Vodafone 3G, GlobeTrotter Fusion, GT Max :
comgt 2G 2G networks only.
comgt 3G 3G networks only
comgt 3G2G 3G network preferred
Command line options (must be before script name) -
-d device Use alternative device. e.g -d /dev/ttyUSB0
-e Turn on communication echo.
-h Help.
-V Version.
-s Don't run internal 'default' script before running
external script.
-t=\n Set alternative line terminator (default=\n).
-v Verbose mode. Print lots of trace info.
-x Speed exchange. 115200 replaced by 57600.
***used for GlobeTrotter EDGE and Combo EDGE***
NOTES:
comgt assumes that the GlobeTrotter device is /dev/modem (create a logical link
to actual device or use -d switch). Unless you use the '-s' switch comgt will
run the internal 'default' script first before running an external script file.
外部脚本g.gcom
opengt
set com 115200n81
set comecho off
set senddelay 0.02
waitquiet 0.2 0.2
flash 0.1
:start
send "AT^m"
get 1 "" $s
print $s
:continue
exit 0
调试使用
root@genvict_imx8qxp:~# ./comgt -d /dev/ttyUSB5 -se g.gcom
AT
OK
microcom单命令查询
使用管道作为microcom的AT指令输入,设置microcom超时退出时间,单位ms:
echo -ne "AT\r\n" | microcom -t 100 -s 115200 /dev/ttyUSB2,有时候第一次不能成功,需要多试几次直到成功。
BusyBox v1.29.3 (2023-03-16 16:29:22 CST) multi-call binary.
Usage: microcom [-d DELAY] [-t TIMEOUT] [-s SPEED] [-X] TTY
Copy bytes for stdin to TTY and from TTY to stdout
-d Wait up to DELAY ms for TTY output before sending every
next byte to it
-t Exit if both stdin and TTY are silent for TIMEOUT ms
-s Set serial line to SPEED
-X Disable special meaning of NUL and Ctrl-X from stdin
例子查询EC20 4G模块的状态脚本:
#4g
ret=$(echo -ne "AT\r\n" | microcom -t 100 -s 115200 /dev/ttyUSB2 | grep OK)
while true
do
if [ -n "$ret" ];then
ret=$(echo -ne "AT+CPIN?\r\n" | microcom -t 100 -s 115200 /dev/ttyUSB2 | grep READY)
if [ -n "$ret" ];then
echo "CPIN=READY" >> /tmp/sysinfo.txt
else
echo "CPIN=NOT READY" >> /tmp/sysinfo.txt
fi
ret=$(echo -ne "AT+CSQ\r\n" | microcom -t 100 -s 115200 /dev/ttyUSB2 | grep CSQ | awk '{print $2}')
if [ -n "$ret" ];then
echo "CSQ=$ret" >> /tmp/sysinfo.txt
else
echo "CSQ=NULL" >> /tmp/sysinfo.txt
fi
ret=$(echo -ne "AT+CGREG?\r\n" | microcom -t 100 -s 115200 /dev/ttyUSB2 | grep CGREG | awk '{print $2}' | awk -F, '{print $2}')
if [ -n "$ret" ];then
if [ "$ret" = "1" ];then
echo "CGREG=REG" >> /tmp/sysinfo.txt
else
echo "CGREG=NOT REG" >> /tmp/sysinfo.txt
fi
else
echo "CGREG=NULL" >> /tmp/sysinfo.txt
fi
ret=$(echo -ne "AT+CGSN\r\n" | microcom -t 100 -s 115200 /dev/ttyUSB2 | awk 'NR==2{print $1}')
if [ -n "$ret" ];then
echo "IMEI=$ret" >> /tmp/sysinfo.txt
else
echo "IMEI=NULL" >> /tmp/sysinfo.txt
fi
break
fi
sleep 1
done
CPIN=READY
CSQ=31,99
CGREG=REG
IMEI=868274063166963