Monday, 5 December 2005

HP Printer Hacking

Looking at http://odetocode.com/Humor/68.aspx I saw a cool .net hack for displaying custom messages on an HP printer LCD.

I’m a bit of a .net fan from a distances, which is to say I’m an ex-delphi afficionado, having done some cool hacks like 16 bit multithreading and form inheritance in Delphi, and I’m waiting for .net to be the cross platform “delphi” that Kylix never became (if only they used wxWidgets, but who was to know then, eh?)

Well anyway, .net seemed a bit of overkill for HP printer LCD hacking so I replaced it with a small shell script instead

#! /bin/sh

printer="$1"
shift

message() {
printf "x1B%%-12345X@PJL RDYMSG DISPLAY = "%s"rnx1B%%-12345Xrn" "$*"
}

# try to use bash tcp redirection if enabled
if exec 9> "/dev/tcp/$printer/9100"
then message "$@" >&9
else message "$@" | netcat -q 2 "$printer" 9100 >/dev/null
fi


Invoke thus:

./hpmsg my.printer.name.or.ip.address hello joe wassup

of course, this is hardly just a small shell script as it relies on all of bash, and possibly netcat. (My ubuntu bash doesn’t seem to have build-in tcp redirection, boo!)

No comments:

Post a Comment