简体   繁体   中英

Sending AT commands from Powershell script to Android phone via adb

I have a little script that I run in adb shell of Android phone (/system/etc directory), which enables to communicate with the modem by sending/receiving a single AT command. The script itself, if run in adb shell, works OK. That's what it looks like:

cat /dev/pts/7 &  
echo -e $1\\r > /dev/pts/7 

Here's the output in adb shell:

# ./sendATCommand "at+cops?"
./sendATCommand "at+cops?"
#
+COPS: 0,0,"AT&T",6

OK
/dev/pts/7: invalid length
(need to press ENTER to return control to adb shell)

#

Now I want to invoke this script from a powershell script running on my PC, thus eventually controlling modem via AT commands, but nothing happens. For example, the below powershell script will send the command at+cops? to check the operator to which mobile is registered to:

$adb = [IO.Path]::Combine([IO.Path]::Combine($Env:ANDROID, "platform-tools"), "adb.exe")  
& $adb remount  

$atCommand = "at+cops?"  
& $adb shell /system/etc/sendATCommand $atCommand  

The output may looks sometimes like +ATCMD (any residual [proprietary]AT command sitting in device buffer after bootup), or at+cops?(echo), or nothing at all, but never +COPS: 0,0,"AT&T",6 which I expect. Could you help me figure out what's going on and how to possibly fix it? Ideally I want to be able to execute at command, return control to powershell, and have output available for further processing. I am also open to other solutions to implement same thing. Would greatly appreciate your help. Thanks!

Not sure to answer your question, my phone is not an Android, but when I connect it via buetooth or USB to my computer a COM port is created. So I build an assembly tool on the top of .NET SerialPort class that allow, for example, to send SMS using the phone Modem.

I think it's usable in your case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM