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. Open up Powershell

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

3. 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. You can now open the COM connection and start writing commands. Start with a simple “hello world”

$port.open()
$port.Write("Hello World")

5. 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 omnima.co.uk, 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")
$port.Write("#@Reboot`r")

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


Or you might like these sexy wallpaper, tweaks and themes:

Written by oliversk Friday, August 12th, 2011

Was it helpful? Please bookmark it and spread the word

delicious   facebook   google   twitter  

You love Windows, Gaming and everything digital? Great, we too! We have thousands of great Windows 7 themes, registry tweaks, tutorials, so please use our search box if you look for anything specific. If you have some awesome desktop themes, tips or want to write for us, then drop us a mail: win7themes at googlemail.com

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>