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

HP site link 2

and you can do a search on google for 12345x@pjl


In reply to HP Jet Direct Control by cacharbe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.