Scanner buttons and one-touch scanning

From Gentoo Linux Wiki
Jump to: navigation, search
Please format this article according to the Style Guidelines and Wikification suggestions, then remove this notice {{Wikify}} from the article.

Reason(s):

  • Uses first person (I, me, etc)

Contents

[edit] Introduction

Thanks much to Bernhard Stiftner, you can now configure your scanner buttons to do one-touch scanning in Linux!!! Here's a little howto for it!

Supported Chipsets:

  • epson
  • plustek
  • niash
  • snapscan

An untested ebuild for scanbuttond has been posted on the Gentoo Bugzilla.

Note: A new program for monitoring scanner buttons (daemon + GUI) has been published. This one is based upon SANE (whereas scanbuttond is not). Despite its name (KScannerButtons), only the GUI is KDE centric. The daemon (sanebuttonsd) has the same approach as scanbuttond. It has been tested with the avision chipset (and SANE backend). An untested ebuild for kscannerbuttons has also been posted on the Gentoo Bugzilla bug #160139
Note: My Scanner - the Epson Perfection V10 / V100 is not yet supported by scanbuttond and KScannerButtons. But you can write a very simple shellscript around the command
scanimage --resolution 200 --mode Color --wait-for-button > $IMAGE_NAME.pnm

[edit] Download CVS snapshot of scanbuttond

cd /usr/src cvs -d:pserver:anonymous@scanbuttond.cvs.sourceforge.net:/cvsroot/scanbuttond login cvs -z3 -d:pserver:anonymous@scanbuttond.cvs.sourceforge.net:/cvsroot/scanbuttond co -P scanbuttond
Note: you must have /usr/include/usb.h for user-mode (not /usr/include/linux/usb.h which is for kernel-mode). On debian, install the libusb-dev package to get this file.

[edit] Compile

cd scanbuttond make clean make
make install

Don't forget to run ldconfig! Otherwise, you will get error messages like

Unable to load backend library "/usr/local/lib/libscanbtnd-backend_meta.so"!

[edit] Test

For a test run just start scanbuttond, press your scan buttons, and check your log files

scanbuttond grep -R scanbuttond /var/log
Jul 27 06:34:29 dragon scanbuttond: query button
Jul 27 06:34:29 dragon scanbuttond: query button
Jul 27 06:34:29 dragon scanbuttond: query button
Jul 27 06:34:29 dragon scanbuttond: button 1 has been pressed.
Jul 27 06:34:30 dragon scanbuttond: query button
Jul 27 06:34:30 dragon scanbuttond: button 2 has been pressed.
Jul 27 06:34:30 dragon scanbuttond: query button
Jul 27 06:34:30 dragon scanbuttond: button 2 has been released.
Jul 27 06:34:30 dragon scanbuttond: query button
Jul 27 06:34:30 dragon scanbuttond: button 3 has been pressed.

You can also run

scanbuttond -f

Then, scanbuttond will run in foreground and you can see the messages directly.

[edit] Configure

[edit] Environment

make sure /usr/local/bin is in your profile. Edit /etc/env.d/00local

File: /etc/env.d/00local
PATH="${HOME}/bin:/usr/local/bin:${PATH}"
env-update source /etc/profile

[edit] Automatic Startup

If the PC you'll be running this software on is most commonly accessed by only one person at a time (as most Desktop PCs are) then you may wish to add it to your desktop's startup.

  • Gnome: Desktop » Preferences » Sessions » Startup Programs » Add » /usr/local/bin/scanbuttond

On a system with multiple users you may want to use a sysvinit or init-ng script to run the daemon as root each boot. Create an init script to automatically load on startup

touch /etc/init.d/scanbuttond chmod a+x /etc/init.d/scanbuttond


File: /etc/init.d/scanbuttond
#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License, v2 or later

depend() {
        need modules
}

start() {
        ebegin "Starting scanbuttond"
        start-stop-daemon --start --quiet \
                --exec /usr/local/bin/scanbuttond
        eend $?
}

stop() {
        ebegin "Stopping scanbuttond"
        start-stop-daemon --stop --quiet --exec /usr/local/bin/scanbuttond
        eend $?
} 

[edit] /etc/scanbuttond

If you use the niash or plustek chipset you may need to uncomment this line:

File: /etc/scanbuttond/initscanner.sh
scanimage -n

You'll need to figure out which buttons map to which label on your scanner (IE the "one-touch" button may actually be button 2 and the "print" button may be button 3 and the "email" button 1.

File: /etc/scanbuttond/buttonpressed.sh
BUTTON="$1"
DEVICE="$2"
PICDIR="/tmp/scanned/"
TMPFILE="${PICDIR}/`date +%Y%m%d%H%M%S`"
LOCKFILE="/tmp/${DEVICE}.lock"
 
if [ -f ${LOCKFILE} ]; then
  zenity --error --title="Error: Device already in use." --text="It seems that the previous scan has not finished yet. \
     If this is not the case, please execute 'rm -f ${LOCKFILE}'." || \
     echo "Error: Device already in use. It seems that the previous scan has not finished yet. \
     If this is not the case, please execute 'rm -f ${LOCKFILE}'."
  exit
fi
 
touch ${LOCKFILE}
mkdir -p ${PICDIR}
msg="Button ${BUTTON} has been pressed on ${DEVICE}"
echo ${msg}
echo ${msg}| festival --tts
 
case ${BUTTON} in
        1)
                # Button one we'll use for one-touch scanning
                /etc/scanbuttond/sbd-scan.sh ${TMPFILE} ${DEVICE}
                ;;
        2)
                # Button two we'll use for a direct copy via lpr
                /etc/scanbuttond/sbd-print.sh ${TMPFILE} ${DEVICE}
                ;;
        3)
                # Button three we'll use to send to start an e-mail attachment
                /etc/scanbuttond/sbd-mail.sh ${TMPFILE} ${DEVICE}
                ;;
        4)
                # Button four has not been configured
 
                ;;
esac
 
# Note: you will need to add your user to the (new) group (scanner).
# Log out and in again for the new settings to take effect or use su to create a new session
# For details see
# http://www.linuxquestions.org/questions/linux-newbie-8/chgrp-operation-not-permitted-even-though-i-own-the-file-118678/page2.html
 
chgrp scanner ${TMPFILE}*
chmod g+rw ${TMPFILE}*
rm -f ${LOCKFILE}

[edit] Sample scripts

These scripts use pretty generic options, however, to see what options are available for your specific scanner, please run

scanimage --help

[edit] one-touch scan

touch /etc/scanbuttond/sbd-scan.sh chmod a+x /etc/scanbuttond/sbd-scan.sh
File: /etc/scanbuttond/sbd-scan.sh
DEVICE=$2
TMPFILE=$1
scanimage --device-name ${DEVICE} --format pnm \
   --mode Color --depth 8 --resolution 300 \
   -l 0 -t 0 -x 215mm -y 280mm \
   --lampoff-time 300 \
   > ${TMPFILE}.pnm
 
pnmtojpeg -quality 85 -optimize \
   -comment "Created with scanbuttond and pnmtojpeg." \
   ${TMPFILE}.pnm > ${TMPFILE}.jpeg
 
rm -f ${TMPFILE}.pnm


[edit] one-touch copy

touch /etc/scanbuttond/sbd-print.sh chmod a+x /etc/scanbuttond/sbd-print.sh
File: /etc/scanbuttond/sbd-print.sh
 DEVICE=$2
 TMPFILE=$1
 scanimage --device-name ${DEVICE} --format tiff --mode Gray \
    --resolution 300  --brightness -3 \
    -l 0 -t 0 -x 215mm -y 280mm  > ${TMPFILE}.tiff
 
# Note: some scanners support additional settings such as --sharpness 0 --gamma-correction "High contrast printing"
 
 tiff2ps -z -w 8.27 -h 11.69 ${TMPFILE}.tiff | lpr
 
 rm -f ${TMPFILE}.tiff

An alternative, much faster for black and white copy command:

scanimage --format tiff --resolution 300 | convert - -monochrome ps:- | lpr -P C5300_192.168.0.101

The advantage is that the print job file sent to the printer is small and very quickly printed as all pixels are black and white, which ensures the monochrome option. The quality, however is fairly similar to an ordinary copier.

[edit] one-touch gimp

touch /etc/scanbuttond/sbd-gimp.sh chmod a+x /etc/scanbuttond/sbd-gimp.sh
File: /etc/scanbuttond/sbd-gimp.sh
DEVICE=$2
TMPFILE=$1
GIMP=/usr/bin/gimp-2.2
 
scanimage --device-name ${DEVICE} --format pnm \
   --mode Color --depth 8 --resolution 300 \
   -l 0 -t 0 -x 215mm -y 280mm \
   --lampoff-time 300 \
   > ${TMPFILE}.pnm
 
${GIMP} ${TMPFILE}.pnm

[edit] one-touch e-mail

touch /etc/scanbuttond/sbd-mail.sh chmod a+x /etc/scanbuttond/sbd-mail.sh
File: /etc/scanbuttond/sbd-mail.sh
DEVICE=$2
TMPFILE=$1
scanimage --device-name ${DEVICE} --format pnm \
   --mode Color --depth 8 --resolution 300 \
   -l 0 -t 0 -x 215mm -y 280mm \
   --lampoff-time 300 \
   > ${TMPFILE}.pnm
 
pnmtojpeg -quality 85 -optimize \
   -comment "Created with scanbuttond and pnmtojpeg." \
   ${TMPFILE}.pnm > ${TMPFILE}.jpeg
 
rm -f ${TMPFILE}.pnm
 
# Use mozilla thunderbird to e-mail an image with one-touch scanning
thunderbird -compose attachment=file://${TMPFILE}.jpeg

[edit] Troubleshooting

try putting one of these lines in /etc/scanbuttond/initscanner.sh

File: /etc/scanbuttond/initscanner.sh
scanimage -n
sane-find-scanner

try unplugging and replugging your scanner then check

dmesg

to make sure it is recognized

[edit] Your Scanner Isn't Supported

tail /var/log/messages
Jul 24 19:11:59 dragon scanbuttond: no supported devices found. rescanning in a few seconds...
Jul 24 19:12:01 dragon scanbuttond: rescanning devices...

There is hope! You may be able to add your information to the code

Find out what your scanner product and vendor ID is:

cd scanbuttond make clean lsusb && lsusb | grep -i scan

Google to find out which driver supports that device, and manually add your scanner (example adding CanoScan LiDE 30, which is already supported by the CVS Version)

cd scanbuttond/backends/ vim scanbuttond/backends/${MODULE}.c
File: ./scanbuttond/backends/plustek.c
#define NUM_SUPPORTED_USB_DEVICES 5
 
static int supported_usb_devices[NUM_SUPPORTED_USB_DEVICES][3] = {
      // vendor, product, num_buttons
      { 0x04a9, 0x2207, 1 },  // CanoScan N1220U
      { 0x04a9, 0x2208, 1 },  // CanoScan CanoScan D660U
      { 0x04a9, 0x2206, 1 },  // CanonScan N650U
      { 0x04a9, 0x220d, 3 },  // CanonScan LIDE 20
      { 0x04a9, 0x220e, 3 }   // CanonScan LIDE 30
};
 
static char* usb_device_descriptions[NUM_SUPPORTED_USB_DEVICES][2] = {
      { "Canon", "CanoScan N1220U" },
      { "Canon", "CanoScan D660U"  },
      { "Canon", "CanonScan N650U" },
      { "Canon", "CanonScan LIDE 20" },
      { "Canon", "CanonScan LIDE 30" }
};

Hint: To get CanoScan D660U fully supported with the FAU Button change this before compiling:

File: ./scanbuttond/backends/plustek.c
... 
static int supported_usb_devices[NUM_SUPPORTED_USB_DEVICES][3] = {
      // vendor, product, num_buttons
      { 0x04a9, 0x2207, 1 },  // CanoScan N1220U
      { 0x04a9, 0x2208, 2 },  // CanoScan CanoScan D660U  // Set num_buttons to 2 for working FAU button
...

Don't forget to recompile at least the backend. Cd into the "backends" directory in the 0.2.3 source tree and "make; make install"

[edit] Key points

  • You need to increment the number of supported devices by 1
Code:
#define NUM_SUPPORTED_USB_DEVICES 5
  • Add a comma to the last line in the section, then add your device
Code:
{ 0x04a9, 0x220d, 3 },  // CanonScan LIDE 20
{ 0x04a9, 0x220e, 3 }   // CanonScan LIDE 30
  • Add a comma to the last line in the section, then name your device
Code:
{ "Canon", "CanonScan LIDE 20" },
{ "Canon", "CanonScan LIDE 30" }

[edit] Work YOU can do!

  • E-mail Bernhard if your scanner works but is not on the list
  • Create a sample script for a common task to include
  • Use your programming expertice to help with the coding
  • sysv init script
  • init-ng init script
Personal tools