Issues sending serial command via Powershell (Syntax??)

Posted on 2011-10-22
Last Modified: 2012-05-12

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:
$port= new-Object System.IO.Ports.SerialPort COM10,9600,None,8,one
$port.WriteLine("~0000 1")

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

$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 ??

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

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

thanks everyone
Question by:WalkerYYJ
    LVL 67

    Accepted Solution

    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 The tilde ~ doesn't have any special meaning to PS, so that cannot be the issue.

    Author Closing Comment

    Awesome, thanks buddy, ill give it a shot!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
    Set OWA language and time zone in Exchange for individuals, all users or per database.
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
    The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now