サーチ…


導入とインストール

このドキュメントの目的は、ユーザーインターフェイスなしでスキャナを使用することです。よく使われるのは、スキャナのボタンを押すだけで、GoogleのスキャンしたファイルをGoogleドライブやDropboxに直接アップロードすることです。

scanbdは、スキャナのボタンからアクションをトリガすることを許可します。

少し厄介なことは、スキャナをポーリングすることで、scanbdがデバイスをロックすることです。 scanimageのようなローカルツールからもスキャンする必要があるので、必要に応じてscandbをポーリングから中断するプロキシを設定する必要があります。これはネットワークを監視し、スキャナへのローカルアクセスにscanbdよりも優先順位を与えるscanbmの仕事です。

したがって、我々は以下のことを行う必要があります。

  • ネットワークからのみスキャンするようにローカル状態設定を設定する(scanbm経由)
  • アクセスできるようにscanbdを構成し、ローカルスキャナをポーリングする

ルートとして:

apt-get update
apt-get install libconfuse-dev libsane-dev libudev-dev libusb-dev xinetd

scanbdの最新バージョンは、 https ://sourceforge.net/projects/scanbd/files/releases/で見つけることができます。

# Download the latest version of **scanbd**.
wget https://sourceforge.net/projects/scanbd/files/releases/scanbd-1.4.4.tgz/download

# Uncompress
tar xvzf scanbd-1.4.4.tgz && cd 1.4.4

# Configure with the installation path in /etc/
./configure --disable-Werror

# install it
make
make install

# Add a dbus policy to authorize "saned" user to manage scanbd :
cp integration/scanbd_dbus.conf /etc/dbus-1/system.d/

# Add the init script to manage the daemon :
cp integration/scanbd.debian /etc/init.d/scanbd

scanbdはインストールされましたが、まだ設定されていません。

ネットワークからのスキャンを設定する

saneのローカル設定は/etc/saned.d内にあり/etc/saned.d


/etc/sane.d/dll.conf

# /etc/sane.d/dll.conf - Configuration file for the SANE dynamic backend loader
#
# Backends can also be enabled by configuration snippets under
# /etc/sane.d/dll.d directory -- packages providing backends should drop
# a config file similar to dll.conf in this directory, named after the package.
#

# The next line enables the network backend; comment it out if you don't need
# to use a remote SANE scanner over the network - see sane-net(5) and saned(8)

net

dll.confには、 netバックエンドのみが含まれています。


/etc/sane.d/net.conf:

# This is the net backend config file.

## net backend options
# Timeout for the initial connection to saned. This will prevent the backend
# from blocking for several minutes trying to connect to an unresponsive
# saned host (network outage, host down, ...). Value in seconds.
connect_timeout = 3

## saned hosts
# Each line names a host to attach to.
# If you list "localhost" then your backends can be accessed either
# directly or through the net backend.  Going through the net backend
# may be necessary to access devices that need special privileges.

localhost

この時点で、 scanbmはまだ設定されていません。ネットワークからスキャナに到達することはできません。設定をテストするためにscanbmとscanbdを設定する必要があります。

ローカルスキャナをポーリングするようにscanbdを設定する

ローカルスキャナを特定する

lsusbを使用して、 productId (ここでは1909)を識別します。

pi:# lsusb
pi:# Bus 001 Device 005: ID 04a9:1909 Canon, Inc. CanoScan LiDE 110

そのproductIdを使ってgrep正しい設定ファイル(スキャナのモデルに依存します、それは私にとってはgenesys.confです ):

pi:# grep 1909 /etc/sane.d/*conf
pi:# /etc/sane.d/genesys.conf:usb 0x04a9 0x1909

scanbd設定フォルダ内のファイルをコピーします。

cp /etc/sane.d/genesys.conf /usr/local/etc/scanbd/
cp /etc/sane.d/dll.conf /usr/local/etc/scanbd/

/usr/local/etc/scanbd/dll.confを編集し、 netを適切なスキャナのバックエンドに置き換えます。

# /etc/sane.d/dll.conf - Configuration file for the SANE dynamic backend loader
#
# Backends can also be enabled by configuration snippets under
# /etc/sane.d/dll.d directory -- packages providing backends should drop
# a config file similar to dll.conf in this directory, named after the package.
#

# The next line enables the network backend; comment it out if you don't need
# to use a remote SANE scanner over the network - see sane-net(5) and saned(8)

genesys

scanbdがローカルスキャナを検出したことを確認する

今すぐテストする準備が整いました。

scanbd -d7 -f

env var SANE_CONFIG_DIRを操作するのをできるだけ避けてください。これは問題を引き起こす可能性があります。デフォルト値は/usr/local/etc/scanbd/scanbd.confとinitスクリプトですでに設定されています。

出力は次のようになります。

scanbd: foreground
scanbd: reading config file /usr/local/etc/scanbd/scanbd.conf
scanbd: debug on: level: 7
scanbd: dropping privs to uid saned
scanbd: dropping privs to gid scanner
scanbd: group scanner has member: 
scanbd: saned
scanbd: pi
scanbd: drop privileges to gid: 110
scanbd: Running as effective gid 110
scanbd: drop privileges to uid: 110
scanbd: Running as effective uid 110
scanbd: dbus_init
scanbd: dbus match type='signal',interface='org.freedesktop.Hal.Manager'
scanbd: SANE_CONFIG_DIR=/usr/local/etc/scanbd/sane.d
scanbd: sane version 1.0
scanbd: Scanning for local-only devices
scanbd: found device: genesys:libusb:001:005 Canon LiDE 110 flatbed scanner

ここで最も重要なのはfound deviceです。

「見つかったデバイス」が表示されない場合はどうなりますか?

構成、特にこのマニュアルの識別部分を再度確認し、最終的なSANE_CONFIG_DIR環境変数が間違って設定された場合は、次のように入力してクリアする必要がありますunset SANE_CONFIG_DIR


ネットワーク上でscanbmがリッスンするようにxinetdを設定する

次を含む/etc/xinetd.d/sane-portを作成します。

service sane-port
{
        port        = 6566
        socket_type = stream
        wait        = no
        user        = saned
        group       = scanner
        server      = /usr/local/sbin/scanbm
        server_args = scanbm -c /usr/local/etc/scanbd/scanbd.conf
        disable     = no
}

/!\ scanbmのパスをダブルチェックして、 which scanbm

次に、 xinetdを再起動してscanbdを起動します

service xinetd restart
/etc/init.d/scanbd start

scanimage -Lはスキャナを表示するはずです。

この段階でのほとんどの問題は、アクセス許可に関係しています。 sudo -u saned -sを実行してsanedとしてログオンしたときに、 scanimage -L動作することを確認してください。

そうでない場合は、USBの許可を確認してください: ls -al /dev/bus/usb/***

スキャナボタンからのトリガアクション

アクションは/usr/local/etc/scanbd/scanbd.confます。私はスキャンコピー電子メールファイルの 4つのボタンを持っています

デフォルトの設定ファイルには、デフォルトのすべてのアクションが含まれているわけではありません。ブロックを手動で追加する必要があります。あなたのスキャナモデルに応じて、より少ないまたはより多くのボタンを持つことができます。

各アクションについて、 スクリプトオプションのカスタムパスを設定します。

action scan {
    filter = "^scan.*"
    numerical-trigger {
            from-value = 1
            to-value   = 0
    }
    desc   = "Scan to file"
    # script must be an relative path starting from scriptdir (see above), 
    # or an absolute pathname. 
    # It must contain the path to the action script without arguments
    # Absolute path example: script = "/some/path/foo.script 
    script = "/home/pi/scan.sh"
}

scanbd.confの最後に、他のデフォルトのアクションをコメントすることを忘れないでください:

# devices 
# each device can have actions and functions, you can disable not relevant devices
#include(scanner.d/avision.conf)
#include(scanner.d/fujitsu.conf)
#include(scanner.d/hp.conf)
#include(scanner.d/pixma.conf)
#include(scanner.d/snapscan.conf)
#include(scanner.d/canon.conf)

カスタムスクリプトを作成して、各アクションを処理できるようになりました。

/sys/class/leds/led0/triggerは、LEDが何が起こっているかを監視するためのものです。 cat /sys/class/leds/led0/triggerを使用すると、さまざまなパターンの照明が得られます。

/home/pi/scan.sh

#!/bin/bash

# don't forget to create the folder
scan_dir=/home/pi/scanned-files
datetime=`date +%F_%H%M%S`

echo none >/sys/class/leds/led0/trigger

case $SCANBD_ACTION in
  scan)
    filename=file-$datetime
    logger -t "scanbd: $0" "$SCANBD_DEVICE $SCANBD_ACTION - scanning --resolution 150 --mode Color --depth 8 --format=tiff to $scan_dir/$filename.jpg"
    echo timer >/sys/class/leds/led0/trigger
    scanimage -d $SCANBD_DEVICE --resolution 150 --mode Color --depth 8 --format=tiff  --brightness 5 --contrast 20 | convert tiff:- -compress jpeg $scan_dir/$filename.pdf
    echo none >/sys/class/leds/led0/trigger
    logger -t "scanbd: $0" "Finished scanning"
    ;;
    
  email)
    logger -t "scanbd: $0" "Emailing $scan_dir/file-*pdf"
    echo heartbeat >/sys/class/leds/led0/trigger
    # here are the lines to send the file
    echo none >/sys/class/leds/led0/trigger

esac


Modified text is an extract of the original Stack Overflow Documentation
ライセンスを受けた CC BY-SA 3.0
所属していない Stack Overflow