Description: | This is code designed for controlling an HP printer using only IO::Socket, oh and interoffice war fare. I used it to "threaten" the global help desk. I told them that if I didn't get what I want (Access on a certain machine for a project that was two weeks past due because of their mess up) I'd make all of the printers at the world head quarters display $msg. *grin* I know it's not pretty, but it works nicely for me Update: I included a couple of the resources I used to figure out the PJL syntax and commands used in the script. C-. |
use IO::Socket;
my $host = 'INSERT IP HERE';
my $port = '9100'; #jet direct port
my $eoln = "\x0A";
$msg = 'Insert $0.25 and Press Go to Continue';
my $sock = IO::Socket::INET->new(PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp');
die "Couldn't connect to $host on $port: $!\n" unless $sock;
print "Connected\n";
$printer{"escapeseq"} = chr(27) . "%-12345X\@PJL";
$printer{"input"} = "\@PJL OPMSG DISPLAY= \"$msg \" $eoln";
$printer{"last"} = "\x1B&k3G";
foreach $key (sort(keys %printer)){
if ($key eq "escapeseq"){
syswrite($sock, $printer{$key}, $len);
}else{
my $len = length $printer{$key};
unless(syswrite($sock, $printer{$key}. chr(27), $len) == $len)
+ {
$sock->close;
print "Server unexpectedly closed connection\n";
last;
}
}
}
HP site link 1 and you can do a search on google for 12345x@pjl