我只是坐在 windows cmd shell 前面,通过 powershell 打开一个 COM 端口,将一些信息发送到外部设备。如果我在 shell 中输入以下代码,一切正常:
powershell
$port=new-Object System.IO.Ports.SerialPort COM3,9600,None,8,one
$port.open(
$port.WriteLine("Hello world")
$port.Close()
但现在我想将日期和时间发送到端口,所以我想我只需要更改第 5 行:
$port.WriteLine(Get-Date)
或者
$port.WriteLine($Get-Date)
但这不起作用(外壳用红色字母告诉我一些奇怪的东西),到目前为止我不知道如何做到这一点......有人可以帮助我吗?