Subject: Serving HP JetDirect Printers (Was: which printers will work?)
To: Andrew Gillham <gillhaa@ghost.whirlpool.com>
From: Bob Beck <beck@obtuse.com>
List: netbsd-users
Date: 07/23/1997 00:15:39
>
> [ Bob is innundated with replies "You Do Printers! Tell us How" ] 

> [ An eerie voice from under my chair reminds me of the fate that 
>   awaits me ] 	

Ohhh man, I'm sure Satan is keeping it plenty warm down there in 
that printer room for me.  Sigh... I'm doomed..

Since I got about a gazillion replies asking essentially the same
thing, I'll just explain to the list rather than individually,
apologies for slightly off topic. Two methods below. Method 1 is the
easy way, if you can use it (i.e. You don't need page
accounting). Method two is harder, but definately doable. It's not as
painful as it used to be in the Bad Old Days(tm).  (It could be
NeWSPrint on SunOS.. Oh the pain!)

****************************************************************
***Method #1, The simple way, No page accounting, newer JetDirect card,
printer talking lpd.

Newer HP Jet Direct cards all will talk lpd in the standard unix way.
These will communicate fine with a NetBsd or any other unix that talks
lpd. Because they talk lpd, the look like an lpd server (i.e a remote
machine with a printer) to your NetBSD machine. You put the printer on
the ethernet, You can either doodle in the ip address on the front
panel (slow, but effective) or use bootp from a bootp server on your
unix machine to set up the printer's IP address.  You can then use the
regular LPD that comes with NetBSD and add an entry for the printer:
For example, If I give my HP laserjet the Ip Address 192.168.20.5 I
put the folliwing in my printcap file:

laserjet|Bob's evil printer:\
        :lp=:rm=192.168.20.5:rp=lp:sd=/var/spool/laserjet:lf=/var/log/lpd-errs:

You can either point all your machines at the printer directly using
the entry above, *or* you figure out one machine that's the printer spooler
(You can set the Printer to only talk to it via the frontpanel or bootp)
and then (lets say this machine's name is "printserver", it has the above
printcap entry) the other machines would have a printcap entry like:

laserjet|Bob's evil printer on printserver:\
	:lp=rm=printserver::rp=laserjet:sd=/var/spool/laserjet:\
	:lf=/var/log/lpd-errs:

	printserver could also run samba to provide netbios-over-tcp
access to the printer for machines suffering from the common tragedy
of the lack of a functional operating system.

****************************************************************
***Method number 2. Send directly to the JetDirect card. Do this for
page accounting: 

	Ok.  JetDirect cards with TCP/IP turned on all can talk on 
port 9100 (TCP) and recieve jobs and commands in PJL (Printer Job 
Language or somthing like that). If you spit text at port 9100 
the printer will print it.  To make it do something intelligent (like
pagecount) you want to send the job and talk to the printer via 
port 9100. For this you set up an *output filter* in lpd that 
talks to the printer. Setting up the filter program is usually the 
harder part. 

	Personally, I use the LPRng package and CTI-ifhp filters
(ftp://dickory.sdsu.edi/pub/LPRng, or mirrored at
ftp://gwynne.cs.ualberta.ca/pub/LPRng). This is a replacement lpr/lpd
daemon/client with better support for things like page counting and 
limiting use by user. I use it because I mostly do this in an academic
environment. If you don't need pagecounts and tight control over the 
printer *STOP READING NOW* Go back up to method one above, thank your
lucky stars and forget you ever heard the words "printer" and "accounting"
together lest Satan lock you in the room with me and hundreds of printers
and Unix machines to make work when you join me in hell... 

	The key part of LPRng that you will need is the CTI-ifhp
package.  This is a program that talks PJL to a laserjet, preferably
on port 9100 of a JetDirect card. It keep status and can ask for and
get pagecounts before and after to reliably report usage. It will work
for pagecounts with a LaserJet 4m with the Add-on jet Direct card, or
newer (4m+ 5m+ etc.) HP printers.  I know it works with the 4m (no
plus, add on jet direct card) because it didn't untill I had to add
the support for it because I had one of the $@#!$! orphaned things, A
week after my change was put in the distribution the offending orphan
printer was stolen. (And you wonder why this topic makes me feel like
I'm doomed to endure it)

	Anyway, grab LPRng and CTI-ifhp. There are a wad of examples
in the distribution, You get your accouting informtion in a log file
and/or you can set a post job accounting shell script to run after the
job to do whatever you like with the info.  The log format is as ugly
as a harp seal beat with a stick, but nothing a few lines of perl
can't cure ;-)

here's what one of my printcaps looks like: (with lprng and CTI-ifhp
installed to /usr/lprng).

psnw|for PLP/LPRng software - network based HP Jetdirect card:\
        :rw:sf:sh:lp=printer.my.domain%9100:sd=/usr/lprng/spool:\
        :as=|/usr/lprng/as.perl:\
        :af=acct:\
        :lf=log:\
        :connect_retry#1:\
        :connect_timeout#60:\
        :send_failure_action=remove:\
        :send_timeout#600:\
        :send_try#1:\
        :ps=status:\
        :fx=flpv:\
        :if=/usr/lprng/lib/filters/ifhp:\
        :of=/usr/lprng/lib/filters/ofhp:\
        :vf=/usr/lprng/lib/filters/ifhp -c:


  
  Cheers, 
  -Bob "Printers are Evil Incarnate" Beck

--
Bob Beck					 Obtuse Systems Corporation
beck@obtuse.com					 http://www.obtuse.com/	
True Evil hides its real intentions in its street address.