Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-19 14:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found