Connecting To COM Serial Port via PowerShell

I often mess around with shell scripts. Originally, I used Linux for that – that is until I discovered the Windows 7 equivalent “PowerShell”. Now, I wanted to send some commands to a COM Serial port to my programmable Omnima LCD display.

Connecting to COM PORT

Tip: Connecting to a COM port can be very useful. For example if you want to automate sending a SMS from your mobilephone from your own computer. The possibilities are endless.

1. Step Open up Powershell

2. Step Let’s find out what COM ports are in use. Enter [System.IO.Ports.SerialPort]::getportnames()

3. Step You need to know the baud rate to talk to your device. Look it up in your manual. I want to talk to a programmable LCD that supports baud rate 115200. The other settings should also be adjusted accordingly.

Enter: $port= new-Object System.IO.Ports.SerialPort COM7,115200,None,8,one

4. StepYou can now open the COM connection and start writing commands. Start with a simple “hello world”

$port.Write("Hello World")

5. Step Now enter the commands that you want to send to your COM device. I am also still new to using the PowerShell (Linux is a bit easier to handle) so try to do more research on sending commands. You might have to use the CR and LF sequences to send the commands. This is often send automatically with Linux tools like screen stty.

Here I am now using some codes of the Omnima API that can draw a rectangle on a screen. This will only work with some Omnima devices, so unless you are planning to buy one from, you need to read your manual for the commands that you want to send to your device – whatever you’re up to!

$port.Write("#@BkColor 255 0 0 0`r")
$port.Write("#@Rect MW 100 100 100 100 `r")

Will keep you posted on this and will let you know how to create a functional uptime script for your website.

Published: Friday, August 12th, 2011 Last Modified: August 22, 2011

Related Posts

Rate This Article
5 of 5 0 (100%) 1 vote