简体   繁体   English

通过adb从Powershell脚本向Android手机发送AT命令

[英]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. 我有一个小脚本,我在Android手机(/ system / etc目录)的adb shell中运行,它可以通过发送/接收单个AT命令与调制解调器通信。 The script itself, if run in adb shell, works OK. 如果脚本本身在adb shell中运行,则可以正常工作。 That's what it looks like: 这就是它的样子:

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

Here's the output in adb shell: 这是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. 现在我想从我的PC上运行的PowerShell脚本调用这个脚本,最终通过AT命令控制调制解调器,但没有任何反应。 For example, the below powershell script will send the command at+cops? 例如,下面的powershell脚本将在+ 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. 输出有时可能看起来像+ ATCMD(启动后位于设备缓冲区中的任何剩余[专有] AT命令),或+ cops?(echo),或者什么都没有,但从不+ COPS:0,0,“AT&T” ,6我期待。 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. 理想情况下,我希望能够执行命令,将控制权返回给powershell,并使输出可用于进一步处理。 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. 不确定回答你的问题,我的手机不是Android,但当我通过蓝牙或USB连接到我的电脑时,会创建一个COM端口。 So I build an assembly tool on the top of .NET SerialPort class that allow, for example, to send SMS using the phone Modem. 因此,我在.NET SerialPort类的顶部构建了一个组装工具,例如,允许使用手机调制解调器发送短信。

I think it's usable in your case. 我认为它适用于您的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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