Scanner_buttons_and_one-touch_scanning
| Terminals / Shells • Network • X Window System • Portage • System • Filesystems • Kernel • Other |
Contents |
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
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
Note that scanimage doesnt work without the "--resolution" with this scanner. I uploaded the small script here: http://www.regenduft.de/scan.sh it works but it needs some documentation.
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.
Compile
cd scanbuttond make clean make # You must be root (su or sudo) to install 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"!
Test
For a test run just start scanbuttond, press your scan buttons, and check your log files
scanbuttond
| Code: 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.
Configure
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
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 $?
}
|
/etc/scanbuttond
If you use the niash or plustek chipset you may need to uncomment this line in /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}
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
echo "button 4 has been pressed on ${DEVICE}"
;;
esac
chgrp scanner ${TMPFILE}.*
chmod g+rw ${TMPFILE}.*
rm -f ${LOCKFILE}
|
sample scripts
These scripts use pretty generic options, however, please run scanimage --help to see what options are available for your specific scanner.
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
|
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 --sharpness 0 --brightness -3 \
-l 0 -t 0 -x 215mm -y 280mm \
--gamma-correction "High contrast printing" > ${TMPFILE}.tiff
tiff2ps -z -w 8.27 -h 11.69 ${TMPFILE}.tiff | lpr
rm -f ${TMPFILE}.tiff
|
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
|
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
# Use gnome ximian evolution to e-mail an image with one-touch scanning
# ???
|
I visited a few mailing lists [1] [2] in order to figure out how to get mozilla thunderbird to load attachments from the commandline. I just subscribed to the ximian list, hopefully I can get some information from those folks fairly quickly.
This link may have the solution for using evolution with one-touch scanning: http://lists.debian.org/debian-devel/2003/05/msg01397.html
Also try http://www.linux.com/article.pl?sid=06/12/18/1937227
Something like the following _should_ work
evolution --display=:0.0 "mailto:?attach=${TMPFILE}.jpeg"Troubleshooting
try putting one of these lines in /etc/scanbuttond/initscanner.sh
scanimage -n
sane-find-scanner
try unplugging and replugging your scanner then check
dmesg
to make sure it is recognized
Your Scanner Isn't Supported
| Code: sudo 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
1. Find out what your scanner product and vendor ID is:
cd scanbuttond make clean lsusb && lsusb | grep -i scan
2. Google to find out which driver supports that device
3. 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" }
};
|
Key points:
- You need to increment the number of supported devices by 1
#define NUM_SUPPORTED_USB_DEVICES 5
- Add a comma to the last line in the section, then add your device
{ 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
{ "Canon", "CanonScan LIDE 20" },
{ "Canon", "CanonScan LIDE 30" }
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
Created by NickStallman.net, Luxury Homes Australia
Real estate agents should list their apartments, townhouses and units in Australia.
