[英]Capturing the output from COM port using PowerShell on Windows 7
I want to send Sierra AT commands to a COM port and capture the output and store it in a variable using PowerShell. 我想将Sierra AT命令发送到COM端口并捕获输出并将其存储在使用PowerShell的变量中。
PowerShell version: PowerShell版本:
Name : ConsoleHost
Version : 2.0
InstanceId : eb5987f0-9961-4842-b349-ba215d86fdfa
UI : System.Management.Automation.Internal.Host.InternalHostUserI
nterface
CurrentCulture : en-IN
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
For example: at!gstatus?
例如: at!gstatus?
I tried this, but it's not working for me. 我试过了,但是对我不起作用。
PS> [System.IO.Ports.SerialPort]::getportnames()
COM16
PS> $port= new-Object System.IO.Ports.SerialPort COM16,115200,None,8,one
PS> $port.open()
PS> $port.WriteLine("at!gstatus?")
PS> $port.WriteLine("`r")
PS> $port.ReadExisting() //getting null output
PS> $port.close()
How can this be done? 如何才能做到这一点?
Modem ? 调制解调器? COM port ? COM端口? AT commands ? AT指令? Is it 2015 or 1995 ? 是2015年还是1995年? ^_^ ^ _ ^
Try with a pause before reading the data: 在读取数据之前先暂停一下:
$port = New-Object System.IO.Ports.SerialPort COM16,115200,None,8,one
$port.Open()
$port.WriteLine( "at!gstatus?" + "`r" )
Start-Sleep -m 50
$port.ReadExisting()
$port.Close()
Source : https://social.technet.microsoft.com/Forums/en-US/2980f24e-56d1-431f-aedc-811c087b5184/powershell-serial-com-port?forum=ITCG 来源: https : //social.technet.microsoft.com/Forums/zh-CN/2980f24e-56d1-431f-aedc-811c087b5184/powershell-serial-com-port?forum=ITCG
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.