Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Issues sending serial command via Powershell (Syntax??)

Posted on 2011-10-22
2
Medium Priority
?
861 Views
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:
[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
0
Comment
Question by:WalkerYYJ
2 Comments
 
LVL 72

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 37011052
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
 

Author Closing Comment

by:WalkerYYJ
ID: 37011406
Awesome, thanks buddy, ill give it a shot!
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

580 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