Issues sending serial command via Powershell (Syntax??)


So I am trying to have a serial command sent whenever a machine is booted. I figured powershell would be a good way to do this (which it may or may not be.)
The device I am sending the command to needs to receive "~0000 1" followed by a line break.

this is what I have so far:
[System.IO.Ports.SerialPort]::getportnames()
$port= new-Object System.IO.Ports.SerialPort COM10,9600,None,8,one
$port.open()
$port.WriteLine("~0000 1")
$port.Close()
 

Open in new window


However the message isn't making it accros.
I have treid changing things to:
$port.WriteLine("~0000 1 'r")

Open in new window

and
$port.WriteLine("~0000 1 'n")

Open in new window


incase the issue was the CR/LN not being sent at the end of the line, but none are working. so first question:
Do I have the right usage for the <CR> command?

Second question:
Could the problem be the "~" should this be sent using some funny command like [char]126 ??

Third:
Is there anything else obvious going on here that I am getting wrong?

Last:
Is there a better way to do this, (batch file maybe?)


thanks everyone
WalkerYYJAsked:
Who is Participating?
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
The batch file:
@echo off
mode com10 baud=9600 parity=none data=8 stop=1
echo ~0000 1> com10

Open in new window

You should be fine with your initial PS script, as I cannot see anything wrong there.
However, if you have to send a CR or LF, you need to use the backtick (grace accent) `, not the common tick ', so it is `r or `n (see also http://ss64.com/ps/syntax-esc.html). The tilde ~ doesn't have any special meaning to PS, so that cannot be the issue.
0
 
WalkerYYJAuthor Commented:
Awesome, thanks buddy, ill give it a shot!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.