RS232 (Serial) Control of LG LCD TV via MythTV

I got sick of having a remote control for everything, so I have started down the path of using RS232 (Serial) control where I can. Currently that is only my TV, but when the Decoder and DVD player get replaced I will be looking for models with remote control capability (I know I could use an IR blaster, but that can impede using the real remote and looks kind of ugly).

So I started by deciding the basic features I used on my TV all the time and how to remap them to the remote control I use for MythTV (I haven’t done every button, I figured if I need to use the remote once a month then so be it). The features required for me were:

  • On/Off
  • Aspect Ratio
  • Input (DTV, Comp, RCA, VGA)

I found the codes required to send to the TV on the LG website somewhere. If your TV supports RS232 there should be a document somewhere that describes the protocol used you will just need to find it.

I found the following code somewhere, it was originally used just to send and receive data via a serial port so I have modified it to send what I need to the TV and removed everything else.

Just drop the following in a file called tvcontrol in /usr/local/bin


#allows you to capture the command switches
import sys

#get serial features for python
import serial

#this next line sets up the serial port to allow for communication
#and opens the serial port you may need to change
#ttyS0 to S1, S2, ect. The rest shouldn't need to change.
ser = serial.Serial('/dev/ttyS0', 9600, 8, serial.PARITY_NONE,
         serial.STOPBITS_ONE, xonxoff=0, rtscts=0, timeout=1)

#default COMMAND is bogus
COMMAND = "nope"
aspect169 = "kc 00 02n"
aspect43 = "kc 00 01n"
poweron = "ka 00 01n"
poweroff = "ka 00 00n"
inputdtv = "kb 00 00n"
inputav1 = "kb 00 02n"
inputcomp1 = "kb 00 04n"
inputpc = "kb 00 06n"

if sys.argv[1:] == ['--aspect169'] :
    COMMAND = aspect169

if sys.argv[1:] == ['--aspect43'] :
    COMMAND = aspect43

if sys.argv[1:] == ['--poweron'] :
    COMMAND = poweron

if sys.argv[1:] == ['--poweroff'] :
    COMMAND = poweroff

if sys.argv[1:] == ['--inputdtv'] :
    COMMAND = inputdtv

if sys.argv[1:] == ['--inputav1'] :
    COMMAND = inputav1

if sys.argv[1:] == ['--inputcomp1'] :
    COMMAND = inputcomp1

if sys.argv[1:] == ['--inputpc'] :
    COMMAND = inputpc

#This is when it actually writes the command to the serial port.

#all done now close the port.

The following is an example of using this script with LIRC, this is a small part of my lircrc file. This map the buttons that I use on my DVICO remote control.

    remote = *
    button = live
    prog   = irexec
    config = tvcontrol --aspect169
    remote = *
    button = folder
    prog   = irexec
    config = tvcontrol --aspect43
    remote = *
    button = tv_onoff
    prog   = irexec
    config = tvcontrol --poweron
    remote = *
    button = power_onoff
    prog   = irexec
    config = tvcontrol --poweroff
    remote = *
    button = dtv
    prog   = irexec
    config = tvcontrol --inputdtv
    remote = *
    button = mp3
    prog   = irexec
    config = tvcontrol --inputav1
    remote = *
    button = dvd
    prog   = irexec
    config = tvcontrol --inputcomp
    remote = *
    button = cpf
    prog   = irexec
    config = tvcontrol --inputpc

You mileage my vary, you will need to understand how your remote control functions and what the current button assignments are.

Another possiblity is to have the tvcontrol script run via a Cron entry or controlled via a webpage, use your mobile phone as a remote instead. The possiblities are endless. Have Fun.

.NET Programming

Simple .NET XML Tutorial

I needed to build an application the other day that used XML to talk to a web service, but I wanted to deal with raw XML rather then using anything based on WSDL and RPC. This was the first time I had written anything that used XML before so I started googling for code examples and tutorials.

There wasn’t much clear documentation out there on exactly what I wanted to do so I ended up using a couple of code examples I found in the end (links provided below for original source) and modifying them for my needs.

The end result is extremely simple to understand (however the information was not easy to find) so I thought I would post the details here in hopes that someone else wanting to do the same thing ends up finding this article rather than searching for hours and not finding exactly what is required. (As an a-side, most of what I found online was regarding using premade XML files, and the generation of XML files and not generating and sending the XML request on the fly). Also I wasted a bit of time because of my lack of knowledge on how various Streams work together, but that is another issue entirely.

The following is code for C# but should apply to other .NET based languages (with an appropriate change of syntax).

Required Namespace Imports

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.IO;
using System.Net;
using System.Threading;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;


WebRequest req = WebRequest.Create("http://URLHERE/WebService");
req.Method = "POST";
req.ContentType = "text/xml";
Stream requestStream = req.GetRequestStream();

XmlTextWriter xml = new XmlTextWriter(requestStream, null);


// The DocType will be different for most situations, this
// is what works for me.
xml.WriteDocType("Request", null, "somefile.dtd", null);

// These values could come from any source
xml.WriteElementString("Username", "<>");
xml.WriteElementString("Password", "<
xml.WriteElementString("Info", "something");

// When Close() is called the request is sent to the server

// Use a WebResponse Component to retrieve the response
WebResponse rsp = req.GetResponse();
XmlTextReader xmlin = new XmlTextReader(rsp.GetResponseStream());

while (xmlin.Read())
  if (xmlin.NodeType == XmlNodeType.Element)
    if (xmlin.Name == "Info")
      String info = xmlin.ReadString();

      // Do something with returned data



There are plenty of useful tutorials out there based on XmlTextReader and XmlTextWriter that can explain how to use them to read and write XML. So I wont cover that here. My biggest problem was finding out how to generate the XML and send it straight to the server without having to save to a file.


LJSearchRankTool PHP SEO Web Application

LJ Google Search Rank Tool – Ver 0.1r16 (Bug Fix Release)

Bugfix Release.


  • Fixed issue with Date Formatting from cron job generated emails.

Check out the project page for more details.


Linode Linux VPS

I have just moved my Virtual server from Web24 to Linode. I was suffering from pretty much the same IO issues as described here (

Pings/Latency was great at around 35ms from home, but when you were logged into the server sometimes the most basic operation (ls for instance) would take seconds to complete.

So i bit the bullet and went for an overseas VPS from Linode, I went with the Linode 540 which with 540mb RAM, 24Gb Disk and 300Gb network transfer is much more then I need at the moment (All for less then what I was paying for my Australian VPS).

I have to say I am very impressed. Along with my VPS, i get free access to Linode’s DNS servers to host what seems like an unlimited amount of domains. This means I don’t have to worry about Primary/Slave’s and redundant configurations/Bind security issues. Linode also provide an API to access server stats as well as manage DNS configurations, this has allowed me to create some cacti graphs based on Linodes Stats (CPU Load over Time and Network Transfer and Allowance) which I will post later on.

Support is top notch, I had a configuration error on my server (my fault, not theirs) and logged a support ticket at about 11pm on a Saturday night (Australian Time) and within 5 minutes had a response and another 5 minutes after that the entire issue was solved.

So to anyone thinking of getting a VPS for their hosting requirements or as a test server give Linode a go. I cant fault the performance of the box or the services/support offered.

If you are interested please click on the following referral link:

LJSearchRankTool PHP SEO Web Application

LJ Google Search Rank Tool – Ver 0.1r15

LJ Google Search Rank Tool is a Web Utility written in PHP to Track and Monitor the Google Search Ranking for any site against the specified keywords within the Top 64 results (This is a limitation of the Google AJAX Search API). It will email any changes in Search Ranking and keep a record of changes over time.

This is the initial public release.

Check out the project page for more details