Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
HP OfficeJet Hotplugging
View unanswered posts
View posts from last 24 hours

Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message

Joined: 14 Jul 2002
Posts: 642
Location: Mitzpe Adi, Israel

PostPosted: Tue Dec 02, 2003 1:46 pm    Post subject: HP OfficeJet Hotplugging Reply with quote

HP OfficeJet Hotplugging
WARNING: This caused major hanging on my system, even though it worked. If anyone can figure it out, please post.
This HOWTO doesn't thoroughly explain how to get the printer working. Suffice it to say that you need to get your USB controller working, emerge hpoj, /etc/init.d/hpoj start, and follow the guide on
What does it explain? Well - have you noticed that you must have your printer working when you start the hpoj service (or ptal-init start) for it to work? That pretty much means that if your printer isn't on at boot, you have to become root and start its driver in order to use it. Annoying. So here's what you need:

Getting your OfficeJet's info
In order to use Hotplug, we need the vendor and product ID for your printer. For my HP PSC 2110, those are 03f0 and 2811 respectively. If you have usbview working, you can use that. Here's the minimalist way how to figure them out for yourself if you don't:
cd /proc/bus/usb

If this directory doesn't exist, follow this step. If it does exist, skip to the next. (By the way, usbview needs this too, so you wouldn't save time with that)
# cd /usr/src/linux
# make menuconfig
Check USB->[*] Preliminary USB device filesystem

# make dep && make bzImage
# mount /boot
# cp /boot/bzImage /boot/bzImage.old
# cp arch/[your architecture, usually i386]/boot/bzImage /boot
# reboot (Close your open stuff first :)
When it's back up:
$ cd /proc/bus/usb

Now that we have our USB proc filesystem, let's figure out the IDs for the printer.
$ less devices

Look for your printer's name in there. You should see something like this:
P:  Vendor=[b]03f0[/b] ProdID=[b]2811[/b] Rev= 1.00
S:  Manufacturer=Hewlett-Packard
S:  Product=PSC 2100 Series

Those two highlighted numbers are your vendor and product ID. The vendor ID will probably be the same.

Setting hotplug up
emerge hotplug

Now we need to tell hotplug how to identify our printer. Add this line to /etc/hotplug/usb.usermap:
officejet0           0x0003      0x[b]03f0[/b]   0x[b]2811[/b]    0x0000       0x0000       0x00         0x00            0x00            0x00            0x00               0x00               0x00000000

That should be one line. Replace the two bold numbers - the first should be your vendor ID and the second should be your product ID.
Next we'll tell hotplug what to do when it detects this device. Create a file called /etc/hotplug/usb/officejet0 with these contents:

/usr/sbin/ptal-init restart

You need to make that file executable:
# chmod a+x /etc/hotplug/usb/officejet0

Now to check.
# ptal-init stop
# /etc/init.d/hotplug start

Works? Then you probably want to do this:
# rc-update add hotplug default

Have fun ;)

  • Perhaps stop the driver when the device is disconnected? If necessary, that is.
  • Printer gets stopped in CUPS if a job is sent when the printer is offline... perhaps start it back automatically? How is this done?
  • Actually, we should probably stop ptal-init when the printer gets turned off/disconnected anyway. But how?


"If it wasn't for fog, the world would run at a really crappy framerate."

Back to top
View user's profile Send private message

Joined: 01 Sep 2003
Posts: 880
Location: Edinburgh, Scotland

PostPosted: Sat Sep 11, 2004 8:35 pm    Post subject: Reply with quote

I've improved things for ya. Took several hours of research but I really wanted to know how all this works. I looked through the docs for hotplug and those said that the variable ACTION gets set to "add" when you plug something in and "remove" when you unplug something. I tested this but the scripts in /etc/hotplug/usb were only being run when something was plugged in so that wasn't quite it. I delved a little deeper and found some interesting stuff in /etc/hotplug/usb.agent. When the scripts get run initially, they have a variable called REMOVER. This points to a non-existent file that you can create if you choose to and this will get run and deleted when the device is unplugged. Bingo.

But it occurred to me that you don't necessarily want to stop hpoj when you unplug a printer because you might have more than one hpoj printer plugged in. It's unlikely, I know, but we might as well get this right. So what my script does first is run ptal-init setup and feeds it several carriage returns. Why? If you simply press enter all the way through it, it should pick up all the printers you have plugged in through USB or parallel. Five carriage returns is sufficient for one printer. I chucked a few more in for good measure. :wink: I tried to do this more intelligently using Expect but I just can't figure that thing out. Help with this would be appreciated. The script then checks to see if any printers were found using ptal-device and restarts or stops hpoj accordingly. The last part simply links the remover back to this script since the remover needs to do the same thing.


echo -e "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" | /usr/sbin/ptal-init setup

if [[ -n $(/usr/bin/ptal-device) ]];
        /etc/init.d/hpoj restart
        /etc/init.d/hpoj stop

if [[ -n $REMOVER && $ACTION == "add" ]];
        ln -s $0 $REMOVER

I haven't actually tested this yet because I don't have access to the printer right now but I did test a similar script with my camera and that worked. A delay may be needed at the start of the script because the device nodes sometimes take a few seconds to update. CUPS may also need to be restarted since hpoj is supposed to start before CUPS but this is probably only necessary when adding the printer. Restarting CUPS like this may stop any print jobs being spooled so I've left this out for now.

Feedback would be appreciated. I think I'll go and make a thread about why this sort of thing isn't being done for more hardware by default. We need some kind of hardware database.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum