Scanbuttons on LaserJet 3380

Asked by Rubeosis

Dear users and developers,

I am using an HP LaserJet 3380 (MFP) with ADF and many, many scanbuttons.

I would like to find a way to use at least the "Scan" and perhaps the "Scan to" button on the printer in order to start a scan with SANE. Is there anybody who is experienced in using the built-in buttons? Is there an implemented function in HPLIP to read out the status of the buttons on the MFP? Does anybody have a script that starts SANE on pressing a button on the MFP?

I want to use the 3380 connected to a standalone server (without keyboard and monitor) via USB. On pressing the "Scan" button the 3380 shall start SANE and scan in a defined resolution.

Thank you very much for your help!

Regards

FSP

Question information

Language:
English Edit question
Status:
Answered
For:
HPLIP Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Aaron Albright (albrigha-deactivatedaccount) said :
#1

FSB,

HPLIP does not currently support this functionality. We are considering implementing this feature in the future, however I can't give you a better ETA. Although, it is on our list to do.

Sorry for the inconvenience,

Aaron

Revision history for this message
Dawie Joubert (dawie-techso) said :
#2

I am currently busy with my own script that does just that... although I am not a programmer by job title though ... so far I can scan a document when the button is pressed for my HP LaserJet 3030, but I still need to write the logic that determines if the ADF was loaded with paper or if is the flatbed that needs to be used (It doesn't do it automatically unfortunately) ... And there has to be a better way to get the dynamic information from the printer ... sheesh ... :) anyway ... here goes (A python script though):

#!/usr/bin/env python

import sys, os, time, atexit, logging, commands, string
from signal import SIGTERM

class Daemon:
    """
    Original generic daemon class - by Sander Marechal
    Original found at: http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
    Usage: subclass the Daemon class and override the run() method
    """
    def __init__(self, pidfile, logfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'):
        self.stdin = stdin
        self.stdout = stdout
        self.stderr = stderr
        self.pidfile = pidfile
        self.logfile = logfile
    def daemonize(self):
        """
        do the UNIX double-fork magic, see Stevens' "Advanced
        Programming in the UNIX Environment" for details (ISBN 0201563177)
        http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16
        """
        logging.info("Daemon process starting ...")
        try:
            pid = os.fork()
            if pid > 0:
                # exit first parent
                sys.exit(0)
        except OSError, e:
            sys.stderr.write("Fork #1 failed: %d (%s)\n" % (e.errno, e.strerror))
            sys.exit(1)
        logging.debug("First process forked")
        # decouple from parent environment
        os.chdir("/")
        os.setsid()
        os.umask(0)
        # do second fork
        try:
            pid = os.fork()
            if pid > 0:
                # exit from second parent
                sys.exit(0)
        except OSError, e:
            sys.stderr.write("Fork #2 failed: %d (%s)\n" % (e.errno, e.strerror))
            sys.exit(1)
        logging.debug("Second process forked")
        # redirect standard file descriptors
        sys.stdout.flush()
        sys.stderr.flush()
        si = file(self.stdin, 'r')
        so = file(self.stdout, 'a+')
        se = file(self.stderr, 'a+', 0)
        os.dup2(si.fileno(), sys.stdin.fileno())
        os.dup2(so.fileno(), sys.stdout.fileno())
        os.dup2(se.fileno(), sys.stderr.fileno())
        logging.debug("Standard file descriptors redirected")
        # write pidfile
        atexit.register(self.delpid)
        pid = str(os.getpid())
        file(self.pidfile,'w+').write("%s\n" % pid)
        logging.info("Daemon process registered")

    def delpid(self):
        os.remove(self.pidfile)
    def start(self):
        """
        Start the daemon
        """
        logging.basicConfig(filename=self.logfile, level=logging.DEBUG, format="%(asctime)s [%(levelname)s] %(message)s")
        # Check for a pidfile to see if the daemon already runs
        logging.info("Process starting ...")
        try:
            pf = file(self.pidfile,'r')
            pid = int(pf.read().strip())
            pf.close()
        except IOError:
            pid = None

        if pid:
            message = "Pidfile %s already exist. Daemon already running?\n"
            sys.stderr.write(message % self.pidfile)
            sys.exit(1)
        # Start the daemon
        logging.info("Process started")
        self.daemonize()
        self.run()

    def stop(self):
        """
        Stop the daemon
        """
        logging.basicConfig(filename=self.logfile, level=logging.DEBUG, format="%(asctime)s [%(levelname)s] %(message)s")
        logging.info("Daemon process stopping ...")
        # Get the pid from the pidfile
        try:
            pf = file(self.pidfile,'r')
            pid = int(pf.read().strip())
            pf.close()
        except IOError:
            pid = None

        if not pid:
            message = "Pidfile %s does not exist. Daemon not running?\n"
            sys.stderr.write(message % self.pidfile)
            return # not an error in a restart

        # Try killing the daemon process
        try:
            while 1:
                os.kill(pid, SIGTERM)
                time.sleep(0.1)
        except OSError, err:
            err = str(err)
            if err.find("No such process") > 0:
                if os.path.exists(self.pidfile):
                    os.remove(self.pidfile)
                    logging.info("Daemon process stopped")
            else:
                print str(err)
                logging.error("Daemon process stopping failure!!!")
                sys.exit(1)

    def restart(self):
        """
        Restart the daemon
        """
        logging.basicConfig(filename=self.logfile, level=logging.DEBUG, format="%(asctime)s [%(levelname)s] %(message)s")
        logging.info("Daemon process restarting ...")
        self.stop()
        self.start()

    def run(self):
        """
        You should override this method when you subclass Daemon. It will be called after the process has been
        daemonized by start() or restart().
        """

class HPScanButtonDaemon(Daemon):
    def parsehpgeneratedinfo(self):
        #if len(self.hpgeneratedinfo) > 0:
        if string.find(self.hpgeneratedinfo,"Waiting for PC") != -1:
            logging.debug("Found device initiated scan command ...")
            self.scancommandtoexecute = "scanimage --device=hpaio:/usb/hp_LaserJet_3030?serial=00CNBF030598 -l 0 -t 0 -x 215 -y 297 --resolution 300 --mode=color --format=tiff > /tmp/hpscandoc.tif"
            logging.debug("Executing scan command ...")
            #os.system(self.scancommandtoexecute)
            temp1 = commands.getoutput(self.scancommandtoexecute)
            self.convertcommandtoexecute = "convert -density 300 /tmp/*.tif /tmp/hpscandoc.ps"
            logging.debug("Executing convert command ...")
            #os.system(self.convertcommandtoexecute)
            temp2 = commands.getoutput(self.convertcommandtoexecute)
            self.ps2pdfcommandtoexecute = "ps2pdf /tmp/hpscandoc.ps /mnt/smb/scans/" + time.strftime("%Y-%m-%d_%H-%M") + ".pdf"
            logging.debug("Executing ps2pdf command ...")
            #os.system(self.ps2pdfcommandtoexecute)
            temp3 = commands.getoutput(self.ps2pdfcommandtoexecute)
            logging.debug("Cleaning up ...")
            os.system("rm /tmp/*.tif")
            os.system("rm /tmp/*.ps")
            os.system("rm /tmp/*.pdf")

    def createhpgeneratedinfo(self):
        logging.debug("Setting up own command ...")
        self.infocommandtoexecute = "hp-info -i"
        self.scannertobeused ="hp:/usb/hp_LaserJet_3030?serial=00CNBF030598"
        self.infocommandtoexecute =self.infocommandtoexecute + " " + self.scannertobeused
        logging.debug("Executing hp-info command ...")
        self.hpgeneratedinfo = commands.getoutput(self.infocommandtoexecute)
        self.hpgeneratedinfo = string.strip(self.hpgeneratedinfo)
        logging.debug("Hp-info command executed ...")

    def run(self):
        logging.info("Daemon process running ...")
        while True:
            self.createhpgeneratedinfo()
            self.parsehpgeneratedinfo()
            time.sleep(3)

if __name__ == "__main__":
    daemon = HPScanButtonDaemon("/var/run/hpscanbutton.pid","/var/log/hpscanbutton.log")
    if len(sys.argv) == 2:
        if 'start' == sys.argv[1]:
            daemon.start()
        elif 'stop' == sys.argv[1]:
            daemon.stop()
        elif 'restart' == sys.argv[1]:
            daemon.restart()
        else:
            print "Invalid command usage ..."
            print "Usage: %s start|stop|restart" % sys.argv[0]
            sys.exit(2)
        sys.exit(0)
    else:
        print "Usage: %s start|stop|restart" % sys.argv[0]
        sys.exit(2)

Can you help with this problem?

Provide an answer of your own, or ask Rubeosis for more information if necessary.

To post a message you must log in.