I'm trying to create a powershell script that sends a string from 1 COM port to another one. The string should show up in a teraterm screen of the receiving port. But the I can't get it to work, although it should be straight forward. The teraterm screen is just blank.
Setup:
I have 2 usb serial adapter (COM3, COM4), both connected with a physical serial cable.
The powershell code:
[System.IO.Ports.SerialPort]::getportnames()
#prints COM1 COM3 COM4
$STX = [char] 2
$ETX = [char] 3
$port= new-Object System.IO.Ports.SerialPort COM4,9600,None,8,one
$port.open()
$port.Write("Hello world\r\n")
$port.close()
$port.open()
$port.Write("Hello world\n")
$port.close()
$port.open()
$port.Write("Hello world\r")
$port.close()
$port.open()
$port.WriteLine("Hello world")
$port.close()
$port.open()
$port.WriteLine($STX+"Hello world"+$ETX)
$port.close()
read-host
Anything I missed or any pointers?
Extra info:
Also tried sending strings with CMD and C#
We were able to send a string from an old handheld device (so cable is fine)
$Port.Open();$Port.ReadExisting();$Port.Close()
to see if you are able to read from the port? With it being a USB adapter PowerShell may not be seeing it like you would expect, so you may be sending data into nothing. - TheMadTechnician"Hello world\r\n"
... do you get a different response if you try"Hello world`r`n"
. Backtick is the PowerShell escape character. - MattIO.Ports.SerialPort
as being largely unreliable. sparxeng.com/blog/software/…. Still reading but it talks about using the WinAPI instead. Have you tried to read and send bytes instead? - Matt